Files
web/scripts/i18n/syncDefaultMessage/syncFormattedMessage.test.ts
Joakim Jäderberg aafad9781f Merged in feat/lokalise-rebuild (pull request #2993)
Feat/lokalise rebuild

* chore(lokalise): update translation ids

* chore(lokalise): easier to switch between projects

* chore(lokalise): update translation ids

* .

* .

* .

* .

* .

* .

* chore(lokalise): update translation ids

* chore(lokalise): update translation ids

* .

* .

* .

* chore(lokalise): update translation ids

* chore(lokalise): update translation ids

* .

* .

* chore(lokalise): update translation ids

* chore(lokalise): update translation ids

* chore(lokalise): new translations

* merge

* switch to errors for missing id's

* merge

* sync translations


Approved-by: Linus Flood
2025-10-22 11:00:03 +00:00

70 lines
2.5 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { syncFormattedMessage } from "./syncFormattedMessage";
describe("syncFormattedMessage", () => {
it("updated false when given empty file and no translations", () => {
expect(
syncFormattedMessage({ fileContent: "", translations: {} })
).toEqual({ updated: false });
});
it("updates <FormattedMessage> components", () => {
expect(
syncFormattedMessage({
fileContent:
'<FormattedMessage id="myKey" defaultMessage="old message" />',
translations: { myKey: "new message" },
})
).toEqual({
updated: true,
fileContent:
'<FormattedMessage id="myKey" defaultMessage="new message" />',
});
});
it("updates multiline <FormattedMessage>", () => {
expect(
syncFormattedMessage({
fileContent: `<FormattedMessage\n\tid="myKey"\n\tdefaultMessage="old message" />`,
translations: { myKey: "new message" },
})
).toEqual({
updated: true,
fileContent: `<FormattedMessage\n\tid="myKey"\n\tdefaultMessage="new message" />`,
});
});
it("updates multiple <FormattedMessage> components", () => {
expect(
syncFormattedMessage({
fileContent:
'<FormattedMessage id="myKey" defaultMessage="old message" />' +
'<FormattedMessage id="anotherKey" defaultMessage="another old message" />',
translations: {
myKey: "new message",
anotherKey: "another new message",
},
})
).toEqual({
updated: true,
fileContent:
'<FormattedMessage id="myKey" defaultMessage="new message" />' +
'<FormattedMessage id="anotherKey" defaultMessage="another new message" />',
});
});
it("updates nothing if no key was found", () => {
expect(
syncFormattedMessage({
fileContent:
'<FormattedMessage id="myKey" defaultMessage="old message" />' +
'<FormattedMessage id="anotherKey" defaultMessage="another old message" />',
translations: {
unusedKey: "new message",
},
})
).toEqual({
updated: false,
});
});
});