8000 fix(custom-select): fix test case · atinc/ngx-tethys@6a348a0 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 6a348a0

Browse files
committed
fix(custom-select): fix test case
1 parent 9b3b2e8 commit 6a348a0

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/select/custom-select.spec.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
import { FormsModule, FormControl, ReactiveFormsModule } from '@angular/forms';
1212
import { Component, ViewChild, ViewChildren, QueryList, ElementRef, Sanitizer, SecurityContext } from '@angular/core';
1313
import { ThySelectModule } from './module';
14-
import { ThySelectCustomComponent, SelectMode } from './custom-select.component';
15-
import { ThyOptionComponent } from './option.component';
14+
import { ThySelectCustomComponent, SelectMode } from './custom-select/custom-select.component';
15+
import { ThyOptionComponent } from './custom-select/option.component';
1616
import { By, DomSanitizer } from '@angular/platform-browser';
1717
import { UpdateHostClassService } from '../shared';
1818
import { ThyPositioningService } from '../positioning/positioning.service';
@@ -656,7 +656,9 @@ describe('ThyCustomSelect', () => {
656656

657657
expect(option.classList).toContain('active');
658658
expect(fixture.componentInstance.options.first.selected).toEqual(true);
659-
expect(fixture.componentInstance.select.selected).toBe(fixture.componentInstance.options.first);
659+
expect(fixture.componentInstance.select._selectionModel.selected[0]).toBe(
660+
fixture.componentInstance.options.first
661+
);
660662
}));
661663

662664
it('should be able to select to an option using th ThyOptionComponent API', fakeAsync(() => {
@@ -672,7 +674,7 @@ describe('ThyCustomSelect', () => {
672674
flush();
673675
expect(optionNodes[1].classList).toContain('active');
674676
expect(optionInstances[1].selected).toBe(true);
675-
expect(fixture.componentInstance.select.selected).toBe(optionInstances[1]);
677+
expect(fixture.componentInstance.select._selectionModel.selected[0]).toBe(optionInstances[1]);
676678
}));
677679

678680
it('should deselect other options when one is selected', fakeAsync(() => {
@@ -853,7 +855,7 @@ describe('ThyCustomSelect', () => {
853855
fixture.detectChanges();
854856

855857
expect(fixture.componentInstance.select.thyShowSearch).toBe(true);
856-
expect(overlayContainerElement.querySelector('thy-input-search')).not.toBeNull();
858+
expect(fixture.debugElement.query(By.css('.search-input-field'))).not.toBeNull();
857859
}));
858860
it('should hide the options that can not be searched', fakeAsync(() => {
859861
const fixture = TestBed.createComponent(SelectWithSearchComponent);
@@ -863,9 +865,10 @@ describe('ThyCustomSelect', () => {
863865
trigger.click();
864866
fixture.detectChanges();
865867

866-
const input = overlayContainerElement.querySelector('input');
868+
const input = fixture.debugElement.query(By.css('.search-input-field')).nativeElement;
867869

868870
typeInElement('Steak', input);
871+
flush();
869872
fixture.detectChanges();
870873
flush();
871874

@@ -888,12 +891,12 @@ describe('ThyCustomSelect', () => {
888891
}));
889892
it('should search option use thySearchKey', fakeAsync(() => {
890893
const fixture = TestBed.createComponent(SelectWithSearchUseSearchKeyComponent);
891-
const trigger = fixture.debugElement.query(By.css('.form-control-custom')).nativeElement;
892894
fixture.detectChanges();
895+
const trigger = fixture.debugElement.query(By.css('.form-control-custom')).nativeElement;
893896
trigger.click();
894897
fixture.detectChanges();
895898

896-
const input = overlayContainerElement.querySelector('input');
899+
const input = fixture.debugElement.query(By.css('.search-input-field')).nativeElement;
897900

898901
typeInElement('lrs', input);
899902
fixture.detectChanges();
@@ -914,15 +917,14 @@ describe('ThyCustomSelect', () => {
914917
}));
915918
it('should hide the thy-group when all options of the group is hidden', fakeAsync(() => {
916919
const fixture = TestBed.createComponent(SelectWithSearchAndGroupComponent);
917-
const trigger = fixture.debugElement.query(By.css('.form-control-custom')).nativeElement;
918-
919920
fixture.detectChanges();
921+
const trigger = fixture.debugElement.query(By.css('.form-control-custom')).nativeElement;
920922
trigger.click();
921923
fixture.detectChanges();
922924

923925
const groups = fixture.componentInstance.select.optionGroups.toArray();
924926
const options = fixture.componentInstance.select.options.toArray();
925-
const input = overlayContainerElement.querySelector('input');
927+
const input = fixture.debugElement.query(By.css('.search-input-field')).nativeElement;
926928
typeInElement('Cat', input);
927929

928930
tick(1000);
@@ -943,13 +945,14 @@ describe('ThyCustomSelect', () => {
943945
}));
944946
it('should exec thyOnSearch when thyServerSearch is true', fakeAsync(() => {
945947
const fixture = TestBed.createComponent(SelectWithSearchAndServerSearchComponent);
946-
const trigger = fixture.debugElement.query(By.css('.form-control-custom')).nativeElement;
947948
fixture.detectChanges();
949+
const trigger = fixture.debugElement.query(By.css('.form-control-custom')).nativeElement;
948950
trigger.click();
949951
fixture.detectChanges();
950952

951953
const spy = fixture.componentInstance.thyOnSearch;
952-
const input = overlayContainerElement.querySelector('input');
954+
const input = fixture.debugElement.query(By.css('.search-input-field')).nativeElement;
955+
953956
typeInElement('milk', input);
954957
fixture.detectChanges();
955958
tick();
@@ -965,8 +968,8 @@ describe('ThyCustomSelect', () => {
965968

966969
it('should remove the thy-option when sourcedata change', fakeAsync(() => {
967970
const fixture = TestBed.createComponent(SelectEimtOptionsChangesComponent);
968-
const trigger = fixture.debugElement.query(By.css('.form-control-custom')).nativeElement;
969971
fixture.detectChanges();
972+
const trigger = fixture.debugElement.query(By.css('.form-control-custom')).nativeElement;
970973
trigger.click();
971974
fixture.detectChanges();
972975

@@ -1002,7 +1005,7 @@ describe('ThyCustomSelect', () => {
10021005
fixture.detectChanges();
10031006
flush();
10041007

1005-
const selectContainer = overlayContainerElement.querySelector('.thy-select-container');
1008+
const selectContainer = overlayContainerElement.querySelector('.thy-custom-select-dropdown');
10061009
dispatchFakeEvent(selectContainer, 'mouseleave');
10071010
fixture.detectChanges();
10081011

0 commit comments

Comments
 (0)
0