2020-08-28 12:09:46 +00:00
|
|
|
import {
|
|
|
|
buildSearchParamsWithLocale,
|
|
|
|
getLocale,
|
|
|
|
buildPopoutURL,
|
|
|
|
} from '../urlParamsHelper';
|
2020-06-12 18:49:43 +00:00
|
|
|
|
|
|
|
describe('#buildSearchParamsWithLocale', () => {
|
|
|
|
it('returns correct search params', () => {
|
2020-12-12 06:38:36 +00:00
|
|
|
let windowSpy = jest.spyOn(window, 'window', 'get');
|
|
|
|
windowSpy.mockImplementation(() => ({
|
|
|
|
WOOT_WIDGET: {
|
|
|
|
$root: {
|
|
|
|
$i18n: {
|
|
|
|
locale: 'el',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
2020-06-12 18:49:43 +00:00
|
|
|
expect(buildSearchParamsWithLocale('?test=1234')).toEqual(
|
|
|
|
'?test=1234&locale=el'
|
|
|
|
);
|
|
|
|
expect(buildSearchParamsWithLocale('')).toEqual('?locale=el');
|
2020-12-12 06:38:36 +00:00
|
|
|
windowSpy.mockRestore();
|
2020-06-12 18:49:43 +00:00
|
|
|
});
|
|
|
|
});
|
2020-08-28 12:09:46 +00:00
|
|
|
|
|
|
|
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'
|
|
|
|
);
|
2022-10-19 20:20:40 +00:00
|
|
|
expect(getLocale('')).toEqual(null);
|
2020-08-28 12:09:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|