refactor: Rewrite the composable to a helper method
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Replaces occurrences of "Chatwoot" with the provided installation name in a given string.
|
||||
*
|
||||
* @param {string} str - The original string that may contain "Chatwoot".
|
||||
* @param {string} installationName - The name to replace "Chatwoot" with.
|
||||
* @returns {string} The modified string with "Chatwoot" replaced by the installation name,
|
||||
* or the original string if either input is falsy.
|
||||
*/
|
||||
export const useInstallationName = (str, installationName) => {
|
||||
if (str && installationName) {
|
||||
return str.replace(/Chatwoot/g, installationName);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useInstallationName } from '../installationNameHelper';
|
||||
|
||||
describe('installationNameHelper', () => {
|
||||
it('should return the string with the installation name', () => {
|
||||
const str = 'Chatwoot is awesome';
|
||||
const installationName = 'Acme Inc';
|
||||
expect(useInstallationName(str, installationName)).toBe(
|
||||
'Acme Inc is awesome'
|
||||
);
|
||||
});
|
||||
|
||||
it('should return the string without the installation name', () => {
|
||||
const str = 'Chatwoot is awesome';
|
||||
const installationName = '';
|
||||
expect(useInstallationName(str, installationName)).toBe(
|
||||
'Chatwoot is awesome'
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle null installation name properly', () => {
|
||||
const str = 'Chatwoot is super cool';
|
||||
const installationName = null;
|
||||
expect(useInstallationName(str, installationName)).toBe(
|
||||
'Chatwoot is super cool'
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle undefined installation name properly', () => {
|
||||
const str = 'Chatwoot is super cool';
|
||||
const installationName = undefined;
|
||||
expect(useInstallationName(str, installationName)).toBe(
|
||||
'Chatwoot is super cool'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user