-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetPhrase.test.ts
More file actions
144 lines (133 loc) · 2.74 KB
/
GetPhrase.test.ts
File metadata and controls
144 lines (133 loc) · 2.74 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { MockedFunction } from "ts-jest/dist/utils/testing";
import { getPhrase } from "./GetPhrase";
import * as getL10nModule from "./GetL10n";
jest.mock("./GetL10n");
const getL10nMock = getL10nModule.getL10n as any as MockedFunction<
typeof getL10nModule.getL10n
>;
beforeEach(() => getL10nMock.mockReset());
describe("GetPhrase", () => {
it("returns the phrase if l10n is unavailable", () => {
getL10nMock.mockImplementation(() => null);
const phrase = getPhrase("Testar $__count$", {
__count: 1
});
expect(phrase).toBe("Testar $__count$");
});
it("returns the phrase if it is unavailable", () => {
getL10nMock.mockImplementation(() => ({
Phrases: {},
ruleEvaluator: (c) => c
}));
const phrase = getPhrase("Testar $__count$", {
__count: 1
});
expect(phrase).toBe("Testar $__count$");
});
it("uses the correct phrase if available", () => {
getL10nMock.mockImplementation(() => ({
ruleEvaluator: (c) => c,
Phrases: {
["test"]: {
r: {
"0": "test2"
}
},
["test2"]: {
r: {
"0": "test3"
}
}
}
}));
const phrase = getPhrase("test");
expect(phrase).toBe("test2");
});
it("uses the 0 phrase if no other is available", () => {
getL10nMock.mockImplementation(() => ({
ruleEvaluator: (c) => c,
Phrases: {
["test"]: {
r: {
"0": "test2"
}
},
["test2"]: {
r: {
"0": "test3"
}
}
}
}));
const phrase = getPhrase("test", {
__count: 3
});
expect(phrase).toBe("test2");
});
it("uses the correct counted phrase if available", () => {
getL10nMock.mockImplementation(() => ({
ruleEvaluator: (c) => c,
Phrases: {
["test"]: {
r: {
"0": "test2",
"1": "test4"
}
},
["test2"]: {
r: {
"0": "test3"
}
}
}
}));
const phrase = getPhrase("test", {
__count: 1
});
expect(phrase).toBe("test4");
});
it("uses the correct counted phrase if available 2", () => {
getL10nMock.mockImplementation(() => ({
ruleEvaluator: (c) => (c === 1 ? 6 : c),
Phrases: {
["test"]: {
r: {
"0": "test2",
"6": "test4"
}
},
["test2"]: {
r: {
"0": "test3"
}
}
}
}));
const phrase = getPhrase("test", {
__count: 1
});
expect(phrase).toBe("test4");
});
it("uses replaces metadata if needed", () => {
getL10nMock.mockImplementation(() => ({
ruleEvaluator: (c) => (c === 1 ? 6 : c),
Phrases: {
["test !ctx=my test data"]: {
r: {
"0": "test2 !ctx=my test data",
"6": "test4 !ctx=my test data"
}
},
["test2"]: {
r: {
"0": "test3"
}
}
}
}));
const phrase = getPhrase("test !ctx=my test data", {
__count: 1
});
expect(phrase).toBe("test4");
});
});