Files
chatwoot/app/javascript/widget/helpers/specs/urlParamsHelper.spec.js
Pranav 9de8c27368 feat: Use vitest instead of jest, run all the specs anywhere in app/ folder in the CI (#9722)
Due to the pattern `**/specs/*.spec.js` defined in CircleCI, none of the
frontend spec in the folders such as
`specs/<domain-name>/getters.spec.js` were not executed in Circle CI.

This PR fixes the issue, along with the following changes: 
- Use vitest instead of jest
- Remove jest dependancies
- Update tests to work with vitest

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2024-07-10 08:32:16 -07:00

52 lines
1.4 KiB
JavaScript

import {
buildSearchParamsWithLocale,
getLocale,
buildPopoutURL,
} from '../urlParamsHelper';
describe('#buildSearchParamsWithLocale', () => {
it('returns correct search params', () => {
let windowSpy = vi.spyOn(window, 'window', 'get');
windowSpy.mockImplementation(() => ({
WOOT_WIDGET: {
$root: {
$i18n: {
locale: 'el',
},
},
},
}));
expect(buildSearchParamsWithLocale('?test=1234')).toEqual(
'?test=1234&locale=el'
);
expect(buildSearchParamsWithLocale('')).toEqual('?locale=el');
windowSpy.mockRestore();
});
});
describe('#getLocale', () => {
it('returns correct locale', () => {
expect(getLocale('?test=1&cw_conv=2&locale=fr')).toEqual('fr');
expect(getLocale('?test=1&locale=fr')).toEqual('fr');
expect(getLocale('?test=1&cw_conv=2&website_token=3&locale=fr')).toEqual(
'fr'
);
expect(getLocale('')).toEqual(null);
});
});
describe('#buildPopoutURL', () => {
it('returns popout URL', () => {
expect(
buildPopoutURL({
origin: 'https://chatwoot.com',
conversationCookie: 'random-jwt-token',
websiteToken: 'random-website-token',
locale: 'ar',
})
).toEqual(
'https://chatwoot.com/widget?cw_conversation=random-jwt-token&website_token=random-website-token&locale=ar'
);
});
});