|
1 | 1 | import { IgxInputState } from './../directives/input/input.directive'; |
2 | | -import { Component, ViewChild, DebugElement, OnInit } from '@angular/core'; |
| 2 | +import { Component, ViewChild, DebugElement, OnInit, ViewChildren, QueryList } from '@angular/core'; |
3 | 3 | import { async, TestBed, tick, fakeAsync } from '@angular/core/testing'; |
4 | 4 | import { FormsModule, FormGroup, FormBuilder, FormControl, Validators, ReactiveFormsModule, NgForm } from '@angular/forms'; |
5 | 5 | import { By } from '@angular/platform-browser'; |
@@ -92,7 +92,8 @@ describe('igxSelect', () => { |
92 | 92 | IgxSelectAffixComponent, |
93 | 93 | IgxSelectReactiveFormComponent, |
94 | 94 | IgxSelectTemplateFormComponent, |
95 | | - IgxSelectHeaderFooterComponent |
| 95 | + IgxSelectHeaderFooterComponent, |
| 96 | + IgxSelectCDRComponent |
96 | 97 | ], |
97 | 98 | imports: [ |
98 | 99 | FormsModule, |
@@ -2467,7 +2468,31 @@ describe('igxSelect', () => { |
2467 | 2468 | expect(selectList.nativeElement.nextElementSibling).toBeNull(); |
2468 | 2469 | })); |
2469 | 2470 | }); |
2470 | | -}); |
| 2471 | + |
| 2472 | + describe('Test CDR - Expression changed after it was checked', () => { |
| 2473 | + beforeEach(fakeAsync(() => { |
| 2474 | + fixture = TestBed.createComponent(IgxSelectCDRComponent); |
| 2475 | + fixture.detectChanges(); |
| 2476 | + tick(); |
| 2477 | + })); |
| 2478 | + it('Should NOT throw console Warning for "Expression changed after it was checked"', fakeAsync(() => { |
| 2479 | + const firstSelect = fixture.componentInstance.selectComponents.first as IgxSelectComponent; |
| 2480 | + spyOn(console, 'warn'); |
| 2481 | + |
| 2482 | + expect(firstSelect).toBeDefined(); |
| 2483 | + expect(firstSelect.value).toBe('ID'); |
| 2484 | + expect(console.warn).toHaveBeenCalledTimes(0); |
| 2485 | + |
| 2486 | + fixture.componentInstance.render = !fixture.componentInstance.render; |
| 2487 | + fixture.detectChanges(); |
| 2488 | + tick(); |
| 2489 | + |
| 2490 | + const lastSelect = fixture.componentInstance.selectComponents.last as IgxSelectComponent; |
| 2491 | + expect(lastSelect).toBeDefined(); |
| 2492 | + expect(lastSelect.value).toBe('CompanyName'); |
| 2493 | + expect(console.warn).toHaveBeenCalledTimes(0); |
| 2494 | + })); |
| 2495 | + }); |
2471 | 2496 |
|
2472 | 2497 | @Component({ |
2473 | 2498 | template: ` |
@@ -2794,3 +2819,47 @@ class IgxSelectHeaderFooterComponent implements OnInit { |
2794 | 2819 | } |
2795 | 2820 | } |
2796 | 2821 | } |
| 2822 | + |
| 2823 | + @Component({ |
| 2824 | + template: ` |
| 2825 | + <h4>*ngIf test select for 'expression changed...console Warning'</h4> |
| 2826 | + <div *ngIf="render"> |
| 2827 | + <igx-select #select value="ID"> |
| 2828 | + <label igxLabel>Column</label> |
| 2829 | + <igx-select-item *ngFor="let column of columns" [value]="column.field"> |
| 2830 | + {{column.field}} |
| 2831 | + </igx-select-item> |
| 2832 | + </igx-select> |
| 2833 | + </div> |
| 2834 | + <button igxButton (click)="render=!render">toggle render *ngIF</button> |
| 2835 | + <div *ngIf="!render"> |
| 2836 | + <igx-select #select value="CompanyName"> |
| 2837 | + <label igxLabel>Column</label> |
| 2838 | + <igx-select-item *ngFor="let column of columns" [value]="column.field"> |
| 2839 | + {{column.field}} |
| 2840 | + </igx-select-item> |
| 2841 | + </igx-select> |
| 2842 | + </div> |
| 2843 | +` |
| 2844 | + }) |
| 2845 | + class IgxSelectCDRComponent { |
| 2846 | + @ViewChildren(IgxSelectComponent) public selectComponents: QueryList<IgxSelectComponent>; |
| 2847 | + |
| 2848 | + public render = true; |
| 2849 | + public columns: Array<any> = [ |
| 2850 | + { field: 'ID', width: 80, resizable: true, movable: true, type: 'string' }, |
| 2851 | + { field: 'CompanyName', width: 150, resizable: true, movable: true, type: 'string' }, |
| 2852 | + { field: 'ContactName', width: 150, resizable: true, movable: true, type: 'string' }, |
| 2853 | + { field: 'Employees', width: 150, resizable: true, movable: true, type: 'number' }, |
| 2854 | + { field: 'ContactTitle', width: 150, resizable: true, movable: true, type: 'string' }, |
| 2855 | + { field: 'DateCreated', width: 150, resizable: true, movable: true, type: 'date' }, |
| 2856 | + { field: 'Address', width: 150, resizable: true, movable: true, type: 'string' }, |
| 2857 | + { field: 'City', width: 150, resizable: true, movable: true, type: 'string' }, |
| 2858 | + { field: 'Region', width: 150, resizable: true, movable: true, type: 'string' }, |
| 2859 | + { field: 'PostalCode', width: 150, resizable: true, movable: true, type: 'string' }, |
| 2860 | + { field: 'Phone', width: 150, resizable: true, movable: true, type: 'string' }, |
| 2861 | + { field: 'Fax', width: 150, resizable: true, movable: true, type: 'string' }, |
| 2862 | + { field: 'Contract', width: 150, resizable: true, movable: true, type: 'boolean' } |
| 2863 | + ]; |
| 2864 | + } |
| 2865 | +}); |
0 commit comments