Skip to content

Commit 390f0e8

Browse files
refactor(e2e): derive locale and audit types from as const arrays
Use single-source-of-truth const tuples for Locale and audit log enums, and loop LOCALES when merging translation bundles. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e01e720 commit 390f0e8

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

e2e-tests/playwright/e2e/audit-log/logs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ interface LogResponse {
2020
status: number;
2121
}
2222

23-
export type EventStatus = "initiated" | "succeeded" | "failed";
23+
const EVENT_STATUSES = ["initiated", "succeeded", "failed"] as const;
24+
export type EventStatus = (typeof EVENT_STATUSES)[number];
2425

25-
export type EventSeverityLevel = "low" | "medium" | "high" | "critical";
26+
const EVENT_SEVERITY_LEVELS = ["low", "medium", "high", "critical"] as const;
27+
export type EventSeverityLevel = (typeof EVENT_SEVERITY_LEVELS)[number];
2628

2729
export class Log {
2830
actor: Actor;

e2e-tests/playwright/e2e/localization/locale.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,21 @@ const ja = {
5050
...jaRhdhPlugins,
5151
};
5252

53-
export type Locale = "de" | "en" | "es" | "fr" | "it" | "ja";
53+
const LOCALES = ["de", "en", "es", "fr", "it", "ja"] as const;
54+
export type Locale = (typeof LOCALES)[number];
5455

55-
const LOCALES: readonly Locale[] = ["de", "en", "es", "fr", "it", "ja"];
56+
const NON_EN_LOCALE_BUNDLES = {
57+
de,
58+
es,
59+
fr,
60+
it,
61+
ja,
62+
} as const;
63+
64+
const LOCALE_SET = new Set<string>(LOCALES);
5665

5766
function isLocale(lang: string): lang is Locale {
58-
return (LOCALES as readonly string[]).includes(lang);
67+
return LOCALE_SET.has(lang);
5968
}
6069

6170
type TranslationFile = Record<string, Record<string, Record<string, string>>>;
@@ -78,14 +87,23 @@ function createMergedTranslations() {
7887

7988
for (const namespace of allNamespaces) {
8089
const enKeys = (en as TranslationFile)[namespace]?.en || {};
81-
merged[namespace] = {
90+
const namespaceTranslations: Record<string, Record<string, string>> = {
8291
en: enKeys,
83-
de: { ...enKeys, ...(de as TranslationFile)[namespace]?.de },
84-
es: { ...enKeys, ...(es as TranslationFile)[namespace]?.es },
85-
fr: { ...enKeys, ...(fr as TranslationFile)[namespace]?.fr },
86-
it: { ...enKeys, ...(it as TranslationFile)[namespace]?.it },
87-
ja: { ...enKeys, ...(ja as TranslationFile)[namespace]?.ja },
8892
};
93+
94+
for (const locale of LOCALES) {
95+
if (locale === "en") {
96+
continue;
97+
}
98+
namespaceTranslations[locale] = {
99+
...enKeys,
100+
...(NON_EN_LOCALE_BUNDLES[locale] as TranslationFile)[namespace]?.[
101+
locale
102+
],
103+
};
104+
}
105+
106+
merged[namespace] = namespaceTranslations;
89107
}
90108

91109
return merged;

0 commit comments

Comments
 (0)