Files
chatwoot/app/javascript/portal/specs/portal.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

47 lines
1.4 KiB
JavaScript

import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { JSDOM } from 'jsdom';
import { InitializationHelpers } from '../portalHelpers';
describe('InitializationHelpers.navigateToLocalePage', () => {
let dom;
let document;
let window;
beforeEach(() => {
dom = new JSDOM(
'<!DOCTYPE html><html><body><div class="locale-switcher" data-portal-slug="test-slug"><select><option value="en">English</option><option value="fr">French</option></select></div></body></html>',
{ url: 'http://localhost/' }
);
document = dom.window.document;
window = dom.window;
global.document = document;
global.window = window;
});
afterEach(() => {
dom = null;
document = null;
window = null;
delete global.document;
delete global.window;
});
it('should return false if .locale-switcher is not found', () => {
document.querySelector('.locale-switcher').remove();
const result = InitializationHelpers.navigateToLocalePage();
expect(result).toBe(false);
});
it('should add change event listener to .locale-switcher', () => {
const localeSwitcher = document.querySelector('.locale-switcher');
const addEventListenerSpy = vi.spyOn(localeSwitcher, 'addEventListener');
InitializationHelpers.navigateToLocalePage();
expect(addEventListenerSpy).toHaveBeenCalledWith(
'change',
expect.any(Function)
);
});
});