@@ -69,10 +69,10 @@ describe('GPS Plugin', () => {
6969 test ( `button disabled when ${ field } is invalid` , ( ) => {
7070 const fieldInput = gps . inputComponents [ field ] ;
7171 const submitButton = document . querySelector ( '.gm-gps-update' ) ;
72- fieldInput . value = value ;
73- fieldInput . dispatchEvent (
74- new CustomEvent ( 'gm-text- input-change' , { detail : { value : value } , bubbles : true } ) ,
75- ) ;
72+
73+ const input = fieldInput . querySelector ( 'input' ) ;
74+ input . value = value ;
75+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
7676 if ( field !== 'accuracy' && field !== 'bearing' ) {
7777 expect (
7878 fieldInput . querySelector ( '.text-input-message' ) . classList . contains ( 'hidden' ) ,
@@ -109,63 +109,13 @@ describe('GPS Plugin', () => {
109109 sendEventSpy . mockRestore ( ) ;
110110 } ) ;
111111
112- /*
113- *test('invalid input value', () => {
114- * gps.inputComponents.altitude.value = 'jean-michel';
115- * gps.inputComponents.altitude.dispatchEvent(new CustomEvent('gm-text-input-change', { detail: { value: 'jean-michel' }, bubbles: true }));
116- *
117- * gps.inputComponents.latitude.value = 'jean-michel';
118- * gps.inputComponents.latitude.dispatchEvent(new CustomEvent('gm-text-input-change', { detail: { value: 'jean-michel' }, bubbles: true }));
119- *
120- * gps.inputComponents.longitude.value = 'jean-michel';
121- * gps.inputComponents.longitude.dispatchEvent(new CustomEvent('gm-text-input-change', { detail: { value: 'jean-michel' }, bubbles: true }));
122- *
123- * gps.inputComponents.accuracy.value = 'jean-michel';
124- * gps.inputComponents.accuracy.dispatchEvent(new CustomEvent('gm-text-input-change', { detail: { value: 'jean-michel' }, bubbles: true }));
125- *
126- * gps.inputComponents.bearing.value = 'jean-michel';
127- * gps.inputComponents.bearing.dispatchEvent(new CustomEvent('gm-text-input-change', { detail: { value: 'jean-michel' }, bubbles: true }));
128- *
129- * gps.inputComponents.speed.value = 'jean-michel';
130- * gps.inputComponents.speed.dispatchEvent(new CustomEvent('gm-text-input-change', { detail: { value: 'jean-michel' }, bubbles: true }));
131- * expect(document.querySelector('.gm-gps-update').disabled).toBeTruthy();
132- *
133- * document.querySelector('.gm-gps-update').click();
134- *
135- * expect(sendEventSpy).toHaveBeenCalledTimes(0);
136- *});
137- */
138-
139112 test ( 'min value' , ( ) => {
140- gps . inputComponents . altitude . value = '-10000' ;
141- gps . inputComponents . altitude . dispatchEvent (
142- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '-10000' } , bubbles : true } ) ,
143- ) ;
144-
145- gps . inputComponents . latitude . value = '-90' ;
146- gps . inputComponents . latitude . dispatchEvent (
147- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '-90' } , bubbles : true } ) ,
148- ) ;
149-
150- gps . inputComponents . longitude . value = '-180' ;
151- gps . inputComponents . longitude . dispatchEvent (
152- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '-180' } , bubbles : true } ) ,
153- ) ;
154-
155- gps . inputComponents . accuracy . value = '0' ;
156- gps . inputComponents . accuracy . dispatchEvent (
157- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '0' } , bubbles : true } ) ,
158- ) ;
159-
160- gps . inputComponents . bearing . value = '0' ;
161- gps . inputComponents . bearing . dispatchEvent (
162- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '0' } , bubbles : true } ) ,
163- ) ;
164-
165- gps . inputComponents . speed . value = '0' ;
166- gps . inputComponents . speed . dispatchEvent (
167- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '0' } , bubbles : true } ) ,
168- ) ;
113+ [ 'altitude' , 'latitude' , 'longitude' , 'accuracy' , 'bearing' , 'speed' ] . forEach ( ( field , index ) => {
114+ const vals = [ '-10000' , '-90' , '-180' , '0' , '0' , '0' ] ;
115+ const input = gps . inputComponents [ field ] . querySelector ( 'input' ) ;
116+ input . value = vals [ index ] ;
117+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
118+ } ) ;
169119 document . querySelector ( '.gm-gps-update' ) . click ( ) ;
170120
171121 expect ( sendEventSpy ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -184,35 +134,12 @@ describe('GPS Plugin', () => {
184134 } ) ;
185135
186136 test ( 'max value' , ( ) => {
187- gps . inputComponents . altitude . value = '10000' ;
188- gps . inputComponents . altitude . dispatchEvent (
189- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '10000' } , bubbles : true } ) ,
190- ) ;
191-
192- gps . inputComponents . latitude . value = '90' ;
193- gps . inputComponents . latitude . dispatchEvent (
194- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '90' } , bubbles : true } ) ,
195- ) ;
196-
197- gps . inputComponents . longitude . value = '180' ;
198- gps . inputComponents . longitude . dispatchEvent (
199- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '180' } , bubbles : true } ) ,
200- ) ;
201-
202- gps . inputComponents . accuracy . value = '200' ;
203- gps . inputComponents . accuracy . dispatchEvent (
204- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '200' } , bubbles : true } ) ,
205- ) ;
206-
207- gps . inputComponents . bearing . value = '360' ;
208- gps . inputComponents . bearing . dispatchEvent (
209- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '360' } , bubbles : true } ) ,
210- ) ;
211-
212- gps . inputComponents . speed . value = '399.99' ;
213- gps . inputComponents . speed . dispatchEvent (
214- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '399.99' } , bubbles : true } ) ,
215- ) ;
137+ [ 'altitude' , 'latitude' , 'longitude' , 'accuracy' , 'bearing' , 'speed' ] . forEach ( ( field , index ) => {
138+ const vals = [ '10000' , '90' , '180' , '200' , '360' , '399.99' ] ;
139+ const input = gps . inputComponents [ field ] . querySelector ( 'input' ) ;
140+ input . value = vals [ index ] ;
141+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
142+ } ) ;
216143 document . querySelector ( '.gm-gps-update' ) . click ( ) ;
217144
218145 expect ( sendEventSpy ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -231,35 +158,12 @@ describe('GPS Plugin', () => {
231158 } ) ;
232159
233160 test ( 'nominal value' , ( ) => {
234- gps . inputComponents . altitude . value = '420' ;
235- gps . inputComponents . altitude . dispatchEvent (
236- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '420' } , bubbles : true } ) ,
237- ) ;
238-
239- gps . inputComponents . latitude . value = '69' ; // Nice
240- gps . inputComponents . latitude . dispatchEvent (
241- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '69' } , bubbles : true } ) ,
242- ) ;
243-
244- gps . inputComponents . longitude . value = '3.14' ;
245- gps . inputComponents . longitude . dispatchEvent (
246- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '3.14' } , bubbles : true } ) ,
247- ) ;
248-
249- gps . inputComponents . accuracy . value = '42' ;
250- gps . inputComponents . accuracy . dispatchEvent (
251- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '42' } , bubbles : true } ) ,
252- ) ;
253-
254- gps . inputComponents . bearing . value = '13' ;
255- gps . inputComponents . bearing . dispatchEvent (
256- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '13' } , bubbles : true } ) ,
257- ) ;
258-
259- gps . inputComponents . speed . value = '399' ;
260- gps . inputComponents . speed . dispatchEvent (
261- new CustomEvent ( 'gm-text-input-change' , { detail : { value : '399' } , bubbles : true } ) ,
262- ) ;
161+ [ 'altitude' , 'latitude' , 'longitude' , 'accuracy' , 'bearing' , 'speed' ] . forEach ( ( field , index ) => {
162+ const vals = [ '420' , '69' , '3.14' , '42' , '13' , '399' ] ;
163+ const input = gps . inputComponents [ field ] . querySelector ( 'input' ) ;
164+ input . value = vals [ index ] ;
165+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
166+ } ) ;
263167 document . querySelector ( '.gm-gps-update' ) . click ( ) ;
264168
265169 expect ( sendEventSpy ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments