Skip to content

Commit

Permalink
(HP-2047) Remove enzyme from header test
Browse files Browse the repository at this point in the history
  • Loading branch information
Riippi committed Feb 19, 2024
1 parent 9d7e248 commit f73ee6a
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/common/header/__tests__/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import React from 'react';
import { mount } from 'enzyme';
import { render, fireEvent, waitFor } from '@testing-library/react';

import i18n from '../../test/testi18nInit';
import Header from '../Header';

const getWrapper = () => mount(<Header />);

it('language is changed from header language selector', () => {
it('language is changed from header language selector', async () => {
i18n.changeLanguage('fi');
const wrapper = getWrapper();
const { getByText } = render(<Header />);

const ariaCurrent = 'aria-current';

const fiButton = wrapper
.find('button')
.filterWhere(node => node.text() === 'Suomi');
expect(fiButton.props()[ariaCurrent]).toBe(true);
// Find the button for Finnish
const fiButton = getByText('Suomi').parentElement;
expect(fiButton?.getAttribute(ariaCurrent)).toBe('true');
expect(i18n.language).toBe('fi');

const svButton = wrapper
.find('button')
.filterWhere(node => node.text() === 'Svenska');
expect(svButton.props()[ariaCurrent]).toBe(false);
// Find the button for Swedish
const svButton = getByText('Svenska').parentElement;
expect(svButton?.getAttribute(ariaCurrent)).toBe('false');

// Change the language
svButton.simulate('click');
if (svButton) {
fireEvent.click(svButton);
}

setTimeout(() => {
expect(fiButton.props()[ariaCurrent]).toBe(false);
await waitFor(() => {
expect(fiButton?.getAttribute(ariaCurrent)).toBe('false');
expect(svButton?.getAttribute(ariaCurrent)).toBe('true');
expect(i18n.language).toBe('sv');
}, 100);
});
});

0 comments on commit f73ee6a

Please sign in to comment.