Files
gochat/frontend/app/javascript/entrypoints/specs/runtimeConfig.spec.js
T
Rogeeandrogee 867092fd99 HH-530: replace user-facing Chatwoot branding with GoChat (#117)
* fix(HH-530): replace user-facing Chatwoot branding

* fix(HH-530): close branding review blockers

* test(HH-530): cover update banner binding

---------

Co-authored-by: Rogee <rogee@ipao.vip>
2026-08-23 18:14:02 +08:00

39 lines
1.1 KiB
JavaScript

import { readFileSync } from 'node:fs';
import { runInNewContext } from 'node:vm';
const customBrand = {
INSTALLATION_NAME: 'Acme Support',
BRAND_NAME: 'Acme',
LOGO: '/acme/logo.svg',
LOGO_DARK: '/acme/logo-dark.svg',
LOGO_THUMBNAIL: '/acme/icon.svg',
};
const initializeEntrypoint = filename => {
const html = readFileSync(filename, 'utf8');
const inlineScript = html.match(/<script>\s*([\s\S]*?)<\/script>/);
const runtimeConfigIndex = html.indexOf('/runtime-config.js');
expect(runtimeConfigIndex).toBeGreaterThan(-1);
expect(runtimeConfigIndex).toBeLessThan(inlineScript.index);
const entrypointWindow = {
__GOCHAT_CONFIG__: { globalConfig: customBrand },
location: { search: '' },
};
runInNewContext(inlineScript[1], {
window: entrypointWindow,
navigator: { userAgent: 'test' },
URLSearchParams,
localStorage: { getItem: () => null, setItem: () => {} },
});
return entrypointWindow.globalConfig;
};
it.each(['widget.html', 'super_admin.html'])(
'applies custom runtime branding in %s',
filename => {
expect(initializeEntrypoint(filename)).toMatchObject(customBrand);
}
);