Merge pull request #13130 from strapi/fix/authenticated-app-tests

Fix / AuthenticatedApp tests
This commit is contained in:
Julie Plantey 2022-06-20 14:30:14 +02:00 committed by GitHub
commit 1bd821fa2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,7 +32,7 @@ jest.mock('../utils/api', () => ({
fetchStrapiLatestRelease: jest.fn(),
fetchAppInfo: jest.fn(),
fetchCurrentUserPermissions: jest.fn(),
fetchUserRoles: jest.fn(() => [{ code: 'strapi-super-admin' }]),
fetchUserRoles: jest.fn(),
}));
jest.mock('../../PluginsInitializer', () => () => <div>PluginsInitializer</div>);
@ -85,6 +85,10 @@ describe('Admin | components | AuthenticatedApp', () => {
expect(container.firstChild).toMatchInlineSnapshot(`
.c0 {
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
@ -96,10 +100,6 @@ describe('Admin | components | AuthenticatedApp', () => {
-webkit-justify-content: space-around;
-ms-flex-pack: space-around;
justify-content: space-around;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.c2 {
@ -152,16 +152,8 @@ describe('Admin | components | AuthenticatedApp', () => {
expect(fetchStrapiLatestRelease).not.toHaveBeenCalled();
});
it('should call setGuidedTourVisibility when user is super admin', async () => {
const setGuidedTourVisibility = jest.fn();
useGuidedTour.mockImplementation(() => ({ setGuidedTourVisibility }));
render(app);
await waitFor(() => expect(setGuidedTourVisibility).toHaveBeenCalledWith(true));
});
it.only('should not setGuidedTourVisibility when user is not super admin', async () => {
fetchUserRoles.mockImplementation(() => [{ code: 'strapi-editor' }]);
it('should not setGuidedTourVisibility when user is not super admin', async () => {
fetchUserRoles.mockImplementationOnce(() => [{ code: 'strapi-editor' }]);
const setGuidedTourVisibility = jest.fn();
useGuidedTour.mockImplementation(() => ({ setGuidedTourVisibility }));
@ -169,4 +161,13 @@ describe('Admin | components | AuthenticatedApp', () => {
await waitFor(() => expect(setGuidedTourVisibility).not.toHaveBeenCalled());
});
it('should call setGuidedTourVisibility when user is super admin', async () => {
fetchUserRoles.mockImplementationOnce(() => [{ code: 'strapi-super-admin' }]);
const setGuidedTourVisibility = jest.fn();
useGuidedTour.mockImplementation(() => ({ setGuidedTourVisibility }));
render(app);
await waitFor(() => expect(setGuidedTourVisibility).toHaveBeenCalledWith(true));
});
});