@@ -1162,13 +1162,15 @@ describe('select', () => {
11621162 describe ( 'multiple reactive mode' , ( ) => {
11631163 let component : TestSelectReactiveMultipleComponent ;
11641164 let fixture : ComponentFixture < TestSelectReactiveMultipleComponent > ;
1165+ let selectComponent : NzSelectComponent ;
11651166 let selectElement ! : HTMLElement ;
11661167 let overlayContainerElement : HTMLElement ;
11671168
11681169 beforeEach ( ( ) => {
11691170 fixture = TestBed . createComponent ( TestSelectReactiveMultipleComponent ) ;
11701171 component = fixture . componentInstance ;
11711172 fixture . detectChanges ( ) ;
1173+ selectComponent = fixture . debugElement . query ( By . directive ( NzSelectComponent ) ) . componentInstance ;
11721174 selectElement = fixture . debugElement . query ( By . directive ( NzSelectComponent ) ) . nativeElement ;
11731175 overlayContainerElement = TestBed . inject ( OverlayContainer ) . getContainerElement ( ) ;
11741176 } ) ;
@@ -1332,6 +1334,65 @@ describe('select', () => {
13321334 expect ( listOfContainerItem [ 1 ] ) . toHaveClass ( 'ant-select-item-option-disabled' ) ;
13331335 } ) ) ;
13341336
1337+ it ( 'should isMaxMultipleCountSet work correct' , ( ) => {
1338+ component . nzMaxMultipleCount = Infinity ;
1339+ fixture . detectChanges ( ) ;
1340+ expect ( selectComponent . isMaxMultipleCountSet ) . toBeFalsy ( ) ;
1341+
1342+ component . nzMaxMultipleCount = 1 ;
1343+ fixture . detectChanges ( ) ;
1344+ expect ( selectComponent . isMaxMultipleCountSet ) . toBeTruthy ( ) ;
1345+ } ) ;
1346+
1347+ it ( 'should isMaxMultipleCountReached be set correctly when click options' , fakeAsync ( ( ) => {
1348+ const flushRefresh = ( ) : void => {
1349+ fixture . detectChanges ( ) ;
1350+ flush ( ) ;
1351+ fixture . detectChanges ( ) ;
1352+ } ;
1353+ component . nzOpen = true ;
1354+ component . listOfOption = [
1355+ { value : 'test_01' , label : 'test_01' } ,
1356+ { value : 'test_02' , label : 'test_02' }
1357+ ] ;
1358+ component . value = [ ] ;
1359+ component . nzMaxMultipleCount = 1 ;
1360+ flushRefresh ( ) ;
1361+ expect ( selectComponent . isMaxMultipleCountReached ) . toBeFalsy ( ) ;
1362+ const listOfContainerItem = document . querySelectorAll ( 'nz-option-item' ) ;
1363+ dispatchMouseEvent ( listOfContainerItem [ 0 ] , 'click' ) ;
1364+ flushRefresh ( ) ;
1365+ expect ( selectComponent . isMaxMultipleCountReached ) . toBeTruthy ( ) ;
1366+ } ) ) ;
1367+
1368+ it ( 'should isMaxMultipleCountReached be set correctly when change the ng model value' , fakeAsync ( ( ) => {
1369+ const options = [
1370+ { value : 'test_01' , label : 'test_01' } ,
1371+ { value : 'test_02' , label : 'test_02' }
1372+ ] ;
1373+ const flushRefresh = ( ) : void => {
1374+ fixture . detectChanges ( ) ;
1375+ flush ( ) ;
1376+ fixture . detectChanges ( ) ;
1377+ } ;
1378+ component . nzOpen = true ;
1379+ component . listOfOption = options ;
1380+ component . value = [ ] ;
1381+ component . nzMaxMultipleCount = 1 ;
1382+ flushRefresh ( ) ;
1383+ const listOfContainerItem = document . querySelectorAll ( 'nz-option-item' ) ;
1384+ expect ( selectComponent . isMaxMultipleCountReached ) . toBeFalsy ( ) ;
1385+ selectComponent . writeValue ( [ options [ 0 ] ] ) ;
1386+ flushRefresh ( ) ;
1387+ expect ( selectComponent . isMaxMultipleCountReached ) . toBeTruthy ( ) ;
1388+ expect ( listOfContainerItem [ 1 ] ) . toHaveClass ( 'ant-select-item-option-disabled' ) ;
1389+ selectComponent . writeValue ( [ ] ) ;
1390+ flushRefresh ( ) ;
1391+ expect ( selectComponent . isMaxMultipleCountReached ) . toBeFalsy ( ) ;
1392+ expect ( listOfContainerItem [ 0 ] ) . not . toHaveClass ( 'ant-select-item-option-disabled' ) ;
1393+ expect ( listOfContainerItem [ 1 ] ) . not . toHaveClass ( 'ant-select-item-option-disabled' ) ;
1394+ } ) ) ;
1395+
13351396 it ( 'should show nzShowArrow component when having nzMaxMultipleCount' , ( ) => {
13361397 component . nzMaxMultipleCount = 0 ;
13371398 expect ( selectElement . querySelector ( 'nz-select-arrow' ) ) . toBeFalsy ( ) ;
@@ -1493,33 +1554,6 @@ describe('select', () => {
14931554 // expect(requestAnimationFrameSpy).toHaveBeenCalledTimes(2);
14941555 } ) ) ;
14951556
1496- it ( 'should isMaxTagCountSet work correct' , ( ) => {
1497- component . nzMaxMultipleCount = Infinity ;
1498- fixture . detectChanges ( ) ;
1499- let isMaxTagCountSet ;
1500- isMaxTagCountSet = selectComponent [ 'isMaxTagCountSet' ] ;
1501- expect ( isMaxTagCountSet ) . toBeFalsy ( ) ;
1502-
1503- component . nzMaxMultipleCount = 1 ;
1504- fixture . detectChanges ( ) ;
1505- isMaxTagCountSet = selectComponent [ 'isMaxTagCountSet' ] ;
1506- expect ( isMaxTagCountSet ) . toBeTruthy ( ) ;
1507- } ) ;
1508-
1509- it ( 'should isMaxLimitReached be set correctly' , ( ) => {
1510- selectComponent . nzMaxMultipleCount = 2 ;
1511- selectComponent . listOfValue = [ 'a' , 'b' ] ;
1512- fixture . detectChanges ( ) ;
1513- selectComponent . updateListOfValue ( [ 'a' , 'b' ] ) ;
1514- expect ( selectComponent . isMaxLimitReached ) . toBeTruthy ( ) ;
1515-
1516- selectComponent . nzMaxMultipleCount = 20 ;
1517- selectComponent . listOfValue = [ 'a' , 'b' ] ;
1518- fixture . detectChanges ( ) ;
1519- selectComponent . updateListOfValue ( [ 'a' , 'b' ] ) ;
1520- expect ( selectComponent . isMaxLimitReached ) . toBeFalsy ( ) ;
1521- } ) ;
1522-
15231557 it ( 'should not run change detection when `nz-select-top-control` is clicked and should focus the `nz-select-search`' , ( ) => {
15241558 const appRef = TestBed . inject ( ApplicationRef ) ;
15251559 spyOn ( appRef , 'tick' ) ;
0 commit comments