@mapsindoors/react-native-maps-indoors-mapbox 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -0
- package/android/src/main/java/com/mapsindoorsrn/core/BaseMapCacheProviders.java +94 -0
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +140 -49
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +16 -7
- package/android/src/main/java/com/mapsindoorsrn/core/MPDisplayRuleModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +115 -20
- package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +200 -11
- package/android/src/main/java/com/mapsindoorsrn/core/RnGson.java +110 -0
- package/android/src/main/java/com/mapsindoorsrn/core/UtilsModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/models/DirectionsRendererOptionsModel.java +498 -0
- package/index.ts +25 -0
- package/ios/.swift-format +79 -0
- package/ios/core/DirectionsRendererBridge.m +11 -0
- package/ios/core/DirectionsRendererModule.swift +162 -1
- package/ios/core/DirectionsRendererOptions.swift +352 -0
- package/ios/core/MapsIndoorsBridge.m +14 -1
- package/ios/core/MapsIndoorsData.swift +1 -0
- package/ios/core/MapsIndoorsModule.swift +180 -21
- package/ios/core/UtilsModule.swift +57 -45
- package/package.json +1 -1
- package/react-native-maps-indoors-mapbox.podspec +2 -2
- package/specs/NativeDirectionsRendererModule.ts +3 -0
- package/specs/NativeMapsIndoorsModule.ts +6 -1
- package/src/core/EventNames.ts +3 -0
- package/src/core/MPDirectionsRenderer.ts +76 -1
- package/src/core/MPDirectionsRendererOptions.ts +287 -0
- package/src/core/MPError.ts +48 -1
- package/src/core/MPLanguageTag.ts +222 -0
- package/src/core/MPLegBoundaryIcons.ts +130 -0
- package/src/core/MPRouteAnimationType.ts +24 -0
- package/src/core/MPRouteArrowStyle.ts +28 -0
- package/src/core/MPRouteMarkerDisplayRule.ts +140 -0
- package/src/core/MPRouteStampType.ts +24 -0
- package/src/core/MPSolution.ts +33 -2
- package/src/core/MPStrokeStyle.ts +22 -0
- package/src/core/MapsIndoors.ts +155 -11
- package/src/core/OnBaseMapCacheProgressListener.ts +20 -0
- package/src/core/__tests__/MPBounds.test.ts +109 -0
- package/src/core/__tests__/MPFilter.test.ts +76 -0
- package/src/core/__tests__/MPLanguageTag.test.ts +168 -0
- package/src/core/__tests__/MPPoint.test.ts +82 -0
- package/src/core/__tests__/MPSolution.test.ts +107 -0
- package/src/core/__tests__/MapsIndoors.language.test.ts +180 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import MPFilter from '../MPFilter';
|
|
2
|
+
import MPBounds from '../MPBounds';
|
|
3
|
+
import MPPoint from '../MPPoint';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Unit tests for MPFilter.create - the search filter builder used by getLocationsAsync.
|
|
7
|
+
*
|
|
8
|
+
* These matter because every field is optional: a typo in the mapping would silently drop a
|
|
9
|
+
* caller's filter rather than fail, and the location search would quietly return the wrong set.
|
|
10
|
+
*/
|
|
11
|
+
describe('MPFilter.create', () => {
|
|
12
|
+
it('leaves every field undefined when given nothing', () => {
|
|
13
|
+
const filter = MPFilter.create();
|
|
14
|
+
|
|
15
|
+
expect(filter.take).toBeUndefined();
|
|
16
|
+
expect(filter.skip).toBeUndefined();
|
|
17
|
+
expect(filter.depth).toBeUndefined();
|
|
18
|
+
expect(filter.floorIndex).toBeUndefined();
|
|
19
|
+
expect(filter.categories).toBeUndefined();
|
|
20
|
+
expect(filter.locations).toBeUndefined();
|
|
21
|
+
expect(filter.types).toBeUndefined();
|
|
22
|
+
expect(filter.parents).toBeUndefined();
|
|
23
|
+
expect(filter.mapExtend).toBeUndefined();
|
|
24
|
+
expect(filter.geometry).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('carries every field through unchanged', () => {
|
|
28
|
+
const mapExtend = new MPBounds(new MPPoint(57.1, 10.0), new MPPoint(57.0, 9.9));
|
|
29
|
+
const geometry = new MPBounds(new MPPoint(58.1, 11.0), new MPPoint(58.0, 10.9));
|
|
30
|
+
|
|
31
|
+
const filter = MPFilter.create({
|
|
32
|
+
take: 10,
|
|
33
|
+
skip: 5,
|
|
34
|
+
depth: 2,
|
|
35
|
+
floorIndex: 3,
|
|
36
|
+
categories: ['Activities Wellness'],
|
|
37
|
+
locations: ['loc-1', 'loc-2'],
|
|
38
|
+
types: ['MeetingRoom'],
|
|
39
|
+
parents: ['building-1'],
|
|
40
|
+
mapExtend,
|
|
41
|
+
geometry,
|
|
42
|
+
ignoreLocationSearchableStatus: true,
|
|
43
|
+
ignoreLocationActiveStatus: false,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(filter.take).toBe(10);
|
|
47
|
+
expect(filter.skip).toBe(5);
|
|
48
|
+
expect(filter.depth).toBe(2);
|
|
49
|
+
expect(filter.floorIndex).toBe(3);
|
|
50
|
+
expect(filter.categories).toEqual(['Activities Wellness']);
|
|
51
|
+
expect(filter.locations).toEqual(['loc-1', 'loc-2']);
|
|
52
|
+
expect(filter.types).toEqual(['MeetingRoom']);
|
|
53
|
+
expect(filter.parents).toEqual(['building-1']);
|
|
54
|
+
expect(filter.mapExtend).toBe(mapExtend);
|
|
55
|
+
expect(filter.geometry).toBe(geometry);
|
|
56
|
+
expect(filter.ignoreLocationSearchableStatus).toBe(true);
|
|
57
|
+
expect(filter.ignoreLocationActiveStatus).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('keeps a take of 0 rather than dropping it as falsy', () => {
|
|
61
|
+
// A `||` instead of `??` in the mapping would turn this into undefined and silently return
|
|
62
|
+
// every location.
|
|
63
|
+
expect(MPFilter.create({ take: 0 }).take).toBe(0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('keeps floorIndex 0, the ground floor', () => {
|
|
67
|
+
expect(MPFilter.create({ floorIndex: 0 }).floorIndex).toBe(0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('keeps empty arrays distinct from undefined', () => {
|
|
71
|
+
const filter = MPFilter.create({ categories: [], types: [] });
|
|
72
|
+
|
|
73
|
+
expect(filter.categories).toEqual([]);
|
|
74
|
+
expect(filter.types).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { normalizeLanguageTag, resolveLanguageTag } from '../MPLanguageTag';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unit tests for the BCP-47 tag handling that backs MPSolution.hasLanguage.
|
|
5
|
+
*
|
|
6
|
+
* This module is a TypeScript port of logic that already exists twice in native - iOS's
|
|
7
|
+
* LanguageCodeNormalizer and Android's MPLanguageManager - so the thing worth testing is not that
|
|
8
|
+
* the code runs, but that it still agrees with those two. Every table below is lifted from the
|
|
9
|
+
* native suites (MISDKIOS LanguageCodeNormalizerTests.swift, MISDKAND MPLanguageManagerTest.kt) so
|
|
10
|
+
* a drift on either platform shows up here as a failure rather than as a customer reporting that
|
|
11
|
+
* Chinese works on one platform and not the other.
|
|
12
|
+
*
|
|
13
|
+
* The three cases where the natives disagree with each other get their own `it`, naming which
|
|
14
|
+
* platform's behaviour we chose and why - those are decisions, not incidental behaviour.
|
|
15
|
+
*
|
|
16
|
+
* This file imports nothing but the module under test, so it needs no react-native mock.
|
|
17
|
+
*/
|
|
18
|
+
describe('normalizeLanguageTag', () => {
|
|
19
|
+
// From LanguageCodeNormalizerTests.chineseSimplifiedVariants.
|
|
20
|
+
it.each(['zh-Hans', 'zh_Hans', 'ZH-HANS', 'zh-CN', 'zh_cn', 'zh-SG'])(
|
|
21
|
+
'canonicalizes %s to zh-Hans',
|
|
22
|
+
(tag) => {
|
|
23
|
+
expect(normalizeLanguageTag(tag)).toBe('zh-Hans');
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// From LanguageCodeNormalizerTests.chineseTraditionalVariants.
|
|
28
|
+
it.each(['zh-Hant', 'zh_Hant', 'zh-TW', 'zh-HK', 'zh-MO'])('canonicalizes %s to zh-Hant', (tag) => {
|
|
29
|
+
expect(normalizeLanguageTag(tag)).toBe('zh-Hant');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('leaves bare zh unresolved rather than guessing a script', () => {
|
|
33
|
+
// Guessing here would silently serve Traditional content to a Simplified audience, or the
|
|
34
|
+
// reverse. The caller has to say which one it wants.
|
|
35
|
+
expect(normalizeLanguageTag('zh')).toBe('zh');
|
|
36
|
+
expect(normalizeLanguageTag('ZH')).toBe('zh');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it.each([
|
|
40
|
+
['EN', 'en'],
|
|
41
|
+
['en_us', 'en-US'],
|
|
42
|
+
['pt-br', 'pt-BR'],
|
|
43
|
+
['sr_latn_rs', 'sr-Latn-RS'],
|
|
44
|
+
])('rewrites %s to canonical casing, %s', (tag, expected) => {
|
|
45
|
+
expect(normalizeLanguageTag(tag)).toBe(expected);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it.each([
|
|
49
|
+
['zh-Foo', 'zh-FOO'],
|
|
50
|
+
['zh-yue', 'zh-YUE'],
|
|
51
|
+
])('keeps the unknown Chinese subtag in %s rather than collapsing to bare zh', (tag, expected) => {
|
|
52
|
+
// The iOS SDK used to return bare "zh" for any subtag it did not recognize, discarding what
|
|
53
|
+
// the caller supplied. Unknown subtags now fall through to the generic rebuild.
|
|
54
|
+
expect(normalizeLanguageTag(tag)).toBe(expected);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it.each([
|
|
58
|
+
['', ''],
|
|
59
|
+
[' ', ''],
|
|
60
|
+
[' zh-Hans ', 'zh-Hans'],
|
|
61
|
+
])('handles the edge input %p', (tag, expected) => {
|
|
62
|
+
expect(normalizeLanguageTag(tag)).toBe(expected);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('treats a missing tag as empty, so callers can apply their own fallback', () => {
|
|
66
|
+
// TypeScript-only path: the native signatures are non-optional, but every RN caller of this
|
|
67
|
+
// reaches it through an optional field.
|
|
68
|
+
expect(normalizeLanguageTag(undefined)).toBe('');
|
|
69
|
+
expect(normalizeLanguageTag(null)).toBe('');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('maps zh-MY to zh-Hans, following Android rather than iOS', () => {
|
|
73
|
+
// A deliberate divergence. CLDR's likely-subtags maps zh-MY to zh-Hans and Malaysian Chinese
|
|
74
|
+
// is written in Simplified; Android pins this in buildPriorityListEnrichesZhMYWithHans, while
|
|
75
|
+
// iOS's normalizer omits MY and has no test covering it.
|
|
76
|
+
expect(normalizeLanguageTag('zh-MY')).toBe('zh-Hans');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('resolveLanguageTag', () => {
|
|
81
|
+
// The solution this repo's Chinese testing runs against - 2fb83f9461634b29b6c0fcb6,
|
|
82
|
+
// "MapsIndoors - Office (Chinese)".
|
|
83
|
+
const chinese = ['da', 'en', 'zh-Hans', 'zh-Hant'];
|
|
84
|
+
|
|
85
|
+
it.each([
|
|
86
|
+
['zh-hant', ['en', 'zh-Hant'], 'zh-Hant'],
|
|
87
|
+
['zh-Hant', ['en', 'zh-Hant'], 'zh-Hant'],
|
|
88
|
+
['en-DK', ['en-DK', 'en-NO'], 'en-DK'],
|
|
89
|
+
])('resolves %s to the casing the solution publishes, %s', (tag, available, expected) => {
|
|
90
|
+
// The resolved tag goes into the backend's `lr=` parameter, so it has to be spelled the way
|
|
91
|
+
// the CMS spells it, not the way the caller typed it.
|
|
92
|
+
expect(resolveLanguageTag(tag, available)).toBe(expected);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it.each([
|
|
96
|
+
['zh-CN', ['en', 'zh-Hans'], 'zh-Hans'],
|
|
97
|
+
['zh-TW', ['en', 'zh-Hant'], 'zh-Hant'],
|
|
98
|
+
['zh-HK', ['en', 'zh-Hant'], 'zh-Hant'],
|
|
99
|
+
['zh-CN', chinese, 'zh-Hans'],
|
|
100
|
+
['zh-TW', chinese, 'zh-Hant'],
|
|
101
|
+
])('resolves the region-only tag %s to its script, %s', (tag, available, expected) => {
|
|
102
|
+
expect(resolveLanguageTag(tag, available)).toBe(expected);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('prefers the script variant over bare zh for a region-only tag', () => {
|
|
106
|
+
// Android's setLanguagePrefersScriptVariantOverBareZhForChineseRegions: the implied script is
|
|
107
|
+
// prepended to the priority list so it outranks the bare-language fallback.
|
|
108
|
+
expect(resolveLanguageTag('zh-CN', ['en', 'zh', 'zh-Hans'])).toBe('zh-Hans');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('falls through to bare zh when the solution has no script variant', () => {
|
|
112
|
+
expect(resolveLanguageTag('zh-CN', ['en', 'zh'])).toBe('zh');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it.each([
|
|
116
|
+
['en-US', ['en'], 'en'],
|
|
117
|
+
['en-DK', ['ar', 'en'], 'en'],
|
|
118
|
+
['zh-Hant-TW', ['zh-Hant'], 'zh-Hant'],
|
|
119
|
+
['zh-Hant-TW', ['zh'], 'zh'],
|
|
120
|
+
])('walks %s right-to-left down to %s', (tag, available, expected) => {
|
|
121
|
+
expect(resolveLanguageTag(tag, available)).toBe(expected);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('refuses a Chinese region whose script the solution does not have', () => {
|
|
125
|
+
// Android's setLanguageRejectsCrossScriptChineseRegion. Refusing prevents silently mapping a
|
|
126
|
+
// Traditional reader onto Simplified content, which is the worst available outcome.
|
|
127
|
+
expect(resolveLanguageTag('zh-TW', ['en', 'zh-Hans'])).toBeUndefined();
|
|
128
|
+
expect(resolveLanguageTag('zh-Hant', ['en', 'zh-Hans'])).toBeUndefined();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('refuses bare zh when the solution only publishes script variants', () => {
|
|
132
|
+
// Android's setLanguageRejectsBareZhAgainstScriptOnlySolution. iOS's isLanguageAvailable is
|
|
133
|
+
// looser and would accept this, but Android's setLanguage rejects it, so answering `true`
|
|
134
|
+
// would be a lie on the platform that actually enforces it. Being conservative is what makes
|
|
135
|
+
// a resolved tag safe to pass to setLanguage on both platforms.
|
|
136
|
+
expect(resolveLanguageTag('zh', chinese)).toBeUndefined();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('accepts the ICU underscore form, following iOS rather than Android', () => {
|
|
140
|
+
// A deliberate divergence, and the permissive direction: Android's Locale.forLanguageTag turns
|
|
141
|
+
// "zh_Hans" into the undetermined locale and rejects it, but `_` is what
|
|
142
|
+
// java.util.Locale.toString(), ICU and several JS i18n libraries emit, so a developer copying
|
|
143
|
+
// a locale string will hit it. Accepting it here cannot break a tag that works today.
|
|
144
|
+
expect(resolveLanguageTag('zh_Hans', chinese)).toBe('zh-Hans');
|
|
145
|
+
expect(resolveLanguageTag('zh_cn', chinese)).toBe('zh-Hans');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it.each([
|
|
149
|
+
['fr-FR', ['ar', 'en']],
|
|
150
|
+
['fr', ['en', 'zh']],
|
|
151
|
+
['zh-Hans', []],
|
|
152
|
+
])('returns undefined for %s against %p', (tag, available) => {
|
|
153
|
+
expect(resolveLanguageTag(tag, available)).toBeUndefined();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('rejects a tag shorter than two characters, as Android does', () => {
|
|
157
|
+
expect(resolveLanguageTag('e', ['en'])).toBeUndefined();
|
|
158
|
+
expect(resolveLanguageTag('', ['en'])).toBeUndefined();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('returns undefined when the solution has not loaded its languages yet', () => {
|
|
162
|
+
// availableLanguages is populated from the solution, so every caller can reach this before
|
|
163
|
+
// MapsIndoors.load has resolved.
|
|
164
|
+
expect(resolveLanguageTag('en', undefined)).toBeUndefined();
|
|
165
|
+
expect(resolveLanguageTag('en', null)).toBeUndefined();
|
|
166
|
+
expect(resolveLanguageTag(undefined, ['en'])).toBeUndefined();
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import MPPoint from '../MPPoint';
|
|
2
|
+
import MPGeometry from '../MPGeometry';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Unit tests for the pure parts of MPPoint - construction, coordinate order and JSON shape.
|
|
6
|
+
*
|
|
7
|
+
* The coordinate order matters and is easy to get backwards: the MapsIndoors SDK's JSON uses
|
|
8
|
+
* GeoJSON order [longitude, latitude, floorIndex], while the constructor takes
|
|
9
|
+
* (latitude, longitude, floorIndex). These tests pin that down.
|
|
10
|
+
*
|
|
11
|
+
* Anything that crosses the native bridge (distanceTo, angleBetween) is deliberately not covered
|
|
12
|
+
* here - that is what the on-device suites in mapsindoors-sdk-react-native are for.
|
|
13
|
+
*/
|
|
14
|
+
describe('MPPoint', () => {
|
|
15
|
+
describe('constructor', () => {
|
|
16
|
+
it('keeps latitude, longitude and floor index', () => {
|
|
17
|
+
const point = new MPPoint(57.0582701, 9.9508396, 3);
|
|
18
|
+
|
|
19
|
+
expect(point.latitude).toBe(57.0582701);
|
|
20
|
+
expect(point.longitude).toBe(9.9508396);
|
|
21
|
+
expect(point.floorIndex).toBe(3);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('defaults the floor index to 0', () => {
|
|
25
|
+
expect(new MPPoint(57.0582701, 9.9508396).floorIndex).toBe(0);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('create', () => {
|
|
30
|
+
it('reads GeoJSON coordinate order, [longitude, latitude, floorIndex]', () => {
|
|
31
|
+
const point = MPPoint.create({ type: 'Point', coordinates: [9.9508396, 57.0582701, 2] });
|
|
32
|
+
|
|
33
|
+
expect(point.latitude).toBe(57.0582701);
|
|
34
|
+
expect(point.longitude).toBe(9.9508396);
|
|
35
|
+
expect(point.floorIndex).toBe(2);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('accepts a bare coordinate array, as the SDK sometimes sends', () => {
|
|
39
|
+
const point = MPPoint.create([9.9508396, 57.0582701, 1] as unknown as Parameters<typeof MPPoint.create>[0]);
|
|
40
|
+
|
|
41
|
+
expect(point.latitude).toBe(57.0582701);
|
|
42
|
+
expect(point.longitude).toBe(9.9508396);
|
|
43
|
+
expect(point.floorIndex).toBe(1);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('geometry contract', () => {
|
|
48
|
+
it('reports the point geometry type', () => {
|
|
49
|
+
expect(new MPPoint(1, 2).type).toBe(MPGeometry.point);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('is its own position', () => {
|
|
53
|
+
const point = new MPPoint(1, 2);
|
|
54
|
+
expect(point.position).toBe(point);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('toJSON', () => {
|
|
59
|
+
it('emits GeoJSON coordinate order and the geometry type', () => {
|
|
60
|
+
expect(new MPPoint(57.0582701, 9.9508396, 4).toJSON()).toEqual({
|
|
61
|
+
type: MPGeometry.point,
|
|
62
|
+
coordinates: [9.9508396, 57.0582701, 4],
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('round-trips through create without drift', () => {
|
|
67
|
+
const original = new MPPoint(57.0582701, 9.9508396, 2);
|
|
68
|
+
const restored = MPPoint.create(original.toJSON());
|
|
69
|
+
|
|
70
|
+
expect(restored.latitude).toBe(original.latitude);
|
|
71
|
+
expect(restored.longitude).toBe(original.longitude);
|
|
72
|
+
expect(restored.floorIndex).toBe(original.floorIndex);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('substitutes floor 0 when the floor index is missing', () => {
|
|
76
|
+
const point = new MPPoint(1, 2);
|
|
77
|
+
(point as { floorIndex?: number }).floorIndex = undefined;
|
|
78
|
+
|
|
79
|
+
expect(point.toJSON().coordinates[2]).toBe(0);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import MPSolution from '../MPSolution';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unit tests for MPSolution's language handling.
|
|
5
|
+
*
|
|
6
|
+
* hasLanguage used to be an exact, case-sensitive Array.includes, which put it out of step with
|
|
7
|
+
* both native SDKs: they canonicalize a tag before matching it, so hasLanguage('zh-CN') answered
|
|
8
|
+
* false for a solution where setLanguage('zh-CN') then succeeded. Two APIs on the same object
|
|
9
|
+
* disagreeing about the same solution is worse than either answer alone, and it disagreed in
|
|
10
|
+
* exactly the Chinese case the language work exists for.
|
|
11
|
+
*
|
|
12
|
+
* The tables use the language sets of the solutions this repo actually tests against, so they
|
|
13
|
+
* double as a record of what those solutions publish.
|
|
14
|
+
*/
|
|
15
|
+
const solution = (availableLanguages: string[], defaultLanguage = 'en') =>
|
|
16
|
+
MPSolution.create({
|
|
17
|
+
id: 'solution',
|
|
18
|
+
name: 'Solution',
|
|
19
|
+
solutionConfig: { id: 'config' },
|
|
20
|
+
defaultLanguage,
|
|
21
|
+
availableLanguages,
|
|
22
|
+
modules: [],
|
|
23
|
+
} as unknown as Parameters<typeof MPSolution.create>[0]);
|
|
24
|
+
|
|
25
|
+
/** 2fb83f9461634b29b6c0fcb6, "MapsIndoors - Office (Chinese)" - the Chinese test solution. */
|
|
26
|
+
const CHINESE = ['da', 'en', 'zh-Hans', 'zh-Hant'];
|
|
27
|
+
/** The `mapspeople` solution the on-device suites use. */
|
|
28
|
+
const MAPSPEOPLE = ['de', 'en', 'da'];
|
|
29
|
+
/** The `lapalmeraie` solution both example apps load. */
|
|
30
|
+
const LAPALMERAIE = ['pt', 'fr', 'en'];
|
|
31
|
+
|
|
32
|
+
describe('MPSolution.create', () => {
|
|
33
|
+
it('round-trips the language fields', () => {
|
|
34
|
+
const mapspeople = solution(MAPSPEOPLE, 'da');
|
|
35
|
+
|
|
36
|
+
expect(mapspeople.availableLanguages).toEqual(MAPSPEOPLE);
|
|
37
|
+
expect(mapspeople.defaultLanguage).toBe('da');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('MPSolution.hasLanguage', () => {
|
|
42
|
+
it.each([
|
|
43
|
+
['en', MAPSPEOPLE],
|
|
44
|
+
['de', MAPSPEOPLE],
|
|
45
|
+
['fr', LAPALMERAIE],
|
|
46
|
+
['zh-Hans', CHINESE],
|
|
47
|
+
['zh-Hant', CHINESE],
|
|
48
|
+
])('accepts %s, which the solution advertises verbatim', (language, available) => {
|
|
49
|
+
expect(solution(available).hasLanguage(language)).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it.each([
|
|
53
|
+
['zh-CN', CHINESE],
|
|
54
|
+
['zh-SG', CHINESE],
|
|
55
|
+
['zh-TW', CHINESE],
|
|
56
|
+
['zh-HK', CHINESE],
|
|
57
|
+
['zh_Hans', CHINESE],
|
|
58
|
+
['ZH-HANT', CHINESE],
|
|
59
|
+
['zh-Hant-TW', CHINESE],
|
|
60
|
+
])('accepts %s, which resolves onto an advertised Chinese tag', (language, available) => {
|
|
61
|
+
// Every one of these was false before the tags were canonicalized, while
|
|
62
|
+
// MapsIndoors.setLanguage accepted them natively.
|
|
63
|
+
expect(solution(available).hasLanguage(language)).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('accepts a regional tag whose base language the solution has', () => {
|
|
67
|
+
expect(solution(MAPSPEOPLE).hasLanguage('en-US')).toBe(true);
|
|
68
|
+
expect(solution(LAPALMERAIE).hasLanguage('pt-BR')).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('refuses bare zh against a solution that only publishes script variants', () => {
|
|
72
|
+
// Ambiguous: there is no way to tell whether the caller wants Simplified or Traditional, and
|
|
73
|
+
// Android's setLanguage refuses it too.
|
|
74
|
+
expect(solution(CHINESE).hasLanguage('zh')).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it.each([
|
|
78
|
+
['zh-Hans', MAPSPEOPLE],
|
|
79
|
+
['fr', MAPSPEOPLE],
|
|
80
|
+
['de', LAPALMERAIE],
|
|
81
|
+
])('refuses %s, which the solution does not have in any form', (language, available) => {
|
|
82
|
+
expect(solution(available).hasLanguage(language)).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it.each([undefined, '', ' '])('refuses the empty input %p', (language) => {
|
|
86
|
+
expect(solution(CHINESE).hasLanguage(language)).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('MPSolution.resolveLanguage', () => {
|
|
91
|
+
it.each([
|
|
92
|
+
['zh-CN', 'zh-Hans'],
|
|
93
|
+
['zh-TW', 'zh-Hant'],
|
|
94
|
+
['zh-Hant-TW', 'zh-Hant'],
|
|
95
|
+
['ZH-HANS', 'zh-Hans'],
|
|
96
|
+
['en-US', 'en'],
|
|
97
|
+
])('resolves %s to %s, spelled the way the solution publishes it', (language, expected) => {
|
|
98
|
+
// This is the answer hasLanguage cannot give: what to actually pass to setLanguage.
|
|
99
|
+
expect(solution(CHINESE).resolveLanguage(language)).toBe(expected);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('returns undefined when nothing matches', () => {
|
|
103
|
+
expect(solution(CHINESE).resolveLanguage('fr')).toBeUndefined();
|
|
104
|
+
expect(solution(CHINESE).resolveLanguage('zh')).toBeUndefined();
|
|
105
|
+
expect(solution(CHINESE).resolveLanguage()).toBeUndefined();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { NativeModules, resetNativeModules } from 'react-native';
|
|
2
|
+
import MapsIndoors from '../MapsIndoors';
|
|
3
|
+
import MPError from '../MPError';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Unit tests for the language methods' contract at the JavaScript boundary.
|
|
7
|
+
*
|
|
8
|
+
* These are bridge wrappers, so there is nothing here to compute - which is exactly the point.
|
|
9
|
+
* The tag has to reach native byte-for-byte, because both native SDKs canonicalize it themselves
|
|
10
|
+
* and any rewriting on this side would be a third, invisible set of rules. And the promise has to
|
|
11
|
+
* settle the way the declared types say: setLanguage is typed Promise<boolean> but resolved null on
|
|
12
|
+
* iOS for as long as it has existed, and the getters map a native rejection to MPError only if the
|
|
13
|
+
* native side rejects with JSON.
|
|
14
|
+
*
|
|
15
|
+
* Behaviour that depends on a real solution - whether a given tag is accepted, what getLanguage
|
|
16
|
+
* reads back - belongs in the on-device suites in mapsindoors-sdk-react-native.
|
|
17
|
+
*/
|
|
18
|
+
const nativeModule = NativeModules.MapsIndoorsModule;
|
|
19
|
+
|
|
20
|
+
beforeEach(resetNativeModules);
|
|
21
|
+
|
|
22
|
+
/** The shape both native modules reject with: a JSON-encoded MPError. */
|
|
23
|
+
const nativeRejection = (code: number, message: string) =>
|
|
24
|
+
new Error(JSON.stringify({ code, message }));
|
|
25
|
+
|
|
26
|
+
describe('MapsIndoors.setLanguage', () => {
|
|
27
|
+
it.each(['zh-Hans', 'zh-Hant', 'zh-CN', 'zh_Hans', 'ZH-HANT', 'en', 'pt-BR'])(
|
|
28
|
+
'forwards %s to native unchanged',
|
|
29
|
+
async (language) => {
|
|
30
|
+
// No lower-casing, no splitting, no normalizing. The native SDKs own that, and doing any of
|
|
31
|
+
// it here would silently disagree with them.
|
|
32
|
+
nativeModule.setLanguage.mockResolvedValue(true);
|
|
33
|
+
|
|
34
|
+
await MapsIndoors.setLanguage(language);
|
|
35
|
+
|
|
36
|
+
expect(nativeModule.setLanguage).toHaveBeenCalledWith(language);
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
it.each([true, false])('resolves the native result, %p', async (result) => {
|
|
41
|
+
// iOS used to resolve null here regardless, despite the declared Promise<boolean>.
|
|
42
|
+
nativeModule.setLanguage.mockResolvedValue(result);
|
|
43
|
+
|
|
44
|
+
await expect(MapsIndoors.setLanguage('zh-Hans')).resolves.toBe(result);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it.each(['', ' '])('resolves false for %p without calling native', async (language) => {
|
|
48
|
+
// Android rejects this in its own preconditions, but iOS accepts it and stores an empty
|
|
49
|
+
// language, which corrupts the `lr=` parameter on every subsequent request.
|
|
50
|
+
await expect(MapsIndoors.setLanguage(language)).resolves.toBe(false);
|
|
51
|
+
|
|
52
|
+
expect(nativeModule.setLanguage).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('MapsIndoors.getAvailableLanguages', () => {
|
|
57
|
+
it('passes the solution languages through', async () => {
|
|
58
|
+
nativeModule.getAvailableLanguages.mockResolvedValue(['da', 'en', 'zh-Hans', 'zh-Hant']);
|
|
59
|
+
|
|
60
|
+
await expect(MapsIndoors.getAvailableLanguages()).resolves.toEqual([
|
|
61
|
+
'da',
|
|
62
|
+
'en',
|
|
63
|
+
'zh-Hans',
|
|
64
|
+
'zh-Hant',
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('turns a native rejection into an MPError', async () => {
|
|
69
|
+
// Only works because both native modules reject with JSON - MPError.parse runs JSON.parse on
|
|
70
|
+
// the message, so a raw string reject surfaces as a SyntaxError instead.
|
|
71
|
+
nativeModule.getAvailableLanguages.mockRejectedValue(
|
|
72
|
+
nativeRejection(20, 'No languages are available, try waiting until MapsIndoors is Ready'),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
await expect(MapsIndoors.getAvailableLanguages()).rejects.toBeInstanceOf(MPError);
|
|
76
|
+
await expect(MapsIndoors.getAvailableLanguages()).rejects.toMatchObject({ code: 20 });
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('MapsIndoors.getDefaultLanguage', () => {
|
|
81
|
+
it('passes the default language through', async () => {
|
|
82
|
+
nativeModule.getDefaultLanguage.mockResolvedValue('en');
|
|
83
|
+
|
|
84
|
+
await expect(MapsIndoors.getDefaultLanguage()).resolves.toBe('en');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('turns a native rejection into an MPError', async () => {
|
|
88
|
+
// Android used to resolve null here against a declared Promise<string>; it now rejects, the
|
|
89
|
+
// way iOS already did.
|
|
90
|
+
nativeModule.getDefaultLanguage.mockRejectedValue(
|
|
91
|
+
nativeRejection(20, 'No default language is available, try waiting until MapsIndoors is Ready'),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
await expect(MapsIndoors.getDefaultLanguage()).rejects.toBeInstanceOf(MPError);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('MapsIndoors.getLanguage', () => {
|
|
99
|
+
it('passes the current language through unwrapped', async () => {
|
|
100
|
+
// Deliberately has no MPError mapping: neither native has a reject path here - both return a
|
|
101
|
+
// non-null string with their own fallback chain - so a catch would be dead code.
|
|
102
|
+
nativeModule.getLanguage.mockResolvedValue('zh-Hant');
|
|
103
|
+
|
|
104
|
+
await expect(MapsIndoors.getLanguage()).resolves.toBe('zh-Hant');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('MapsIndoors.getSolution', () => {
|
|
109
|
+
// Not a language method, but hasLanguage / resolveLanguage are only reachable through the
|
|
110
|
+
// solution this returns, and Android used to resolve null here whenever the native solution was
|
|
111
|
+
// momentarily unavailable - which is exactly what a language change causes, because it tears
|
|
112
|
+
// down the data providers. JSON.parse(undefined) then threw "Unexpected character: u", and
|
|
113
|
+
// JSON.parse(null) silently produced a solution whose availableLanguages was undefined, so
|
|
114
|
+
// hasLanguage answered false for every tag.
|
|
115
|
+
it('turns a missing solution into an MPError instead of a parse crash', async () => {
|
|
116
|
+
nativeModule.getSolution.mockRejectedValue(
|
|
117
|
+
nativeRejection(20, 'No solution is available, try waiting until MapsIndoors is Ready'),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
await expect(MapsIndoors.getSolution()).rejects.toBeInstanceOf(MPError);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('parses a solution and exposes its languages', async () => {
|
|
124
|
+
nativeModule.getSolution.mockResolvedValue(
|
|
125
|
+
JSON.stringify({
|
|
126
|
+
id: 'solution',
|
|
127
|
+
name: 'Solution',
|
|
128
|
+
solutionConfig: { id: 'config' },
|
|
129
|
+
defaultLanguage: 'en',
|
|
130
|
+
availableLanguages: ['da', 'en', 'zh-Hans', 'zh-Hant'],
|
|
131
|
+
modules: [],
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const solution = await MapsIndoors.getSolution();
|
|
136
|
+
|
|
137
|
+
expect(solution.availableLanguages).toEqual(['da', 'en', 'zh-Hans', 'zh-Hant']);
|
|
138
|
+
expect(solution.hasLanguage('zh-CN')).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('MapsIndoors.getLocations', () => {
|
|
143
|
+
// Also not a language method, but a language change is what exposed it: Android rejects
|
|
144
|
+
// getLocations while the locations reload, and the catch body here was `{Promise.reject(...)}` -
|
|
145
|
+
// a statement block with no return, so the arrow resolved undefined and swallowed the rejection.
|
|
146
|
+
// JSON.parse(undefined) then threw "Unexpected character: u", masking the real MPError.
|
|
147
|
+
it('propagates a native rejection instead of swallowing it into a parse error', async () => {
|
|
148
|
+
nativeModule.getLocations.mockRejectedValue(
|
|
149
|
+
nativeRejection(20, 'Cannot fetch locations, try waiting until MapsIndoors is Ready'),
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
await expect(MapsIndoors.getLocations()).rejects.toBeInstanceOf(MPError);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('MPError.parse', () => {
|
|
157
|
+
// Every .catch(MPError.parse) in the SDK depends on this, and it used to assume the message was
|
|
158
|
+
// always the native modules' JSON payload. A rejection from the bridge or from JavaScript has a
|
|
159
|
+
// plain-text message, and parsing that threw a SyntaxError which replaced the real message with
|
|
160
|
+
// "JSON Parse error: Unexpected character: ...".
|
|
161
|
+
it('reads a native JSON payload', () => {
|
|
162
|
+
const error = MPError.parse(new Error(JSON.stringify({ code: 10, message: 'No network' })));
|
|
163
|
+
|
|
164
|
+
expect(error.code).toBe(10);
|
|
165
|
+
expect(error.message).toBe('No network');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it.each([
|
|
169
|
+
'Exception in HostFunction: something went wrong',
|
|
170
|
+
'',
|
|
171
|
+
'null',
|
|
172
|
+
'42',
|
|
173
|
+
])('wraps the non-JSON message %p instead of throwing', (message) => {
|
|
174
|
+
const error = MPError.parse(new Error(message));
|
|
175
|
+
|
|
176
|
+
expect(error).toBeInstanceOf(MPError);
|
|
177
|
+
expect(error.code).toBe(MPError.unknownError);
|
|
178
|
+
expect(error.message).toBe(message);
|
|
179
|
+
});
|
|
180
|
+
});
|