From 5f8d116010b8052b6a6ce298c78727d52d422b96 Mon Sep 17 00:00:00 2001 From: Damyan Petev Date: Fri, 28 Feb 2025 18:46:20 +0200 Subject: [PATCH 1/2] test(*): leftover control flow for track adjustments --- .../lib/carousel/carousel.component.spec.ts | 6 +-- .../directives/drag-drop/drag-drop.spec.ts | 10 ++--- .../src/lib/select/select.component.spec.ts | 2 +- .../src/lib/tabs/tabs/tabs.component.spec.ts | 2 +- .../lib/test-utils/tabs-components.spec.ts | 45 +++++++++---------- 5 files changed, 29 insertions(+), 36 deletions(-) diff --git a/projects/igniteui-angular/src/lib/carousel/carousel.component.spec.ts b/projects/igniteui-angular/src/lib/carousel/carousel.component.spec.ts index 30b1a13437a..b971178a8b7 100644 --- a/projects/igniteui-angular/src/lib/carousel/carousel.component.spec.ts +++ b/projects/igniteui-angular/src/lib/carousel/carousel.component.spec.ts @@ -1253,7 +1253,7 @@ class CarouselTemplateSetInTypescriptTestComponent { @Component({ template: ` - @for (slide of slides; track slide) { + @for (slide of slides; track slide.text) {

{{slide.text}}

@@ -1269,10 +1269,6 @@ class CarouselDynamicSlidesComponent { public slides = []; constructor() { - this.addNewSlide(); - } - - public addNewSlide() { this.slides.push( { text: 'Slide 1', active: false }, { text: 'Slide 2', active: false }, diff --git a/projects/igniteui-angular/src/lib/directives/drag-drop/drag-drop.spec.ts b/projects/igniteui-angular/src/lib/directives/drag-drop/drag-drop.spec.ts index de893b9bd94..525fec4c950 100644 --- a/projects/igniteui-angular/src/lib/directives/drag-drop/drag-drop.spec.ts +++ b/projects/igniteui-angular/src/lib/directives/drag-drop/drag-drop.spec.ts @@ -2107,13 +2107,13 @@ class TestDragDropStrategiesComponent extends TestDragDropLinkedSingleComponent drag_indicator Movies list - @for (category of categoriesNotes; track category) { + @for (category of categoriesNotes; track category.text) {
drag_indicator {{category.text}}
- @for (note of getCategoryMovies(category.text); track note) { + @for (note of getCategoryMovies(category.text); track note.text) {
drag_indicator @@ -2128,11 +2128,11 @@ class TestDragDropStrategiesComponent extends TestDragDropLinkedSingleComponent imports: [IgxIconComponent, IgxDragDirective, IgxDragHandleDirective] }) class TestDragDropNestedComponent extends TestDragDropComponent { - public categoriesNotes = [ + protected categoriesNotes = [ { text: 'Action', dragged: false }, { text: 'Fantasy', dragged: false } ]; - public listNotes = [ + protected listNotes = [ { text: 'Avengers: Endgame', category: 'Action', dragged: false }, { text: 'Avatar', category: 'Fantasy', dragged: false }, { text: 'Titanic', category: 'Drama', dragged: false }, @@ -2142,7 +2142,7 @@ class TestDragDropNestedComponent extends TestDragDropComponent { { text: 'The Avengers', category: 'Action', dragged: false } ]; - public getCategoryMovies(inCategory: string){ + protected getCategoryMovies(inCategory: string){ return this.listNotes.filter(item => item.category === inCategory); } } diff --git a/projects/igniteui-angular/src/lib/select/select.component.spec.ts b/projects/igniteui-angular/src/lib/select/select.component.spec.ts index e678a4d50b1..6a3811badec 100644 --- a/projects/igniteui-angular/src/lib/select/select.component.spec.ts +++ b/projects/igniteui-angular/src/lib/select/select.component.spec.ts @@ -3053,7 +3053,7 @@ class IgxSelectTemplateFormComponent { alarm None - @for (item of items; track item) { + @for (item of items; track item.field) { {{ item.field }} diff --git a/projects/igniteui-angular/src/lib/tabs/tabs/tabs.component.spec.ts b/projects/igniteui-angular/src/lib/tabs/tabs/tabs.component.spec.ts index ac5821ddf74..acefcbf1c44 100644 --- a/projects/igniteui-angular/src/lib/tabs/tabs/tabs.component.spec.ts +++ b/projects/igniteui-angular/src/lib/tabs/tabs/tabs.component.spec.ts @@ -493,7 +493,7 @@ describe('IgxTabs', () => { expect(tabs.items.length).toBe(2); expect(tabs.selectedIndex).toBe(0); - fixture.componentInstance.addTab(3); + fixture.componentInstance.addTab(); fixture.detectChanges(); tick(100); diff --git a/projects/igniteui-angular/src/lib/test-utils/tabs-components.spec.ts b/projects/igniteui-angular/src/lib/test-utils/tabs-components.spec.ts index 6d548ca2f86..7bd865dd45f 100644 --- a/projects/igniteui-angular/src/lib/test-utils/tabs-components.spec.ts +++ b/projects/igniteui-angular/src/lib/test-utils/tabs-components.spec.ts @@ -98,7 +98,7 @@ export class TabsTestComponent { template: `
- @for (tab of collection; track tab) { + @for (tab of collection; track tab.name) { {{ tab.name }} @@ -112,7 +112,7 @@ export class TabsTestComponent { export class TabsTest2Component { @ViewChild(IgxTabsComponent, { static: true }) public tabs: IgxTabsComponent; @ViewChild('wrapperDiv', { static: true }) public wrapperDiv: any; - public collection: any[]; + protected collection: any[]; constructor() { this.resetCollectionThreeTabs(); @@ -198,7 +198,7 @@ export class TemplatedTabsTestComponent { template: `
- @for (tab of collection; track tab) { + @for (tab of collection; track tab.name) { {{ tab.name }} @@ -210,7 +210,7 @@ export class TemplatedTabsTestComponent { }) export class TabsTestSelectedTabComponent { @ViewChild(IgxTabsComponent, { static: true }) public tabs: IgxTabsComponent; - public collection: any[]; + protected collection: any[]; constructor() { this.collection = @@ -525,7 +525,7 @@ export class TabsWithPrefixSuffixTestComponent extends TabsTestComponent { template: `
- @for (contact of contacts; track contact) { + @for (contact of contacts; track contact.Name) { {{contact.Name}} @@ -547,7 +547,7 @@ export class TabsContactsComponent extends TabsTestComponent { template: `
- @for (tab of collection; track tab) { + @for (tab of collection; track tab.name) { {{ tab.name }} @@ -560,7 +560,7 @@ export class TabsContactsComponent extends TabsTestComponent { }) export class AddingSelectedTabComponent { @ViewChild(IgxTabsComponent, { static: true }) public tabs: IgxTabsComponent; - public collection: any[]; + protected collection: any[]; constructor() { this.collection = [ { name: 'tab1', selected: true }, @@ -568,9 +568,9 @@ export class AddingSelectedTabComponent { ]; } - public addTab(num: number) { + public addTab() { this.collection.forEach(t => t.selected = false); - this.collection.push({ name: 'tab' + num, selected: true }); + this.collection.push({ name: 'tab' + (this.collection.length + 1), selected: true }); } } @@ -578,7 +578,7 @@ export class AddingSelectedTabComponent { template: `
- @for (tab of collection; track tab) { + @for (tab of collection; track tab.name) { {{ tab.name }} @@ -592,18 +592,15 @@ export class AddingSelectedTabComponent { export class TabsRtlComponent { @ViewChild(IgxTabsComponent, { static: true }) public tabs: IgxTabsComponent; @ViewChild('wrapperDiv', { static: true }) public wrapperDiv: any; - public collection: any[]; - constructor() { - this.collection = [ - { name: 'tab1', selected: true }, - { name: 'tab2', selected: false }, - { name: 'tab3', selected: false }, - { name: 'tab4', selected: false }, - { name: 'tab5', selected: false }, - { name: 'tab6', selected: false }, - { name: 'tab7', selected: false }, - { name: 'tab8', selected: false }, - { name: 'tab9', selected: false }, - ]; - } + protected collection = [ + { name: 'tab1', selected: true }, + { name: 'tab2', selected: false }, + { name: 'tab3', selected: false }, + { name: 'tab4', selected: false }, + { name: 'tab5', selected: false }, + { name: 'tab6', selected: false }, + { name: 'tab7', selected: false }, + { name: 'tab8', selected: false }, + { name: 'tab9', selected: false }, + ]; } From 96d8e190c6d6e58f317a4a111819fba767285f81 Mon Sep 17 00:00:00 2001 From: Damyan Petev Date: Tue, 4 Mar 2025 18:37:12 +0200 Subject: [PATCH 2/2] test(tabs): update for track func for index-testing spec --- .../src/lib/test-utils/tabs-components.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/projects/igniteui-angular/src/lib/test-utils/tabs-components.spec.ts b/projects/igniteui-angular/src/lib/test-utils/tabs-components.spec.ts index 7bd865dd45f..6e3ed047f34 100644 --- a/projects/igniteui-angular/src/lib/test-utils/tabs-components.spec.ts +++ b/projects/igniteui-angular/src/lib/test-utils/tabs-components.spec.ts @@ -98,7 +98,7 @@ export class TabsTestComponent { template: `
- @for (tab of collection; track tab.name) { + @for (tab of collection; track trackByItemRef(tab)) { {{ tab.name }} @@ -151,6 +151,9 @@ export class TabsTest2Component { public resetToEmptyCollection() { this.collection = []; } + + /** Explicitly track object so collection changes entirely for index logic test */ + protected trackByItemRef = (x: any) => x; } @Component({