@mapsindoors/react-native-maps-indoors-mapbox 2.9.0 → 2.10.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 +81 -21
- package/android/build.gradle +2 -14
- package/android/src/main/java/com/mapsindoorsrn/MapboxMapView.java +4 -0
- package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -1
- package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsViewManager.java +28 -2
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +10 -2
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +1 -0
- package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +335 -99
- package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +17 -1
- package/android/src/main/java/com/mapsindoorsrn/core/RouteStore.java +59 -0
- package/app.plugin.js +8 -86
- package/ios/core/DirectionsRendererBridge.m +1 -0
- package/ios/core/DirectionsRendererModule.swift +292 -308
- package/ios/core/DirectionsServiceModule.swift +7 -1
- package/ios/core/MapControlModule.swift +330 -244
- package/ios/core/MapsIndoorsBridge.m +1 -0
- package/ios/core/MapsIndoorsModule.swift +48 -14
- package/ios/core/ReactPositionProvider.swift +6 -7
- package/ios/core/Sources/MainThread/CallGeneration.swift +38 -0
- package/ios/core/Sources/MainThread/MainThread.swift +25 -0
- package/ios/core/Sources/RouteStore/RouteStore.swift +62 -0
- package/package.json +10 -2
- package/react-native-maps-indoors-mapbox.podspec +6 -2
- package/specs/NativeDirectionsRendererModule.ts +1 -1
- package/specs/NativeMapsIndoorsModule.ts +1 -1
- package/src/core/MPCameraPosition.ts +1 -1
- package/src/core/MPDirectionsRenderer.ts +19 -3
- package/src/core/MPDirectionsService.ts +4 -1
- package/src/core/MPRouteStopIconConfig.ts +5 -3
- package/src/core/MapsIndoors.ts +36 -3
- package/src/core/RouteHandles.ts +76 -0
- package/src/core/RouteStopIconConfig.ts +5 -1
- package/src/core/__tests__/MPBounds.test.ts +0 -109
- package/src/core/__tests__/MPFilter.test.ts +0 -76
- package/src/core/__tests__/MPLanguageTag.test.ts +0 -168
- package/src/core/__tests__/MPPoint.test.ts +0 -82
- package/src/core/__tests__/MPSolution.test.ts +0 -107
- package/src/core/__tests__/MapsIndoors.language.test.ts +0 -180
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import MPBounds from '../MPBounds';
|
|
2
|
-
import MPPoint from '../MPPoint';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Unit tests for MPBounds - centre, containment, the bbox order and the Builder.
|
|
6
|
-
*
|
|
7
|
-
* Like MPPoint, the ordering conventions are the risky part: fromBBox takes a GeoJSON bbox
|
|
8
|
-
* [west, south, east, north].
|
|
9
|
-
*/
|
|
10
|
-
describe('MPBounds', () => {
|
|
11
|
-
const southwest = new MPPoint(57.0, 9.9);
|
|
12
|
-
const northeast = new MPPoint(57.1, 10.0);
|
|
13
|
-
const bounds = new MPBounds(northeast, southwest);
|
|
14
|
-
|
|
15
|
-
describe('center', () => {
|
|
16
|
-
it('is the midpoint of the corners', () => {
|
|
17
|
-
const center = bounds.center;
|
|
18
|
-
|
|
19
|
-
expect(center.latitude).toBeCloseTo(57.05, 10);
|
|
20
|
-
expect(center.longitude).toBeCloseTo(9.95, 10);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('contains', () => {
|
|
25
|
-
it('accepts a point inside', () => {
|
|
26
|
-
expect(bounds.contains(new MPPoint(57.05, 9.95))).toBe(true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('accepts the corners, so the bounds are inclusive', () => {
|
|
30
|
-
expect(bounds.contains(southwest)).toBe(true);
|
|
31
|
-
expect(bounds.contains(northeast)).toBe(true);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it.each([
|
|
35
|
-
['north of', new MPPoint(57.2, 9.95)],
|
|
36
|
-
['south of', new MPPoint(56.9, 9.95)],
|
|
37
|
-
['east of', new MPPoint(57.05, 10.5)],
|
|
38
|
-
['west of', new MPPoint(57.05, 9.5)],
|
|
39
|
-
])('rejects a point %s the bounds', (_label, point) => {
|
|
40
|
-
expect(bounds.contains(point)).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('fromBBox', () => {
|
|
45
|
-
it('reads GeoJSON bbox order, [west, south, east, north]', () => {
|
|
46
|
-
const fromBBox = MPBounds.fromBBox([9.9, 57.0, 10.0, 57.1]);
|
|
47
|
-
|
|
48
|
-
expect(fromBBox.southwest.latitude).toBe(57.0);
|
|
49
|
-
expect(fromBBox.southwest.longitude).toBe(9.9);
|
|
50
|
-
expect(fromBBox.northeast.latitude).toBe(57.1);
|
|
51
|
-
expect(fromBBox.northeast.longitude).toBe(10.0);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('create', () => {
|
|
56
|
-
it('keeps the corners it is given', () => {
|
|
57
|
-
const created = MPBounds.create({ southwest, northeast });
|
|
58
|
-
|
|
59
|
-
expect(created.southwest).toBe(southwest);
|
|
60
|
-
expect(created.northeast).toBe(northeast);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('Builder', () => {
|
|
65
|
-
it('grows to enclose every included point', () => {
|
|
66
|
-
const builder = new MPBounds.Builder();
|
|
67
|
-
builder.include(new MPPoint(57.0, 9.9));
|
|
68
|
-
builder.include(new MPPoint(57.1, 10.0));
|
|
69
|
-
builder.include(new MPPoint(57.05, 9.95));
|
|
70
|
-
|
|
71
|
-
const built = builder.build();
|
|
72
|
-
|
|
73
|
-
expect(built.southwest.latitude).toBe(57.0);
|
|
74
|
-
expect(built.southwest.longitude).toBe(9.9);
|
|
75
|
-
expect(built.northeast.latitude).toBe(57.1);
|
|
76
|
-
expect(built.northeast.longitude).toBe(10.0);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('encloses a single point as a degenerate box', () => {
|
|
80
|
-
const builder = new MPBounds.Builder();
|
|
81
|
-
builder.include(new MPPoint(57.0, 9.9));
|
|
82
|
-
|
|
83
|
-
const built = builder.build();
|
|
84
|
-
|
|
85
|
-
expect(built.southwest.latitude).toBe(57.0);
|
|
86
|
-
expect(built.northeast.latitude).toBe(57.0);
|
|
87
|
-
expect(built.contains(new MPPoint(57.0, 9.9))).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* build() means to reject an empty builder, but the guard compares `north` against
|
|
92
|
-
* POSITIVE_INFINITY while the field is initialised to NEGATIVE_INFINITY, so it never fires and
|
|
93
|
-
* an all-infinities MPBounds is returned instead.
|
|
94
|
-
*
|
|
95
|
-
* Marked `failing` so the bug is documented and tracked without turning the suite red - the
|
|
96
|
-
* test starts failing (and so demands attention) the moment the guard is fixed.
|
|
97
|
-
*/
|
|
98
|
-
it.failing('rejects building with no coordinates', () => {
|
|
99
|
-
expect(() => new MPBounds.Builder().build()).toThrow('Cannot build bounds with no coordinates');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('currently returns infinite bounds for an empty builder', () => {
|
|
103
|
-
const built = new MPBounds.Builder().build();
|
|
104
|
-
|
|
105
|
-
expect(built.northeast.latitude).toBe(Number.NEGATIVE_INFINITY);
|
|
106
|
-
expect(built.southwest.latitude).toBe(Number.POSITIVE_INFINITY);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,168 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
});
|