Files
harvester-ui-extension/pkg/harvester/utils/__tests__/l10n-globals.test.js
T
marcelofukumoto 6e0e0237ef feat: use the SUSE Virtualization product name on Prime (#1202)
* feat: switch the product name with Rancher Prime

Use a [[Harvester]] token for the product name in the translations, so
Rancher 2.16 fills it from the l10n global that harvester-manager
registers: SUSE Virtualization on Rancher Prime, Harvester otherwise.

Rancher before 2.16 shows the tokens as written, so on those hosts (and
standalone) the extension resolves them to Harvester itself.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* feat: switch the standalone product name with the server flavor

Standalone has no Rancher Prime, so register the [[Harvester]] l10n
global from the server-flavor setting instead: SUSE Virtualization on
prime, Harvester otherwise.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* fix: point the network policy banner to the documentation

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* feat: use the SUSE theme in standalone Prime

Standalone Prime kept the harvester brand and only overrode the primary
colour, so the rest of the palette and the fonts didn't match Rancher
Prime. Switch the ui-brand setting to suse in the store when the server
flavor is prime, which makes the shell load the SUSE theme.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* fix: keep the SUSE theme after a brand setting change event

The watcher also reads the setting's value, so a change from the server
loaded into the same object switches the brand back to suse.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

---------

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
2026-10-26 17:28:50 +01:00

102 lines
3.4 KiB
JavaScript

import fs from 'fs';
import path from 'path';
import { load } from 'js-yaml';
import { hostResolvesL10nGlobals, resolveL10nGlobals, setStandalonePrime, standaloneProductName } from '../l10n-globals';
describe('hostResolvesL10nGlobals', () => {
it('should be true from Rancher 2.16', () => {
expect(hostResolvesL10nGlobals('v2.16.0')).toBe(true);
expect(hostResolvesL10nGlobals('v2.17.1')).toBe(true);
});
it('should be true for 2.16 head builds', () => {
expect(hostResolvesL10nGlobals('v2.16.0-68ddd75-head')).toBe(true);
expect(hostResolvesL10nGlobals('v2.16-136b11a0062247c1b28f107d82283bdb29bc07ae-head')).toBe(true);
});
it('should be false before Rancher 2.16', () => {
expect(hostResolvesL10nGlobals('v2.15.1')).toBe(false);
expect(hostResolvesL10nGlobals('v2.14.6')).toBe(false);
});
it('should be false when the Rancher version is missing or unknown', () => {
expect(hostResolvesL10nGlobals('')).toBe(false);
expect(hostResolvesL10nGlobals(undefined)).toBe(false);
expect(hostResolvesL10nGlobals('dev')).toBe(false);
});
});
describe('standaloneProductName', () => {
it('should be Harvester when the server flavor is not prime', () => {
setStandalonePrime(false);
expect(standaloneProductName()).toBe('Harvester');
});
it('should be SUSE Virtualization when the server flavor is prime', () => {
setStandalonePrime(true);
expect(standaloneProductName()).toBe('SUSE Virtualization');
setStandalonePrime(false);
});
it('should go back to Harvester when the server flavor changes from prime', () => {
setStandalonePrime(true);
setStandalonePrime(false);
expect(standaloneProductName()).toBe('Harvester');
});
});
describe('resolveL10nGlobals', () => {
it('should replace tokens with their name when no value is given', () => {
const translations = { support: { title: '[[Harvester]] Support' } };
resolveL10nGlobals(translations);
expect(translations).toStrictEqual({ support: { title: 'Harvester Support' } });
});
it('should replace every token in a string with the given value', () => {
const translations = { message: 'The [[Harvester]] UI only supports [[Harvester]] v1.3.0 and later' };
resolveL10nGlobals(translations, { Harvester: 'SUSE Virtualization' });
expect(translations.message).toBe('The SUSE Virtualization UI only supports SUSE Virtualization v1.3.0 and later');
});
it('should keep an escaped token as a literal', () => {
const translations = { message: 'Use \\[[Harvester]] in a string' };
resolveL10nGlobals(translations);
expect(translations.message).toBe('Use [[Harvester]] in a string');
});
it('should leave strings without tokens and non-string values untouched', () => {
const translations = {
plain: 'harvester-seeder is an add-on',
count: 3,
nested: { link: '<a href="https://harvesterhci.io/">site</a>' },
};
resolveL10nGlobals(translations);
expect(translations).toStrictEqual({
plain: 'harvester-seeder is an add-on',
count: 3,
nested: { link: '<a href="https://harvesterhci.io/">site</a>' },
});
});
it('should leave no token in the extension translations', () => {
const translations = load(fs.readFileSync(path.join(__dirname, '../../l10n/en-us.yaml'), 'utf8'));
expect(JSON.stringify(translations)).toContain('[[Harvester]]');
resolveL10nGlobals(translations);
expect(JSON.stringify(translations)).not.toContain('[[');
});
});