summaryrefslogtreecommitdiff
path: root/tests/unit/i18n.vendor.spec.js
blob: 93049b9bfc9bae08750e918e2e879665265399a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// How to run this test in isolation:
//   npm run test:unit -- i18n.vendor.spec.js
// This verifies vendor overlays (e.g., nvidia shared folder) and vendor-root fallback
// without requiring component mounts or full app boot.
describe('i18n vendor overlays', () => {
  const ORIGINAL_ENV = process.env;
  beforeEach(() => {
    jest.resetModules();
    process.env = { ...ORIGINAL_ENV };
    // Ensure default locale is deterministic for the test
    window.localStorage.setItem('storedLanguage', 'en-US');
  });

  afterEach(() => {
    process.env = ORIGINAL_ENV;
  });

  test('falls back to vendor root overlays when env has hyphenated suffix', async () => {
    // Simulate running in nvidia-gb but having overlays only in src/env/locales/nvidia
    process.env.VUE_APP_ENV_NAME = 'nvidia-gb';

    const { createI18nInstance } = await import('@/i18n');
    const vendorEn = require('@/env/locales/nvidia/en-US.json');
    const stubLoader = () => ({ 'en-US': vendorEn.default || vendorEn });
    const i18nInstance = createI18nInstance('nvidia-gb', 'en-US', stubLoader);

    // System HGX dump is NVIDIA-specific and defined in src/env/locales/nvidia/en-US.json
    const translated = i18nInstance.global.t(
      'pageDumps.dumpTypes.systemHgxDump',
    );
    expect(translated).toBe('System [HGX] dump (disruptive)');
  });

  test('base locales do not contain vendor-only keys', async () => {
    process.env.VUE_APP_ENV_NAME = undefined;
    const { createI18nInstance } = await import('@/i18n');
    const i18nInstance = createI18nInstance(undefined, 'en-US');
    const translated = i18nInstance.global.t(
      'pageDumps.dumpTypes.systemHgxDump',
    );
    // When no env overlays are loaded, accessing vendor-only keys should return the key path
    expect(translated).toBe('pageDumps.dumpTypes.systemHgxDump');
  });
});