11import { test , expect , chromium } from '@playwright/test' ;
22let browserLocale , enLocale , frLocale , locales ;
33
4+ test . use ( {
5+ geolocation : { longitude : - 73.56766530667056 , latitude : 45.5027789304487 } ,
6+ permissions : [ 'geolocation' ]
7+ } ) ;
8+
49test . describe ( '<mapml-viewer> localization tests' , ( ) => {
510 let page ;
611 let context ;
712 test . beforeAll ( async ( ) => {
8- context = await chromium . launchPersistentContext ( '' ) ;
13+ context = await chromium . launchPersistentContext ( '' , {
14+ headless : false
15+ } ) ;
916 page =
1017 context . pages ( ) . find ( ( page ) => page . url ( ) === 'about:blank' ) ||
1118 ( await context . newPage ( ) ) ;
@@ -159,13 +166,6 @@ test.describe('<mapml-viewer> localization tests', () => {
159166 } ) ;
160167
161168 test ( 'Hover messages in top left control buttons matches the locale key' , async ( ) => {
162- const buttonNames = [
163- 'btnZoomIn' ,
164- 'btnZoomOut' ,
165- 'btnFullScreen' ,
166- 'btnExitFullScreen'
167- ] ;
168-
169169 for ( const [ language , locale ] of locales ) {
170170 // select the current map
171171 const map = await page . getByTestId ( language ) ;
@@ -188,7 +188,7 @@ test.describe('<mapml-viewer> localization tests', () => {
188188 expect ( reloadText ) . toBeTruthy ( ) ;
189189 expect ( reloadText ) . toBe ( locale . cmReload ) ;
190190
191- // fullscreen
191+ // fullscreen text
192192 const fullscreen = await map . locator (
193193 '.leaflet-control-fullscreen-button.leaflet-bar-part'
194194 ) ;
@@ -199,16 +199,19 @@ test.describe('<mapml-viewer> localization tests', () => {
199199 // click fullscreen button
200200 await fullscreen . click ( ) ;
201201
202- // exit fullscreen
203- // await expect(fullscreen).toHaveAttribute('title', locale.btnExitFullScreen);
204- // await page.waitForTimeout(5000);
205- // const exitFullscreen = await map.locator(
206- // '.leaflet-control-fullscreen-button.leaflet-bar-part'
207- // );
208- // const exitFullscreenText = await exitFullscreen.getAttribute('title');
209- // expect(exitFullscreenText).toBeTruthy();
210- // expect(exitFullscreenText).toBe(locale.btnExitFullScreen);
202+ // exit fullscreen text
203+ await expect ( fullscreen ) . toHaveAttribute (
204+ 'title' ,
205+ locale . btnExitFullScreen
206+ ) ;
207+ const exitFullscreen = await map . locator (
208+ '.leaflet-control-fullscreen-button.leaflet-bar-part'
209+ ) ;
210+ const exitFullscreenText = await exitFullscreen . getAttribute ( 'title' ) ;
211+ expect ( exitFullscreenText ) . toBeTruthy ( ) ;
212+ expect ( exitFullscreenText ) . toBe ( locale . btnExitFullScreen ) ;
211213
214+ // exit fullscreen
212215 await fullscreen . click ( ) ;
213216 }
214217 } ) ;
@@ -225,6 +228,34 @@ test.describe('<mapml-viewer> localization tests', () => {
225228 for ( const [ language , locale ] of locales ) {
226229 // select the current map
227230 const map = await page . getByTestId ( language ) ;
231+
232+ // hover text for turning on show location
233+ const showLocation = await map . locator (
234+ '.leaflet-bar-part.leaflet-bar-part-single'
235+ ) ;
236+ let showLocationText = await showLocation . getAttribute ( 'title' ) ;
237+ expect ( showLocationText ) . toBeTruthy ( ) ;
238+ expect ( showLocationText ) . toBe ( locale . btnLocTrackOff ) ;
239+
240+ // click show location
241+ await showLocation . click ( ) ;
242+
243+ // my current location
244+ const curLocation = await map . locator (
245+ '.leaflet-pane.leaflet-tooltip-pane'
246+ ) ;
247+ const curLocationText = await curLocation . textContent ( ) ;
248+ expect ( curLocationText ) . toBe ( locale . btnMyLocTrackOn ) ;
249+
250+ // hover text for turning off show location
251+ showLocationText = await showLocation . getAttribute ( 'title' ) ;
252+ expect ( showLocationText ) . toBeTruthy ( ) ;
253+ expect ( showLocationText ) . toBe ( locale . btnLocTrackOn ) ;
254+
255+ // turn off show location
256+ await showLocation . click ( ) ;
257+
258+ // when are btnLocTrackLastKnown and btnMyLastKnownLocTrackOn used?
228259 }
229260 } ) ;
230261
@@ -248,31 +279,54 @@ test.describe('<mapml-viewer> localization tests', () => {
248279 for ( const [ language , locale ] of locales ) {
249280 // select the current map
250281 const map = await page . getByTestId ( language ) ;
282+
283+ // where do we access these?
251284 }
252285 } ) ;
253286
254287 test ( 'Keyboard feature messages matches the locale key' , async ( ) => {
255288 // in the attribution button, check that the keyboard feature messages
256289 // are translated
257- const buttonNames = [
258- 'kbdShortcuts' ,
259- 'kbdMovement' ,
260- 'kbdFeature' ,
290+ const dialogBolded = [ 'kbdShortcuts' , 'kbdMovement' , 'kbdFeature' ] ;
291+
292+ const dialogListItems = [
261293 'kbdPanUp' ,
262294 'kbdPanDown' ,
263295 'kbdPanLeft' ,
264296 'kbdPanRight' ,
297+ 'btnZoomIn' ,
298+ 'btnZoomOut' ,
299+ 'kbdPanIncrement' ,
265300 'kbdPanIncrement' ,
266301 'kbdZoom' ,
267- 'kbdFocusMap' ,
268- 'kbdFocusControls' ,
269302 'kbdPrevFeature' ,
270303 'kbdNextFeature'
271304 ] ;
272305
273306 for ( const [ language , locale ] of locales ) {
274307 // select the current map
275308 const map = await page . getByTestId ( language ) ;
309+
310+ // locate the dialog element
311+ const dialog = await map . locator ( 'dialog' ) ;
312+
313+ // check that the bolded texts are translated correctly
314+ const bolded = await dialog . locator ( 'b' ) ;
315+ const countBolded = await bolded . count ( ) ;
316+ for ( let i = 0 ; i < countBolded ; i ++ ) {
317+ const text = await bolded . nth ( i ) . textContent ( ) ;
318+ expect ( text ) . toBeTruthy ( ) ;
319+ expect ( text . startsWith ( locale [ dialogBolded [ i ] ] ) ) . toBe ( true ) ;
320+ }
321+
322+ // check that the list items are translated correctly
323+ const listItems = await dialog . locator ( 'li' ) ;
324+ const countListItems = await listItems . count ( ) ;
325+ for ( let i = 0 ; i < countListItems ; i ++ ) {
326+ const text = await listItems . nth ( i ) . textContent ( ) ;
327+ expect ( text ) . toBeTruthy ( ) ;
328+ expect ( text . endsWith ( locale [ dialogListItems [ i ] ] ) ) . toBe ( true ) ;
329+ }
276330 }
277331 } ) ;
278332} ) ;
0 commit comments