forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_spec.ts
More file actions
106 lines (97 loc) · 2.71 KB
/
options_spec.ts
File metadata and controls
106 lines (97 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { NormalizedApplicationBuildOptions, getLocaleBaseHref } from './options';
describe('getLocaleBaseHref', () => {
const baseI18nOptions: NormalizedApplicationBuildOptions['i18nOptions'] = {
inlineLocales: new Set(),
sourceLocale: 'en-US',
locales: {},
flatOutput: false,
shouldInline: false,
hasDefinedSourceLocale: false,
};
it('should return undefined if flatOutput is true', () => {
const result = getLocaleBaseHref(undefined, { ...baseI18nOptions, flatOutput: true }, 'fr');
expect(result).toBeUndefined();
});
it('should return undefined if locale is not found', () => {
const result = getLocaleBaseHref(undefined, baseI18nOptions, 'fr');
expect(result).toBeUndefined();
});
it('should return baseHref from locale data if present', () => {
const i18nOptions = {
...baseI18nOptions,
locales: {
fr: {
files: [],
translation: {},
subPath: 'fr',
baseHref: '/fr/',
},
},
};
const result = getLocaleBaseHref(undefined, i18nOptions, 'fr');
expect(result).toBe('/fr/');
});
it('should join baseHref and locale subPath if baseHref is provided', () => {
const i18nOptions = {
...baseI18nOptions,
locales: {
fr: {
files: [],
translation: {},
subPath: 'fr',
},
},
};
const result = getLocaleBaseHref('/app/', i18nOptions, 'fr');
expect(result).toBe('/app/fr/');
});
it('should handle missing baseHref (undefined) correctly', () => {
const i18nOptions = {
...baseI18nOptions,
locales: {
fr: {
files: [],
translation: {},
subPath: 'fr',
},
},
};
const result = getLocaleBaseHref(undefined, i18nOptions, 'fr');
expect(result).toBe('/fr/');
});
it('should handle empty baseHref correctly', () => {
const i18nOptions = {
...baseI18nOptions,
locales: {
fr: {
files: [],
translation: {},
subPath: 'fr',
},
},
};
const result = getLocaleBaseHref('', i18nOptions, 'fr');
expect(result).toBe('/fr/');
});
it('should strip leading slash if baseHref does not start with slash', () => {
const i18nOptions = {
...baseI18nOptions,
locales: {
fr: {
files: [],
translation: {},
subPath: 'fr',
},
},
};
const result = getLocaleBaseHref('app/', i18nOptions, 'fr');
expect(result).toBe('app/fr/');
});
});