@@ -92,12 +92,11 @@ describe('Control.LayerSwitcher', function () {
9292 expect ( radios [ 1 ] . checked ) . not . to . be . ok ( ) ;
9393 expect ( group . layers [ 0 ] . isVisible ( ) ) . to . be . ok ( ) ;
9494 expect ( group . layers [ 1 ] . isVisible ( ) ) . not . to . be . ok ( ) ;
95- radios [ 1 ] . addEventListener ( "click" , function ( ) {
96- expect ( radios [ 0 ] . checked ) . not . to . be . ok ( ) ;
97- expect ( radios [ 1 ] . checked ) . to . be . ok ( ) ;
98- expect ( group . layers [ 0 ] . isVisible ( ) ) . not . to . be . ok ( ) ;
99- expect ( group . layers [ 1 ] . isVisible ( ) ) . to . be . ok ( ) ;
100- } ) ;
95+ happen . click ( radios [ 1 ] ) ;
96+ expect ( radios [ 0 ] . checked ) . not . to . be . ok ( ) ;
97+ expect ( radios [ 1 ] . checked ) . to . be . ok ( ) ;
98+ expect ( group . layers [ 0 ] . isVisible ( ) ) . not . to . be . ok ( ) ;
99+ expect ( group . layers [ 1 ] . isVisible ( ) ) . to . be . ok ( ) ;
101100 } ) ;
102101
103102 it ( 'overlay layers switch' , function ( ) {
@@ -114,10 +113,12 @@ describe('Control.LayerSwitcher', function () {
114113 var checkbox = document . querySelector ( '.layer input' ) ;
115114 expect ( checkbox . checked ) . to . be . ok ( ) ;
116115 expect ( tile1 . isVisible ( ) ) . to . be . ok ( ) ;
117- checkbox . addEventListener ( " click" , function ( ) {
118- expect ( checkbox . checked ) . not . to . be . ok ( ) ;
119- expect ( tile1 . isVisible ( ) ) . not . to . be . ok ( ) ;
116+ happen . click ( checkbox , {
117+ 'clientX' : 100 ,
118+ 'clientY' : 100
120119 } ) ;
120+ expect ( checkbox . checked ) . not . to . be . ok ( ) ;
121+ expect ( tile1 . isVisible ( ) ) . not . to . be . ok ( ) ;
121122 } ) ;
122123
123124 it ( 'show and hide' , function ( ) {
@@ -155,4 +156,26 @@ describe('Control.LayerSwitcher', function () {
155156 } ) ;
156157 control . remove ( ) ;
157158 } ) ;
159+
160+ it ( 'disable if layer is transparent or out of zoom' , function ( ) {
161+ var control = new maptalks . control . LayerSwitcher ( ) ;
162+ map . addControl ( control ) ;
163+ var tile1 = new maptalks . TileLayer ( 'tile1' , {
164+ opacity : 0 ,
165+ urlTemplate : '/resources/tile.png'
166+ } ) ;
167+ var tile2 = new maptalks . TileLayer ( 'tile2' , {
168+ minZoom : 1 ,
169+ maxZoom : 1 ,
170+ urlTemplate : '/resources/tile.png'
171+ } ) ;
172+ map . addLayer ( tile1 , tile2 ) ;
173+ happen . mouseover ( control . button , {
174+ 'clientX' : 100 ,
175+ 'clientY' : 100
176+ } ) ;
177+ var checkbox = document . querySelectorAll ( '.layer input' ) ;
178+ expect ( checkbox [ 0 ] . getAttribute ( 'disabled' ) ) . to . be . eql ( 'disabled' ) ;
179+ expect ( checkbox [ 1 ] . getAttribute ( 'disabled' ) ) . to . be . eql ( 'disabled' ) ;
180+ } ) ;
158181} ) ;
0 commit comments