From c5172df1998d453a906eedf2b96974aacfdb0aca Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Mon, 23 May 2022 14:33:37 +0300 Subject: [PATCH] test locale overrides --- debug/locale.html | 5 ---- test/unit/ui/control/fullscreen.test.js | 2 +- test/unit/ui/control/scale.test.js | 2 +- test/unit/ui/map.test.js | 34 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/debug/locale.html b/debug/locale.html index 706af583428..5a286f29a3c 100644 --- a/debug/locale.html +++ b/debug/locale.html @@ -36,11 +36,6 @@ 'NavigationControl.ResetBearing': 'X Reset bearing to north', 'NavigationControl.ZoomIn': 'X Zoom in', 'NavigationControl.ZoomOut': 'X Zoom out', - 'ScaleControl.Feet': 'X ft', - 'ScaleControl.Meters': 'X m', - 'ScaleControl.Kilometers': 'X km', - 'ScaleControl.Miles': 'X mi', - 'ScaleControl.NauticalMiles': 'X nm', 'ScrollZoomBlocker.CtrlMessage': 'X Use ctrl + scroll to zoom the map', 'ScrollZoomBlocker.CmdMessage': 'X Use ⌘ + scroll to zoom the map', 'TouchPanBlocker.Message': 'X Use two fingers to move the map' diff --git a/test/unit/ui/control/fullscreen.test.js b/test/unit/ui/control/fullscreen.test.js index 08f05c3c03a..90352a2c3e5 100644 --- a/test/unit/ui/control/fullscreen.test.js +++ b/test/unit/ui/control/fullscreen.test.js @@ -44,7 +44,7 @@ test('FullscreenControl makes optional container element full screen', (t) => { t.end(); }); -test('FullscreenControl changes language after map.setLanguage', (t) => { +test('FullscreenControl changes language after setLanguage', (t) => { const selector = '.mapboxgl-ctrl-fullscreen'; const map = createMap(t); diff --git a/test/unit/ui/control/scale.test.js b/test/unit/ui/control/scale.test.js index 392e8a09fdd..abc2d1e9f8c 100644 --- a/test/unit/ui/control/scale.test.js +++ b/test/unit/ui/control/scale.test.js @@ -38,7 +38,7 @@ test('ScaleControl should change unit of distance after calling setUnit', (t) => t.end(); }); -test('ScaleControl changes language after map.setLanguage', (t) => { +test('ScaleControl changes language after setLanguage', (t) => { const map = createMap(t); const scale = new ScaleControl(); const selector = '.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-scale'; diff --git a/test/unit/ui/map.test.js b/test/unit/ui/map.test.js index 565e8dedad1..21bf5bd3656 100755 --- a/test/unit/ui/map.test.js +++ b/test/unit/ui/map.test.js @@ -12,6 +12,7 @@ import simulate from '../../util/simulate_interaction.js'; import {fixedLngLat, fixedNum} from '../../util/fixed.js'; import Fog from '../../../src/style/fog.js'; import Color from '../../../src/style-spec/util/color.js'; +import getUIString from '../../../src/ui/get_ui_string.js'; import {MAX_MERCATOR_LATITUDE} from '../../../src/geo/mercator_coordinate.js'; function createStyleSource() { @@ -2372,6 +2373,39 @@ test('Map', (t) => { t.end(); }); }); + + t.test('English is the default UI language', (t) => { + const map = createMap(t); + map.on('style.load', () => { + t.equal(map._getUIString('Map.Title'), getUIString('en', 'Map.Title')); + t.end(); + }); + }); + + t.test('can change UI language', (t) => { + const map = createMap(t); + map.on('style.load', () => { + t.equal(map._getUIString('Map.Title'), getUIString('en', 'Map.Title')); + map.setLanguage('es'); + t.equal(map._getUIString('Map.Title'), getUIString('es', 'Map.Title')); + t.end(); + }); + }); + + t.test('can override UI language with `locale` property', (t) => { + const locale = { + 'Map.Title': 'X Map', + }; + + const map = createMap(t, {locale}); + map.on('style.load', () => { + t.equal(map._getUIString('Map.Title'), locale['Map.Title']); + map.setLanguage('es'); + t.equal(map._getUIString('Map.Title'), locale['Map.Title'], 'if the locale is overridden, changing map language should not affect UI'); + t.end(); + }); + }); + t.end(); });