From 3dff5c49ce7c41d85d64661a5b20bf37883b8805 Mon Sep 17 00:00:00 2001 From: vthinkxie Date: Mon, 11 Mar 2019 17:04:08 +0800 Subject: [PATCH] fix(module:table): fix th check not trigger bug (#3064) close #3028 close #3056 close #3058 --- components/table/demo/default-filter.ts | 1 + components/table/nz-th.component.html | 8 +++--- components/table/nz-th.component.ts | 3 -- components/table/nz-th.spec.ts | 38 +++++++++++++++++++++---- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/components/table/demo/default-filter.ts b/components/table/demo/default-filter.ts index 516f82ad66f..ca6e4cbf5ab 100644 --- a/components/table/demo/default-filter.ts +++ b/components/table/demo/default-filter.ts @@ -58,6 +58,7 @@ export class NzDemoTableDefaultFilterComponent { } filter(listOfSearchName: string[], searchAddress: string): void { + console.log(listOfSearchName, searchAddress); this.listOfSearchName = listOfSearchName; this.searchAddress = searchAddress; this.search(); diff --git a/components/table/nz-th.component.html b/components/table/nz-th.component.html index 27dacb65907..1face9aa325 100644 --- a/components/table/nz-th.component.html +++ b/components/table/nz-th.component.html @@ -43,7 +43,7 @@
- {{ locale.filterConfirm }} + {{ locale.filterConfirm }} - - {{ locale.filterReset }} + + {{ locale.filterReset }}
diff --git a/components/table/nz-th.component.ts b/components/table/nz-th.component.ts index 110c924341a..500ff1f37ae 100644 --- a/components/table/nz-th.component.ts +++ b/components/table/nz-th.component.ts @@ -129,14 +129,11 @@ export class NzThComponent implements OnChanges, OnInit, OnDestroy { } else { this.nzFilterChange.emit(this.filterValue); } - this.hideDropDown(); } reset(): void { this.initMultipleFilterList(true); this.initSingleFilterList(true); - this.search(); - this.hideDropDown(); this.hasFilterValue = false; } diff --git a/components/table/nz-th.spec.ts b/components/table/nz-th.spec.ts index 6d7f02b29fd..1c4d47defcd 100644 --- a/components/table/nz-th.spec.ts +++ b/components/table/nz-th.spec.ts @@ -1,6 +1,7 @@ import { Component, ViewChild } from '@angular/core'; -import { fakeAsync, flush, TestBed } from '@angular/core/testing'; +import { fakeAsync, flush, tick, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NzIconTestModule } from '../icon/nz-icon-test.module'; import { NzTableComponent } from './nz-table.component'; import { NzTableModule } from './nz-table.module'; @@ -9,7 +10,7 @@ import { NzThComponent } from './nz-th.component'; describe('nz-th', () => { beforeEach(fakeAsync(() => { TestBed.configureTestingModule({ - imports : [ NzTableModule, NzIconTestModule ], + imports : [ NzTableModule, NzIconTestModule, NoopAnimationsModule ], declarations: [ NzThTestNzTableComponent, NzThTestTableDefaultFilterComponent ] }); TestBed.compileComponents(); @@ -163,11 +164,11 @@ describe('nz-th', () => { it('should showFilter work', () => { fixture.detectChanges(); expect(th.nativeElement.classList).not.toContain('ant-table-column-has-filters'); - expect(th.nativeElement.querySelector('.anticon anticon-filter')).toBeNull(); + expect(th.nativeElement.querySelector('.anticon.anticon-filter')).toBeNull(); testComponent.showFilter = true; fixture.detectChanges(); expect(th.nativeElement.classList).toContain('ant-table-column-has-filters'); - expect(th.nativeElement.querySelector('.anticon anticon-filter')).toBeDefined(); + expect(th.nativeElement.querySelector('.anticon.anticon-filter')).toBeDefined(); }); it('should filterChange work', () => { testComponent.showFilter = true; @@ -217,6 +218,7 @@ describe('nz-th', () => { fixture.detectChanges(); expect(testComponent.filterChange).toHaveBeenCalledTimes(0); testComponent.nzThComponent.reset(); + testComponent.nzThComponent.dropDownVisibleChange(false); fixture.detectChanges(); expect(testComponent.filterChange).toHaveBeenCalledWith([]); expect(testComponent.nzThComponent.hasFilterValue).toBe(false); @@ -248,6 +250,31 @@ describe('nz-th', () => { }).createComponent(NzTestDisableThComponent); }).toThrow(); }); + it('should filter multiple check work', fakeAsync(() => { + fixture.detectChanges(); + testComponent.showFilter = true; + fixture.detectChanges(); + th.nativeElement.querySelector('.anticon.anticon-filter').click(); + fixture.detectChanges(); + tick(1000); + fixture.detectChanges(); + expect(testComponent.filterChange).toHaveBeenCalledTimes(0); + (document.querySelector('.ant-checkbox-input') as HTMLInputElement).click(); + fixture.detectChanges(); + tick(1000); + fixture.detectChanges(); + (document.querySelector('.confirm') as HTMLInputElement).click(); + fixture.detectChanges(); + tick(1000); + fixture.detectChanges(); + expect(testComponent.filterChange).toHaveBeenCalledTimes(1); + expect(testComponent.filterChange.calls.mostRecent().args[0][0]).toBe('1'); + // flush all microtask + testComponent.destroy = true; + fixture.detectChanges(); + tick(1000); + fixture.detectChanges(); + })); }); describe('nz-th with default filter in nz-table', () => { let fixture; @@ -268,7 +295,7 @@ describe('nz-th', () => { @Component({ selector: 'nz-th-test-nz-table', template: ` - + { }) export class NzThTestNzTableComponent { @ViewChild(NzThComponent) nzThComponent: NzThComponent; + destroy = false; showCheckbox = false; checked = false; checkedChange = jasmine.createSpy('show change');