xref: /openbmc/webui-vue/tests/unit/i18n.vendor.spec.js (revision d2483622fc31f6b965a052d0c4f999ad963d0a0f)
1// How to run this test in isolation:
2//   npm run test:unit -- i18n.vendor.spec.js
3// This verifies vendor overlays (e.g., nvidia shared folder) and vendor-root fallback
4// without requiring component mounts or full app boot.
5describe('i18n vendor overlays', () => {
6  const ORIGINAL_ENV = process.env;
7  beforeEach(() => {
8    jest.resetModules();
9    process.env = { ...ORIGINAL_ENV };
10    // Ensure default locale is deterministic for the test
11    window.localStorage.setItem('storedLanguage', 'en-US');
12  });
13
14  afterEach(() => {
15    process.env = ORIGINAL_ENV;
16  });
17
18  test('falls back to vendor root overlays when env has hyphenated suffix', async () => {
19    // Simulate running in nvidia-gb but having overlays only in src/env/locales/nvidia
20    process.env.VUE_APP_ENV_NAME = 'nvidia-gb';
21
22    const { createI18nInstance } = await import('@/i18n');
23    const vendorEn = require('@/env/locales/nvidia/en-US.json');
24    const stubLoader = () => ({ 'en-US': vendorEn.default || vendorEn });
25    const i18nInstance = createI18nInstance('nvidia-gb', 'en-US', stubLoader);
26
27    // System HGX dump is NVIDIA-specific and defined in src/env/locales/nvidia/en-US.json
28    const translated = i18nInstance.global.t(
29      'pageDumps.dumpTypes.systemHgxDump',
30    );
31    expect(translated).toBe('System [HGX] dump (disruptive)');
32  });
33
34  test('base locales do not contain vendor-only keys', async () => {
35    process.env.VUE_APP_ENV_NAME = undefined;
36    const { createI18nInstance } = await import('@/i18n');
37    const i18nInstance = createI18nInstance(undefined, 'en-US');
38    const translated = i18nInstance.global.t(
39      'pageDumps.dumpTypes.systemHgxDump',
40    );
41    // When no env overlays are loaded, accessing vendor-only keys should return the key path
42    expect(translated).toBe('pageDumps.dumpTypes.systemHgxDump');
43  });
44});
45