-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
134 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
@@ -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> | ||
); | ||
} | ||
|
||
|
@@ -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(); | ||
|
@@ -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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,51 @@ | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { MemoryRouter as Router, Route } from 'react-router-dom'; | ||
import { | ||
genAuthUser, | ||
genProspect, | ||
genSignupLink, | ||
} from '../../../../../test/fixtures.test'; | ||
import { createMemoryRouter, RouterProvider } from 'react-router-dom'; | ||
import { genProspect, genSignupLink } from '../../../../../test/fixtures.test'; | ||
import AccountPasswordCreationView from '../AccountPasswordCreationView'; | ||
import { Provider } from 'react-redux'; | ||
import prospectService from '../../../../services/prospect.service'; | ||
import { Prospect } from '../../../../models/Prospect'; | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { applicationReducer } from '../../../../store/store'; | ||
import AccountCampaignIntentCreationView from '../AccountCampaignIntentCreationView'; | ||
import configureTestStore from '../../../../utils/test/storeUtils'; | ||
|
||
describe('AccountPasswordCreationView', () => { | ||
const user = userEvent.setup(); | ||
const store = configureStore({ | ||
reducer: applicationReducer, | ||
preloadedState: { authentication: { authUser: genAuthUser() } }, | ||
}); | ||
const email = '[email protected]'; | ||
const link = genSignupLink(email); | ||
const prospect: Prospect = { | ||
...genProspect(), | ||
email, | ||
hasAccount: true, | ||
hasCommitment: true, | ||
hasCommitment: true | ||
}; | ||
|
||
function setup() { | ||
const router = createMemoryRouter( | ||
[ | ||
{ path: '/inscription/en-attente', element: 'En attente' }, | ||
{ path: '/inscription/impossible', element: 'Impossible' }, | ||
{ path: '/inscription/email', element: 'Email' }, | ||
{ | ||
path: '/inscription/mot-de-passe', | ||
element: <AccountPasswordCreationView /> | ||
}, | ||
{ | ||
path: '/inscription/campagne', | ||
element: <AccountCampaignIntentCreationView /> | ||
} | ||
], | ||
{ | ||
initialEntries: [ | ||
{ pathname: '/inscription/mot-de-passe', hash: `#${link.id}` } | ||
] | ||
} | ||
); | ||
const store = configureTestStore(); | ||
render( | ||
<Provider store={store}> | ||
<Router | ||
initialEntries={[ | ||
{ | ||
pathname: '/inscription/mot-de-passe', | ||
hash: `#${link.id}`, | ||
}, | ||
]} | ||
> | ||
<Route path="/inscription/en-attente">En attente</Route> | ||
<Route path="/inscription/impossible">Impossible</Route> | ||
<Route path="/inscription/email">Email</Route> | ||
<Route | ||
path="/inscription/mot-de-passe" | ||
component={AccountPasswordCreationView} | ||
/> | ||
<Route | ||
path="/inscription/campagne" | ||
component={AccountCampaignIntentCreationView} | ||
/> | ||
</Router> | ||
</Provider>, | ||
<RouterProvider router={router} /> | ||
</Provider> | ||
); | ||
} | ||
|
||
|
@@ -81,7 +74,7 @@ describe('AccountPasswordCreationView', () => { | |
it("should be forbidden if one's establishment does not exist in ZLV", async () => { | ||
mockProspectServicePass({ | ||
...prospect, | ||
establishment: null, | ||
establishment: null | ||
}); | ||
setup(); | ||
|
||
|
@@ -93,7 +86,7 @@ describe('AccountPasswordCreationView', () => { | |
mockProspectServicePass({ | ||
...prospect, | ||
hasAccount: true, | ||
hasCommitment: false, | ||
hasCommitment: false | ||
}); | ||
setup(); | ||
|
||
|
@@ -105,7 +98,7 @@ describe('AccountPasswordCreationView', () => { | |
mockProspectServicePass({ | ||
...prospect, | ||
hasAccount: false, | ||
hasCommitment: false, | ||
hasCommitment: false | ||
}); | ||
setup(); | ||
|
||
|
@@ -130,11 +123,11 @@ describe('AccountPasswordCreationView', () => { | |
const password = '123QWEasd'; | ||
|
||
const passwordInput = await screen.findByLabelText( | ||
/Créer votre mot de passe/, | ||
/Créer votre mot de passe/ | ||
); | ||
await user.type(passwordInput, password); | ||
const confirmationInput = await screen.findByLabelText( | ||
/Confirmer votre mot de passe/, | ||
/Confirmer votre mot de passe/ | ||
); | ||
await user.type(confirmationInput, password); | ||
await user.keyboard('{Enter}'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.