-
Notifications
You must be signed in to change notification settings - Fork 6
[DIT-12000] Add iosLocales Configuration Support #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: string-file-formats
Are you sure you want to change the base?
Changes from all commits
a398d12
5263cc2
b1085bb
7bf3e78
b3a6d75
9c3e178
7a98aed
2e515c3
a5ec77e
09b32e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { | |
| ExportTextItemsStringResponse, | ||
| PullQueryParams, | ||
| } from "../http/types"; | ||
| import OutputFile from "./shared/fileTypes/OutputFile"; | ||
| export default class IOSStringsDictFormatter extends BaseExportFormatter< | ||
| IOSStringsDictOutputFile<{ variantId: string }>, | ||
| ExportTextItemsStringResponse, | ||
|
|
@@ -19,9 +20,17 @@ export default class IOSStringsDictFormatter extends BaseExportFormatter< | |
| ): void { | ||
| this.outputFiles[fileName] ??= new IOSStringsDictOutputFile({ | ||
| filename: fileName, | ||
| path: this.outDir, | ||
| path: this.getLocalesPath(variantId), | ||
| metadata: { variantId: variantId || "base" }, | ||
| content: content, | ||
| }); | ||
| } | ||
|
|
||
| protected async writeFiles(files: OutputFile[]): Promise<void> { | ||
| if (this.projectConfig.iosLocales) { | ||
| const swiftDriverFile = await this.getSwiftDriverFile(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we call writeFiles for both iosStringsDict and iosStrings. Does that mean we are generating the driver file twice? |
||
| files.push(swiftDriverFile); | ||
| } | ||
| await super.writeFiles(files); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -399,3 +399,4 @@ describe("BaseFormatter", () => { | |
| }); | ||
| }); | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,21 @@ import fetchText from "../../http/textItems"; | |
| import fetchComponents from "../../http/components"; | ||
| import fetchProjects from "../../http/projects"; | ||
| import fetchVariants from "../../http/variants"; | ||
| import generateSwiftDriver from "../../http/cli"; | ||
| import appContext from "../../utils/appContext"; | ||
| import BaseExportFormatter from "./baseExport"; | ||
|
|
||
| jest.mock("../../http/textItems"); | ||
| jest.mock("../../http/components"); | ||
| jest.mock("../../http/projects"); | ||
| jest.mock("../../http/variants"); | ||
| jest.mock("../../http/cli"); | ||
| jest.mock("../../utils/appContext", () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| outDir: "/mock/app/context/outDir", | ||
| }, | ||
| })); | ||
|
|
||
| const mockFetchText = fetchText as jest.MockedFunction<typeof fetchText>; | ||
| const mockFetchComponents = fetchComponents as jest.MockedFunction< | ||
|
|
@@ -26,6 +35,9 @@ const mockFetchProjects = fetchProjects as jest.MockedFunction< | |
| const mockFetchVariants = fetchVariants as jest.MockedFunction< | ||
| typeof fetchVariants | ||
| >; | ||
| const mockGenerateSwiftDriver = generateSwiftDriver as jest.MockedFunction< | ||
| typeof generateSwiftDriver | ||
| >; | ||
|
|
||
| // fake test class to expose private methods | ||
| // @ts-ignore | ||
|
|
@@ -57,6 +69,14 @@ class TestBaseExportFormatter extends BaseExportFormatter { | |
| public async fetchComponentsMap() { | ||
| return super["fetchComponentsMap"](); | ||
| } | ||
|
|
||
| public getLocalesPath(variantId: string) { | ||
| return super.getLocalesPath(variantId); | ||
| } | ||
|
|
||
| public async getSwiftDriverFile() { | ||
| return super.getSwiftDriverFile(); | ||
| } | ||
| } | ||
|
|
||
| describe("BaseExportFormatter", () => { | ||
|
|
@@ -438,4 +458,242 @@ describe("BaseExportFormatter", () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| /*********************************************************** | ||
| * getLocalesPath | ||
| ***********************************************************/ | ||
|
Comment on lines
+462
to
+464
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this comment is unnecessary if we have the describe block |
||
| describe("getLocalesPath", () => { | ||
| it("should return output outDir when iosLocales is not configured", () => { | ||
| const projectConfig = createMockProjectConfig({ | ||
| iosLocales: undefined, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add test for |
||
| }); | ||
| const output = createMockOutput({ outDir: "/test/output" }); | ||
| // @ts-ignore | ||
| const formatter = new TestBaseExportFormatter( | ||
| output, | ||
| projectConfig, | ||
| createMockMeta() | ||
| ); | ||
|
|
||
| const result = formatter.getLocalesPath("base"); | ||
|
|
||
| expect(result).toBe("/test/output"); | ||
| }); | ||
|
|
||
| it("should return locale path when iosLocales is configured and variantId matches", () => { | ||
| const projectConfig = createMockProjectConfig({ | ||
| iosLocales: [{ base: "en" }, { variant1: "es" }, { variant2: "fr" }], | ||
| }); | ||
| const output = createMockOutput({ outDir: "/test/output" }); | ||
| // @ts-ignore | ||
| const formatter = new TestBaseExportFormatter( | ||
| output, | ||
| projectConfig, | ||
| createMockMeta() | ||
| ); | ||
|
|
||
| const result = formatter.getLocalesPath("variant1"); | ||
|
|
||
| expect(result).toBe("/mock/app/context/outDir/es.lproj"); | ||
| }); | ||
|
|
||
| it("should return output's outDir when iosLocales is configured but variantId does not exist in iosLocales map", () => { | ||
| const projectConfig = createMockProjectConfig({ | ||
| iosLocales: [{ base: "en" }, { variant1: "es" }], | ||
| }); | ||
| const output = createMockOutput({ outDir: "/test/output" }); | ||
| // @ts-ignore | ||
| const formatter = new TestBaseExportFormatter( | ||
| output, | ||
| projectConfig, | ||
| createMockMeta() | ||
| ); | ||
|
|
||
| const result = formatter.getLocalesPath("variant2"); | ||
|
|
||
| expect(result).toBe("/test/output"); | ||
| }); | ||
|
|
||
| it("should return locale path for base variant when configured", () => { | ||
| const projectConfig = createMockProjectConfig({ | ||
| iosLocales: [{ base: "en" }, { variant1: "es" }], | ||
| }); | ||
| const output = createMockOutput({ outDir: "/test/output" }); | ||
| // @ts-ignore | ||
| const formatter = new TestBaseExportFormatter( | ||
| output, | ||
| projectConfig, | ||
| createMockMeta() | ||
| ); | ||
|
|
||
| const result = formatter.getLocalesPath("base"); | ||
|
|
||
| expect(result).toBe("/mock/app/context/outDir/en.lproj"); | ||
| }); | ||
| }); | ||
|
|
||
| /*********************************************************** | ||
| * getSwiftDriverFile | ||
| ***********************************************************/ | ||
| describe("getSwiftDriverFile", () => { | ||
| it("should generate Swift driver file with components folders from projectConfig", async () => { | ||
| const projectConfig = createMockProjectConfig({ | ||
| components: { | ||
| folders: [{ id: "folder1" }, { id: "folder2" }], | ||
| }, | ||
| projects: [{ id: "project1" }], | ||
| }); | ||
| const output = createMockOutput(); | ||
| // @ts-ignore | ||
| const formatter = new TestBaseExportFormatter( | ||
| output, | ||
| projectConfig, | ||
| createMockMeta() | ||
| ); | ||
|
|
||
| const mockSwiftDriver = "import Foundation\nclass Ditto { }"; | ||
| mockGenerateSwiftDriver.mockResolvedValue(mockSwiftDriver); | ||
|
|
||
| const result = await formatter.getSwiftDriverFile(); | ||
|
|
||
| expect(mockGenerateSwiftDriver).toHaveBeenCalledWith( | ||
| { | ||
| components: { | ||
| folders: [{ id: "folder1" }, { id: "folder2" }], | ||
| }, | ||
| projects: [{ id: "project1" }], | ||
| }, | ||
| {} | ||
| ); | ||
| expect(result.filename).toBe("Ditto"); | ||
| expect(result.path).toBe("/mock/app/context/outDir"); | ||
| expect(result.content).toBe(mockSwiftDriver); | ||
| }); | ||
|
|
||
| it("should generate Swift driver file with components folders from output", async () => { | ||
| const projectConfig = createMockProjectConfig({ | ||
| components: { | ||
| folders: [{ id: "config-folder" }], | ||
| }, | ||
| }); | ||
| const output = createMockOutput({ | ||
| components: { | ||
| folders: [{ id: "output-folder1" }, { id: "output-folder2" }], | ||
| }, | ||
| }); | ||
| // @ts-ignore | ||
| const formatter = new TestBaseExportFormatter( | ||
| output, | ||
| projectConfig, | ||
| createMockMeta() | ||
| ); | ||
|
|
||
| const mockSwiftDriver = "import Foundation\nclass Ditto { }"; | ||
| mockGenerateSwiftDriver.mockResolvedValue(mockSwiftDriver); | ||
|
|
||
| const result = await formatter.getSwiftDriverFile(); | ||
|
|
||
| expect(mockGenerateSwiftDriver).toHaveBeenCalledWith( | ||
| { | ||
| components: { | ||
| folders: [{ id: "output-folder1" }, { id: "output-folder2" }], | ||
| }, | ||
| projects: [], | ||
| }, | ||
| {} | ||
| ); | ||
| expect(result.filename).toBe("Ditto"); | ||
| expect(result.path).toBe("/mock/app/context/outDir"); | ||
| expect(result.content).toBe(mockSwiftDriver); | ||
| }); | ||
|
|
||
| it("should generate Swift driver file with projects from output", async () => { | ||
| const projectConfig = createMockProjectConfig({ | ||
| projects: [{ id: "config-project" }], | ||
| components: undefined, | ||
| }); | ||
| const output = createMockOutput({ | ||
| projects: [{ id: "output-project1" }, { id: "output-project2" }], | ||
| }); | ||
| // @ts-ignore | ||
| const formatter = new TestBaseExportFormatter( | ||
| output, | ||
| projectConfig, | ||
| createMockMeta() | ||
| ); | ||
|
|
||
| const mockSwiftDriver = "import Foundation\nclass Ditto { }"; | ||
| mockGenerateSwiftDriver.mockResolvedValue(mockSwiftDriver); | ||
|
|
||
| const result = await formatter.getSwiftDriverFile(); | ||
|
|
||
| expect(mockGenerateSwiftDriver).toHaveBeenCalledWith( | ||
| { | ||
| projects: [{ id: "output-project1" }, { id: "output-project2" }], | ||
| }, | ||
| {} | ||
| ); | ||
| expect(result.filename).toBe("Ditto"); | ||
| expect(result.path).toBe("/mock/app/context/outDir"); | ||
| }); | ||
|
|
||
| it("should generate Swift driver file with empty projects array when not configured", async () => { | ||
| const projectConfig = createMockProjectConfig({ | ||
| projects: [], | ||
| components: { | ||
| folders: [], | ||
| }, | ||
| }); | ||
| const output = createMockOutput(); | ||
| // @ts-ignore | ||
| const formatter = new TestBaseExportFormatter( | ||
| output, | ||
| projectConfig, | ||
| createMockMeta() | ||
| ); | ||
|
|
||
| const mockSwiftDriver = "import Foundation\nclass Ditto { }"; | ||
| mockGenerateSwiftDriver.mockResolvedValue(mockSwiftDriver); | ||
|
|
||
| const result = await formatter.getSwiftDriverFile(); | ||
|
|
||
| expect(mockGenerateSwiftDriver).toHaveBeenCalledWith( | ||
| { | ||
| projects: [], | ||
| components: { | ||
| folders: [], | ||
| }, | ||
| }, | ||
| {} | ||
| ); | ||
| expect(result.filename).toBe("Ditto"); | ||
| expect(result.path).toBe("/mock/app/context/outDir"); | ||
| }); | ||
|
|
||
| it("should not include components in filters when components not configured", async () => { | ||
| const projectConfig = createMockProjectConfig({ | ||
| components: undefined, | ||
| projects: [{ id: "project1" }], | ||
| }); | ||
| const output = createMockOutput(); | ||
| // @ts-ignore | ||
| const formatter = new TestBaseExportFormatter( | ||
| output, | ||
| projectConfig, | ||
| createMockMeta() | ||
| ); | ||
|
|
||
| const mockSwiftDriver = "import Foundation\nclass Ditto { }"; | ||
| mockGenerateSwiftDriver.mockResolvedValue(mockSwiftDriver); | ||
|
|
||
| await formatter.getSwiftDriverFile(); | ||
|
|
||
| expect(mockGenerateSwiftDriver).toHaveBeenCalledWith( | ||
| { | ||
| projects: [{ id: "project1" }], | ||
| }, | ||
| {} | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the spread here