refactor: Rewrite the composable to a helper method
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
|
||||
import { useInstallationName } from 'shared/helpers/installationHelper';
|
||||
|
||||
const {
|
||||
LOGO_THUMBNAIL: logoThumbnail,
|
||||
@@ -14,12 +14,6 @@ export default {
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
const { useInstallationName } = useGlobalConfig();
|
||||
return {
|
||||
useInstallationName,
|
||||
};
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
globalConfig: {
|
||||
@@ -46,6 +40,9 @@ export default {
|
||||
return '';
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
useInstallationName,
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Composable for using the installation name in the application.
|
||||
* @param {string} str - The string to be processed.
|
||||
* @param {string} installationName - The installation name.
|
||||
* @returns {string} The processed string with the installation name.
|
||||
*/
|
||||
|
||||
export const useGlobalConfig = () => {
|
||||
const useInstallationName = (str, installationName) => {
|
||||
if (str && installationName) {
|
||||
return str.replace(/Chatwoot/g, installationName);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
return {
|
||||
useInstallationName,
|
||||
};
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
+2
-6
@@ -1,10 +1,9 @@
|
||||
import { useGlobalConfig } from '../useGlobalConfig';
|
||||
import { useInstallationName } from '../installationNameHelper';
|
||||
|
||||
describe('useGlobalConfig', () => {
|
||||
describe('installationNameHelper', () => {
|
||||
it('should return the string with the installation name', () => {
|
||||
const str = 'Chatwoot is awesome';
|
||||
const installationName = 'Acme Inc';
|
||||
const { useInstallationName } = useGlobalConfig();
|
||||
expect(useInstallationName(str, installationName)).toBe(
|
||||
'Acme Inc is awesome'
|
||||
);
|
||||
@@ -13,7 +12,6 @@ describe('useGlobalConfig', () => {
|
||||
it('should return the string without the installation name', () => {
|
||||
const str = 'Chatwoot is awesome';
|
||||
const installationName = '';
|
||||
const { useInstallationName } = useGlobalConfig();
|
||||
expect(useInstallationName(str, installationName)).toBe(
|
||||
'Chatwoot is awesome'
|
||||
);
|
||||
@@ -22,7 +20,6 @@ describe('useGlobalConfig', () => {
|
||||
it('should handle null installation name properly', () => {
|
||||
const str = 'Chatwoot is super cool';
|
||||
const installationName = null;
|
||||
const { useInstallationName } = useGlobalConfig();
|
||||
expect(useInstallationName(str, installationName)).toBe(
|
||||
'Chatwoot is super cool'
|
||||
);
|
||||
@@ -31,7 +28,6 @@ describe('useGlobalConfig', () => {
|
||||
it('should handle undefined installation name properly', () => {
|
||||
const str = 'Chatwoot is super cool';
|
||||
const installationName = undefined;
|
||||
const { useInstallationName } = useGlobalConfig();
|
||||
expect(useInstallationName(str, installationName)).toBe(
|
||||
'Chatwoot is super cool'
|
||||
);
|
||||
Reference in New Issue
Block a user