forked from jenkinsci/pipeline-graph-view-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessages.spec.ts
More file actions
67 lines (57 loc) · 1.95 KB
/
messages.spec.ts
File metadata and controls
67 lines (57 loc) · 1.95 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
import { Mock, vi } from "vitest";
import { getResourceBundle } from "../RestClient.tsx";
import {
getMessages,
LocalizedMessageKey,
Messages,
ResourceBundleName,
} from "./messages.ts";
vi.mock("../RestClient.tsx", () => ({
getResourceBundle: vi.fn(),
}));
describe("Messages", () => {
describe("Format message", () => {
const messages = new Messages(
{
"Property.name": "{arg} world",
},
"en",
);
it("should use known mapped message", () => {
expect(messages.format("Property.name", { arg: "hello" })).toEqual(
"hello world",
);
});
it("should use fallback formatter with unknown property", () => {
expect(
messages.format("Unknown.property.name", { arg: "hello" }),
).toEqual("hello");
});
});
describe("Get Messages", () => {
it("should compile found resource bundle", async () => {
(getResourceBundle as Mock).mockResolvedValue({
"A.property": "a value",
"Another.property": "with another value",
"One.more.property": "with {one} more value",
});
const messages = await getMessages("en", [ResourceBundleName.messages]);
expect(getResourceBundle).toHaveBeenCalledWith(
"io.jenkins.plugins.pipelinegraphview.Messages",
);
expect(messages.format("A.property")).toEqual("a value");
expect(messages.format("Another.property")).toEqual("with another value");
expect(messages.format("One.more.property", { one: "some" })).toEqual(
"with some more value",
);
});
it("should use the default messages if undefined returned", async () => {
(getResourceBundle as Mock).mockResolvedValue(undefined);
const messages = await getMessages("en", [ResourceBundleName.messages]);
expect(
messages.format(LocalizedMessageKey.startedAgo, { 0: "5s" }),
).toEqual("Started 5s ago");
expect(messages.format("A.property")).toEqual("");
});
});
});