Skip to content

Commit

Permalink
test(frontend): fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Falinor committed Nov 26, 2024
1 parent a427c0b commit cf56360
Showing 1 changed file with 36 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MemoryRouter as Router, Route } from 'react-router-dom';
import { createMemoryRouter, RouterProvider } from 'react-router-dom';
import AccountEmailActivationView from '../AccountEmailActivationView';
import { Provider } from 'react-redux';
import { store } from '../../../../store/store';
Expand All @@ -11,16 +11,22 @@ describe('AccountEmailActivationView', () => {

describe('Without passing an email in route state', () => {
function setup() {
const router = createMemoryRouter(
[
{ path: '/inscription/email', element: 'Créer votre compte' },
{
path: '/inscription/activation',
element: <AccountEmailActivationView />
}
],
{
initialEntries: ['/inscription/activation']
}
);
render(
<Provider store={store}>
<Router initialEntries={['/inscription/activation']}>
<Route path="/inscription/email">Créer votre compte</Route>
<Route
path="/inscription/activation"
component={AccountEmailActivationView}
/>
</Router>
</Provider>,
<RouterProvider router={router} />
</Provider>
);
}

Expand All @@ -34,32 +40,34 @@ describe('AccountEmailActivationView', () => {

describe('With an email', () => {
function setup() {
const router = createMemoryRouter(
[
{
path: '/inscription/activation',
element: <AccountEmailActivationView />
}
],
{
initialEntries: [
{
pathname: '/inscription/activation',
state: { email: '[email protected]' }
}
]
}
);
render(
<Provider store={store}>
<Router
initialEntries={[
{
pathname: '/inscription/activation',
state: {
email: '[email protected]',
},
},
]}
>
<Route
path="/inscription/activation"
component={AccountEmailActivationView}
/>
</Router>
</Provider>,
<RouterProvider router={router} />
</Provider>
);
}

it('should render', async () => {
setup();

const title = screen.getByText(
'Vous devez confirmer votre adresse mail.',
'Vous devez confirmer votre adresse mail.'
);

expect(title).toBeVisible();
Expand All @@ -68,15 +76,15 @@ describe('AccountEmailActivationView', () => {
it('should send an email again', async () => {
const sendActivationEmail = jest.spyOn(
signupLinkApi.endpoints.sendActivationEmail,
'initiate',
'initiate'
);
setup();

const sendAgain = screen.getByText(/renvoyer le mail/i);
await user.click(sendAgain);

expect(sendActivationEmail).toHaveBeenCalledWith('[email protected]', {
fixedCacheKey: undefined,
fixedCacheKey: undefined
});
const sent = screen.getByText('Email envoyé.');
expect(sent).toBeVisible();
Expand Down

0 comments on commit cf56360

Please sign in to comment.