chore: Replace globalConfig Mixin with useGlobalConfig Composable

This commit is contained in:
Fayaz Ahmed
2024-08-20 07:53:21 +05:30
parent 8473e72a7e
commit c798474f2b
18 changed files with 142 additions and 42 deletions
@@ -1,5 +1,5 @@
<script>
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
const {
LOGO_THUMBNAIL: logoThumbnail,
@@ -8,13 +8,18 @@ const {
} = window.globalConfig || {};
export default {
mixins: [globalConfigMixin],
props: {
disableBranding: {
type: Boolean,
default: false,
},
},
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
data() {
return {
globalConfig: {
@@ -0,0 +1,39 @@
import { useGlobalConfig } from '../useGlobalConfig';
describe('useGlobalConfig', () => {
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'
);
});
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'
);
});
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'
);
});
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'
);
});
});
@@ -0,0 +1,18 @@
/*
* 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,
};
};
@@ -1,12 +0,0 @@
export const useInstallationName = (str, installationName) => {
if (str && installationName) {
return str.replace(/Chatwoot/g, installationName);
}
return str;
};
export default {
methods: {
useInstallationName,
},
};