mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-05 05:27:48 +00:00
97 lines
2.9 KiB
JavaScript
97 lines
2.9 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 "Chatwoot" with installation name when both text and installation name are provided', () => {
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName('Welcome to Chatwoot');
|
|
|
|
expect(result).toBe('Welcome to MyCompany');
|
|
});
|
|
|
|
it('should replace multiple occurrences of "Chatwoot"', () => {
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName(
|
|
'Chatwoot is great! Use Chatwoot today.'
|
|
);
|
|
|
|
expect(result).toBe('MyCompany is great! Use MyCompany today.');
|
|
});
|
|
|
|
it('should return original text when installation name is not provided', () => {
|
|
mockGlobalConfig.value = {};
|
|
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName('Welcome to Chatwoot');
|
|
|
|
expect(result).toBe('Welcome to Chatwoot');
|
|
});
|
|
|
|
it('should return original text when globalConfig is not available', () => {
|
|
mockGlobalConfig.value = undefined;
|
|
|
|
const { replaceInstallationName } = useBranding();
|
|
const result = replaceInstallationName('Welcome to Chatwoot');
|
|
|
|
expect(result).toBe('Welcome to Chatwoot');
|
|
});
|
|
|
|
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 Chatwoot');
|
|
|
|
expect(result).toBe('Welcome to My-Company & Co.');
|
|
});
|
|
});
|
|
});
|