mirror of
https://github.com/strapi/strapi.git
synced 2025-09-08 08:08:18 +00:00
tests and aria-busy attempt
This commit is contained in:
parent
dfeabd6079
commit
ea0723fbe1
@ -74,6 +74,8 @@ const ProfilePage = () => {
|
|||||||
refetchActive: true,
|
refetchActive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { isLoading: isSubmittingForm } = submitMutation;
|
||||||
|
|
||||||
const handleSubmit = async body => {
|
const handleSubmit = async body => {
|
||||||
lockApp();
|
lockApp();
|
||||||
|
|
||||||
@ -91,16 +93,16 @@ const ProfilePage = () => {
|
|||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<Main labelledBy="title">
|
<Main>
|
||||||
<Helmet title="User profile" />
|
<Helmet title="User profile" />
|
||||||
<HeaderLayout id="title" title="Profile page" />
|
<HeaderLayout title="Profile page" />
|
||||||
<CustomContentLayout isLoading />
|
<CustomContentLayout isLoading />
|
||||||
</Main>
|
</Main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Main labelledBy="user-profile">
|
<Main aria-busy={isSubmittingForm}>
|
||||||
<Helmet title="User profile" />
|
<Helmet title="User profile" />
|
||||||
<Formik
|
<Formik
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
@ -113,7 +115,6 @@ const ProfilePage = () => {
|
|||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
<HeaderLayout
|
<HeaderLayout
|
||||||
id="user-profile"
|
|
||||||
title={data.username || `${data.firstname} ${data.lastname}`}
|
title={data.username || `${data.firstname} ${data.lastname}`}
|
||||||
primaryAction={
|
primaryAction={
|
||||||
<Button startIcon={<CheckIcon />} loading={isSubmitting} type="submit">
|
<Button startIcon={<CheckIcon />} loading={isSubmitting} type="submit">
|
||||||
|
@ -2,9 +2,10 @@ import React from 'react';
|
|||||||
import { render, waitFor, screen } from '@testing-library/react';
|
import { render, waitFor, screen } from '@testing-library/react';
|
||||||
import { IntlProvider } from 'react-intl';
|
import { IntlProvider } from 'react-intl';
|
||||||
import { QueryClient, QueryClientProvider } from 'react-query';
|
import { QueryClient, QueryClientProvider } from 'react-query';
|
||||||
|
// import { rest } from 'msw';
|
||||||
import { ThemeProvider, lightTheme } from '@strapi/parts';
|
import { ThemeProvider, lightTheme } from '@strapi/parts';
|
||||||
import ProfilePage from '../index';
|
import ProfilePage from '../index';
|
||||||
import { serverUsername, serverNoUsername } from './utils/server';
|
import server from './utils/server';
|
||||||
|
|
||||||
jest.mock('../../../components/LocalesProvider/useLocalesProvider', () => () => ({
|
jest.mock('../../../components/LocalesProvider/useLocalesProvider', () => () => ({
|
||||||
changeLocale: () => {},
|
changeLocale: () => {},
|
||||||
@ -39,25 +40,22 @@ const App = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
describe('ADMIN | Pages | Profile page', () => {
|
describe('ADMIN | Pages | Profile page', () => {
|
||||||
// beforeAll(() => server.listen());
|
beforeAll(() => server.listen());
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
serverUsername.resetHandlers();
|
server.resetHandlers();
|
||||||
serverNoUsername.resetHandlers();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
serverUsername.close();
|
server.close();
|
||||||
serverNoUsername.close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders and matches the snapshot', async () => {
|
it('renders and matches the snapshot', async () => {
|
||||||
serverUsername.listen();
|
|
||||||
const { container } = render(App);
|
const { container } = render(App);
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.getByText('Interface language')).toBeInTheDocument();
|
expect(screen.getByText('Interface language')).toBeInTheDocument();
|
||||||
@ -565,7 +563,7 @@ describe('ADMIN | Pages | Profile page', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<main
|
<main
|
||||||
aria-labelledby="user-profile"
|
aria-busy="false"
|
||||||
class="c0"
|
class="c0"
|
||||||
id="main-content"
|
id="main-content"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
@ -590,7 +588,6 @@ describe('ADMIN | Pages | Profile page', () => {
|
|||||||
>
|
>
|
||||||
<h1
|
<h1
|
||||||
class="c4"
|
class="c4"
|
||||||
id="user-profile"
|
|
||||||
>
|
>
|
||||||
yolo
|
yolo
|
||||||
</h1>
|
</h1>
|
||||||
@ -1029,7 +1026,6 @@ describe('ADMIN | Pages | Profile page', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should display username if it exists', async () => {
|
it('should display username if it exists', async () => {
|
||||||
serverUsername.listen();
|
|
||||||
render(App);
|
render(App);
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.getByText('yolo')).toBeInTheDocument();
|
expect(screen.getByText('yolo')).toBeInTheDocument();
|
||||||
@ -1037,10 +1033,30 @@ describe('ADMIN | Pages | Profile page', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should display firstname/lastname if username doesn't exist", async () => {
|
it("should display firstname/lastname if username doesn't exist", async () => {
|
||||||
// serverNoUsername.listen();
|
// TODO
|
||||||
|
// server.use(
|
||||||
|
// rest.get('*/me', (req, res, ctx) => {
|
||||||
|
// return res(
|
||||||
|
// ctx.delay(100),
|
||||||
|
// ctx.status(200),
|
||||||
|
// ctx.json({
|
||||||
|
// data: {
|
||||||
|
// email: 'HOLA@michka.fr',
|
||||||
|
// firstname: 'michoko',
|
||||||
|
// lastname: 'ronronscelestes',
|
||||||
|
// username: 'HOLA',
|
||||||
|
// preferedLanguage: 'en',
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// )
|
||||||
|
// }),
|
||||||
|
// )
|
||||||
// const { queryByText } = render(App);
|
// const { queryByText } = render(App);
|
||||||
|
// // await waitFor(() => {
|
||||||
|
// // expect(queryByText('michka@michka.fr')).not.toBeInTheDocument();
|
||||||
|
// // });
|
||||||
// await waitFor(() => {
|
// await waitFor(() => {
|
||||||
// expect(queryByText('michoko@michka.fr')).toBeInTheDocument();
|
// expect(screen.getByText('HOLA@michka.fr')).toBeInTheDocument();
|
||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -19,23 +19,6 @@ const handlers = [
|
|||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
export const serverUsername = setupServer(...handlers);
|
const server = setupServer(...handlers);
|
||||||
|
|
||||||
const handlersNoUsername = [
|
export default server;
|
||||||
rest.get('*/me', (req, res, ctx) => {
|
|
||||||
return res(
|
|
||||||
ctx.delay(100),
|
|
||||||
ctx.status(200),
|
|
||||||
ctx.json({
|
|
||||||
data: {
|
|
||||||
email: 'michoko@michka.fr',
|
|
||||||
firstname: 'michoko',
|
|
||||||
lastname: 'ronronscelestes',
|
|
||||||
preferedLanguage: 'en',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
export const serverNoUsername = setupServer(...handlersNoUsername);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user