Skip to content

Commit 64a249e

Browse files
committed
test(grid): add test cases for empty filter state
1 parent 648faf1 commit 64a249e

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

projects/angular/components/ui-grid/src/ui-grid.component.spec.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,6 +2836,113 @@ describe('Component: UiGrid', () => {
28362836
});
28372837
});
28382838

2839+
describe('Behaviour: use empty state value for filters', () => {
2840+
@Component({
2841+
template: `
2842+
<ui-grid>
2843+
<ui-grid-header [search]="true">
2844+
</ui-grid-header>
2845+
<ui-grid-column property="id"
2846+
title="Id">
2847+
<ui-grid-dropdown-filter [items]="filterItems"
2848+
[visible]="true"
2849+
[value]="value"
2850+
[emptyStateValue]="emptyStateValue">
2851+
</ui-grid-dropdown-filter>
2852+
</ui-grid-column>
2853+
</ui-grid>
2854+
`,
2855+
})
2856+
class TestFixtureAlternateDesignGridComponent {
2857+
get filterItems(): IDropdownOption[] {
2858+
return [1, 2, 3].map(count => ({
2859+
value: count,
2860+
label: count.toString(),
2861+
}));
2862+
}
2863+
value?: IDropdownOption;
2864+
emptyStateValue?: IDropdownOption['value'];
2865+
}
2866+
2867+
let fixture: ComponentFixture<TestFixtureAlternateDesignGridComponent>;
2868+
let component: TestFixtureAlternateDesignGridComponent;
2869+
2870+
beforeEach(() => {
2871+
TestBed.configureTestingModule({
2872+
imports: [
2873+
UiGridModule,
2874+
UiGridCustomPaginatorModule,
2875+
NoopAnimationsModule,
2876+
],
2877+
providers: [
2878+
UiMatPaginatorIntl,
2879+
{
2880+
provide: UI_GRID_OPTIONS,
2881+
useValue: {
2882+
useLegacyDesign: false,
2883+
collapsibleFilters: true,
2884+
fetchStrategy: 'eager',
2885+
},
2886+
},
2887+
],
2888+
declarations: [
2889+
TestFixtureAlternateDesignGridComponent,
2890+
],
2891+
});
2892+
2893+
fixture = TestBed.createComponent(TestFixtureAlternateDesignGridComponent);
2894+
component = fixture.componentInstance;
2895+
});
2896+
2897+
afterEach(() => {
2898+
fixture.destroy();
2899+
});
2900+
2901+
it('should count applied default filter when there is not empty filter state', () => {
2902+
component.value = {
2903+
value: '123',
2904+
label: '123',
2905+
};
2906+
fixture.detectChanges();
2907+
2908+
const collapisbleFiltersToggleText = fixture.debugElement
2909+
.query(By.css('.ui-grid-collapsible-filters-toggle span span'));
2910+
2911+
expect(collapisbleFiltersToggleText.nativeElement.innerText).toBe('Filters (1)');
2912+
});
2913+
2914+
it('should count applied default filter when it is different from the empty filter state', fakeAsync(() => {
2915+
component.value = {
2916+
value: '123',
2917+
label: '123',
2918+
};
2919+
component.emptyStateValue = '12';
2920+
fixture.detectChanges();
2921+
2922+
const collapisbleFiltersToggleText = fixture.debugElement
2923+
.query(By.css('.ui-grid-collapsible-filters-toggle span span'));
2924+
2925+
expect(collapisbleFiltersToggleText.nativeElement.innerText).toBe('Filters (1)');
2926+
expect(fixture.debugElement.query(By.css('.ui-grid-header-title-filtered'))).toBeTruthy();
2927+
tick(1000);
2928+
}));
2929+
2930+
it('should not count applied default filter when it is equal to empty filter state', () => {
2931+
fixture.componentInstance.value = {
2932+
value: '123',
2933+
label: '123',
2934+
};
2935+
component.emptyStateValue = '123';
2936+
fixture.detectChanges();
2937+
2938+
const collapisbleFiltersToggleText = fixture.debugElement
2939+
.query(By.css('.ui-grid-collapsible-filters-toggle span span'));
2940+
2941+
expect(collapisbleFiltersToggleText.nativeElement.innerText).toBe('Filters');
2942+
expect(fixture.debugElement.query(By.css('.ui-grid-header-title-filtered'))).toBeNull();
2943+
});
2944+
});
2945+
28392946
describe('Behavior: override injection token value', () => {
28402947
@Component({
28412948
template: `

0 commit comments

Comments
 (0)