* 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>
105 lines
3.1 KiB
JavaScript
105 lines
3.1 KiB
JavaScript
import { useBranding } from '../useBranding';
|
|
import { useMapGetter } from 'dashboard/composables/store.js';
|
|
|
|
// Mock the store composable
|
|
vi.mock('dashboard/composables/store.js', () => ({
|
|
useMapGetter: vi.fn(),
|
|
}));
|
|
|
|
describe('useBranding', () => {
|
|
let mockGlobalConfig;
|
|
|
|
beforeEach(() => {
|
|
mockGlobalConfig = {
|
|
value: {
|
|
installationName: 'MyCompany',
|
|
},
|
|
};
|
|
|
|
useMapGetter.mockReturnValue(mockGlobalConfig);
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('replaceInstallationName', () => {
|
|
it('should replace "GoChat" with the installation name', () => {
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName('Welcome to GoChat');
|
|
|
|
expect(result).toBe('Welcome to MyCompany');
|
|
});
|
|
|
|
it('should replace multiple occurrences of "GoChat"', () => {
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName(
|
|
'GoChat is great! Use GoChat today.'
|
|
);
|
|
|
|
expect(result).toBe('MyCompany is great! Use MyCompany today.');
|
|
});
|
|
|
|
it('should preserve legacy Chatwoot placeholders for custom branding', () => {
|
|
const { replaceInstallationName } = useBranding();
|
|
|
|
expect(replaceInstallationName('Welcome to Chatwoot')).toBe(
|
|
'Welcome to MyCompany'
|
|
);
|
|
});
|
|
|
|
it('should return original text when installation name is not provided', () => {
|
|
mockGlobalConfig.value = {};
|
|
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName('Welcome to GoChat');
|
|
|
|
expect(result).toBe('Welcome to GoChat');
|
|
});
|
|
|
|
it('should return original text when globalConfig is not available', () => {
|
|
mockGlobalConfig.value = undefined;
|
|
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName('Welcome to GoChat');
|
|
|
|
expect(result).toBe('Welcome to GoChat');
|
|
});
|
|
|
|
it('should return original text when text is empty or null', () => {
|
|
const { replaceInstallationName } = useBranding();
|
|
|
|
expect(replaceInstallationName('')).toBe('');
|
|
expect(replaceInstallationName(null)).toBe(null);
|
|
expect(replaceInstallationName(undefined)).toBe(undefined);
|
|
});
|
|
|
|
it('should handle text without "Chatwoot" gracefully', () => {
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName('Welcome to our platform');
|
|
|
|
expect(result).toBe('Welcome to our platform');
|
|
});
|
|
|
|
it('should be case-sensitive for "Chatwoot"', () => {
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName(
|
|
'Welcome to chatwoot and CHATWOOT'
|
|
);
|
|
|
|
expect(result).toBe('Welcome to chatwoot and CHATWOOT');
|
|
});
|
|
|
|
it('should handle special characters in installation name', () => {
|
|
mockGlobalConfig.value = {
|
|
installationName: 'My-Company & Co.',
|
|
};
|
|
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName('Welcome to GoChat');
|
|
|
|
expect(result).toBe('Welcome to My-Company & Co.');
|
|
});
|
|
});
|
|
});
|