|
1 | 1 | import { BACKSPACE, DOWN_ARROW, ENTER, ESCAPE, SPACE, TAB, UP_ARROW } from '@angular/cdk/keycodes';
|
2 | 2 | import { OverlayContainer } from '@angular/cdk/overlay';
|
3 | 3 | import { ApplicationRef, Component, TemplateRef, ViewChild } from '@angular/core';
|
4 |
| -import { ComponentFixture, TestBed, fakeAsync, flush, inject, tick } from '@angular/core/testing'; |
| 4 | +import { ComponentFixture, fakeAsync, flush, inject, TestBed, tick } from '@angular/core/testing'; |
5 | 5 | import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
6 | 6 | import { By } from '@angular/platform-browser';
|
7 | 7 |
|
8 | 8 | import {
|
9 |
| - ɵComponentBed as ComponentBed, |
10 |
| - ɵcreateComponentBed as createComponentBed, |
11 | 9 | dispatchFakeEvent,
|
12 | 10 | dispatchKeyboardEvent,
|
13 |
| - dispatchMouseEvent |
| 11 | + dispatchMouseEvent, |
| 12 | + ɵComponentBed as ComponentBed, |
| 13 | + ɵcreateComponentBed as createComponentBed |
14 | 14 | } from 'ng-zorro-antd/core/testing';
|
15 | 15 | import { NzSafeAny, NzStatus } from 'ng-zorro-antd/core/types';
|
16 | 16 | import { NzFormControlStatusType, NzFormModule } from 'ng-zorro-antd/form';
|
@@ -586,13 +586,16 @@ describe('select', () => {
|
586 | 586 | let component: TestSelectTemplateMultipleComponent;
|
587 | 587 | let fixture: ComponentFixture<TestSelectTemplateMultipleComponent>;
|
588 | 588 | let selectElement!: HTMLElement;
|
| 589 | + let overlayContainerElement: HTMLElement; |
| 590 | + |
589 | 591 | beforeEach(() => {
|
590 | 592 | testBed = createComponentBed(TestSelectTemplateMultipleComponent, {
|
591 | 593 | imports: [NzSelectModule, NzIconTestModule, FormsModule]
|
592 | 594 | });
|
593 | 595 | component = testBed.component;
|
594 | 596 | fixture = testBed.fixture;
|
595 | 597 | selectElement = testBed.debugElement.query(By.directive(NzSelectComponent)).nativeElement;
|
| 598 | + overlayContainerElement = TestBed.inject(OverlayContainer).getContainerElement(); |
596 | 599 | });
|
597 | 600 | it('should classname correct', () => {
|
598 | 601 | expect(selectElement.classList).toContain('ant-select-multiple');
|
@@ -773,6 +776,35 @@ describe('select', () => {
|
773 | 776 | flushRefresh();
|
774 | 777 | expect(inputElement.value).toBe('test');
|
775 | 778 | }));
|
| 779 | + it('should nzAutoClearSearchValue work when cdkOverlay send emit close', fakeAsync(() => { |
| 780 | + const flushRefresh = (): void => { |
| 781 | + fixture.detectChanges(); |
| 782 | + flush(); |
| 783 | + fixture.detectChanges(); |
| 784 | + }; |
| 785 | + component.nzOpen = true; |
| 786 | + component.listOfOption = [ |
| 787 | + { nzValue: 'test_01', nzLabel: 'test_01' }, |
| 788 | + { nzValue: 'test_02', nzLabel: 'test_02' } |
| 789 | + ]; |
| 790 | + flushRefresh(); |
| 791 | + const listOfContainerItem = document.querySelectorAll('nz-option-item'); |
| 792 | + const inputElement = selectElement.querySelector('input')!; |
| 793 | + inputElement.value = 'test'; |
| 794 | + dispatchFakeEvent(inputElement, 'input'); |
| 795 | + dispatchMouseEvent(listOfContainerItem[0], 'click'); |
| 796 | + flushRefresh(); |
| 797 | + expect(inputElement.value).toBe(''); |
| 798 | + component.nzAutoClearSearchValue = false; |
| 799 | + flushRefresh(); |
| 800 | + inputElement.value = 'test'; |
| 801 | + dispatchFakeEvent(inputElement, 'input'); |
| 802 | + dispatchKeyboardEvent(overlayContainerElement, 'keydown', ESCAPE, overlayContainerElement); |
| 803 | + fixture.detectChanges(); |
| 804 | + flushRefresh(); |
| 805 | + fixture.detectChanges(); |
| 806 | + expect(inputElement.value).toBe('test'); |
| 807 | + })); |
776 | 808 | });
|
777 | 809 | describe('tags template mode', () => {
|
778 | 810 | let testBed: ComponentBed<TestSelectTemplateTagsComponent>;
|
@@ -1079,13 +1111,16 @@ describe('select', () => {
|
1079 | 1111 | let component: TestSelectReactiveMultipleComponent;
|
1080 | 1112 | let fixture: ComponentFixture<TestSelectReactiveMultipleComponent>;
|
1081 | 1113 | let selectElement!: HTMLElement;
|
| 1114 | + let overlayContainerElement: HTMLElement; |
| 1115 | + |
1082 | 1116 | beforeEach(() => {
|
1083 | 1117 | testBed = createComponentBed(TestSelectReactiveMultipleComponent, {
|
1084 | 1118 | imports: [NzSelectModule, NzIconTestModule, FormsModule]
|
1085 | 1119 | });
|
1086 | 1120 | component = testBed.component;
|
1087 | 1121 | fixture = testBed.fixture;
|
1088 | 1122 | selectElement = testBed.debugElement.query(By.directive(NzSelectComponent)).nativeElement;
|
| 1123 | + overlayContainerElement = TestBed.inject(OverlayContainer).getContainerElement(); |
1089 | 1124 | });
|
1090 | 1125 | it('should ngModel works', fakeAsync(() => {
|
1091 | 1126 | component.listOfOption = [
|
@@ -1263,6 +1298,35 @@ describe('select', () => {
|
1263 | 1298 | flushRefresh();
|
1264 | 1299 | expect(inputElement.value).toBe('test');
|
1265 | 1300 | }));
|
| 1301 | + it('should nzAutoClearSearchValue work when cdkOverlay send emit close', fakeAsync(() => { |
| 1302 | + const flushRefresh = (): void => { |
| 1303 | + fixture.detectChanges(); |
| 1304 | + flush(); |
| 1305 | + fixture.detectChanges(); |
| 1306 | + }; |
| 1307 | + component.nzOpen = true; |
| 1308 | + component.listOfOption = [ |
| 1309 | + { value: 'test_01', label: 'test_01' }, |
| 1310 | + { value: 'test_02', label: 'test_02' } |
| 1311 | + ]; |
| 1312 | + flushRefresh(); |
| 1313 | + const listOfContainerItem = document.querySelectorAll('nz-option-item'); |
| 1314 | + const inputElement = selectElement.querySelector('input')!; |
| 1315 | + inputElement.value = 'test'; |
| 1316 | + dispatchFakeEvent(inputElement, 'input'); |
| 1317 | + dispatchMouseEvent(listOfContainerItem[0], 'click'); |
| 1318 | + flushRefresh(); |
| 1319 | + expect(inputElement.value).toBe(''); |
| 1320 | + component.nzAutoClearSearchValue = false; |
| 1321 | + flushRefresh(); |
| 1322 | + inputElement.value = 'test'; |
| 1323 | + dispatchFakeEvent(inputElement, 'input'); |
| 1324 | + dispatchKeyboardEvent(overlayContainerElement, 'keydown', ESCAPE, overlayContainerElement); |
| 1325 | + fixture.detectChanges(); |
| 1326 | + flushRefresh(); |
| 1327 | + fixture.detectChanges(); |
| 1328 | + expect(inputElement.value).toBe('test'); |
| 1329 | + })); |
1266 | 1330 | });
|
1267 | 1331 | describe('tags reactive mode', () => {
|
1268 | 1332 | let testBed: ComponentBed<TestSelectReactiveTagsComponent>;
|
|
0 commit comments