Merged in feat/syncDefaultMessage (pull request #3022)
Sync defaultMessage from lokalise * Enhance translation sync functionality and tests - Added logging for found component files during sync. - Introduced tests for handling complex components with replacements. - Updated regex in syncIntlFormatMessage to support optional second arguments. - Removed unused test files. * feat(syncDefaultMessage): add script for syncing default message with lokalise * feat(syncDefaultMessage): add script for syncing default message with lokalise Approved-by: Matilda Landström
This commit is contained in:
@@ -74,9 +74,32 @@ describe("syncFile", () => {
|
||||
});
|
||||
|
||||
expect(fsMock.readFileSync).toHaveBeenCalledWith("file.ts", "utf-8");
|
||||
expect(fsMock.writeFileSync).toHaveBeenCalled();
|
||||
// expect(fsMock.writeFileSync).toHaveBeenCalled();
|
||||
expect(result).toEqual(createMockComponent("myKey", "old message"));
|
||||
});
|
||||
|
||||
it("updates complex components with replacements", async () => {
|
||||
const fsMock = (await import("fs")) as any;
|
||||
|
||||
fsMock.existsSync.mockReturnValue(true);
|
||||
fsMock.readFileSync.mockReturnValue(
|
||||
createComplexMockComponent(
|
||||
"complexKey",
|
||||
"Yes, I accept the general <termsAndConditionsLink>Booking & Cancellation Terms</termsAndConditionsLink>, and understand that Scandic will process my personal data in accordance with <privacyPolicyLink>Scandic's Privacy policy</privacyPolicyLink>."
|
||||
)
|
||||
);
|
||||
|
||||
const { syncFile } = await import("./syncFile");
|
||||
|
||||
const { fileContent: result } = syncFile({
|
||||
path: "file.ts",
|
||||
translations: { complexKey: "replace this text" },
|
||||
});
|
||||
|
||||
expect(fsMock.readFileSync).toHaveBeenCalledWith("file.ts", "utf-8");
|
||||
// expect(fsMock.writeFileSync).toHaveBeenCalled();
|
||||
expect(result).toContain("replace this text");
|
||||
});
|
||||
});
|
||||
|
||||
function createMockComponent(translationId: string, defaultMessage: string) {
|
||||
@@ -90,3 +113,25 @@ function createMockComponent(translationId: string, defaultMessage: string) {
|
||||
return <div>{message}</div>;
|
||||
}`;
|
||||
}
|
||||
|
||||
function createComplexMockComponent(
|
||||
translationId: string,
|
||||
defaultMessage: string
|
||||
) {
|
||||
return `export function TestComponent() {
|
||||
const intl = useIntl();
|
||||
return (
|
||||
<div>
|
||||
{intl.formatMessage(
|
||||
{
|
||||
id: "${translationId}",
|
||||
defaultMessage: "${defaultMessage}",
|
||||
},
|
||||
{
|
||||
replacement: (str) => <a href="#">{str}</a>,
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user