Improve test coverage (#6244)
This commit is contained in:
@ -0,0 +1,84 @@
|
||||
import { getOperationName } from '@apollo/client/utilities';
|
||||
import { Meta, StoryObj } from '@storybook/react';
|
||||
import { fireEvent, within } from '@storybook/test';
|
||||
import { HttpResponse, graphql } from 'msw';
|
||||
|
||||
import { AppPath } from '@/types/AppPath';
|
||||
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
|
||||
import { GET_WORKSPACE_FROM_INVITE_HASH } from '@/workspace/graphql/queries/getWorkspaceFromInviteHash';
|
||||
import {
|
||||
PageDecorator,
|
||||
PageDecoratorArgs,
|
||||
} from '~/testing/decorators/PageDecorator';
|
||||
import { graphqlMocks } from '~/testing/graphqlMocks';
|
||||
|
||||
import { Invite } from '../Invite';
|
||||
|
||||
const meta: Meta<PageDecoratorArgs> = {
|
||||
title: 'Pages/Auth/Invite',
|
||||
component: Invite,
|
||||
decorators: [PageDecorator],
|
||||
args: {
|
||||
routePath: AppPath.Invite,
|
||||
routeParams: { ':workspaceInviteHash': 'my-hash' },
|
||||
},
|
||||
parameters: {
|
||||
msw: {
|
||||
handlers: [
|
||||
graphql.query(
|
||||
getOperationName(GET_WORKSPACE_FROM_INVITE_HASH) ?? '',
|
||||
() => {
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
findWorkspaceFromInviteHash: {
|
||||
__typename: 'Workspace',
|
||||
id: '20202020-91f0-46d0-acab-cb5afef3cc3b',
|
||||
displayName: 'Twenty dev',
|
||||
logo: null,
|
||||
allowImpersonation: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
),
|
||||
graphql.query(getOperationName(GET_CURRENT_USER) ?? '', () => {
|
||||
return HttpResponse.json({
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
message: 'Unauthorized',
|
||||
extensions: {
|
||||
code: 'UNAUTHENTICATED',
|
||||
response: {
|
||||
statusCode: 401,
|
||||
message: 'Unauthorized',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}),
|
||||
graphqlMocks.handlers,
|
||||
],
|
||||
},
|
||||
cookie: '',
|
||||
},
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
export type Story = StoryObj<typeof Invite>;
|
||||
|
||||
export const Default: Story = {
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
await canvas.findByText('Join Twenty dev team');
|
||||
|
||||
const continueWithEmailButton = await canvas.findByText(
|
||||
'Continue With Email',
|
||||
);
|
||||
|
||||
await fireEvent.click(continueWithEmailButton);
|
||||
},
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
import { Meta, StoryObj } from '@storybook/react';
|
||||
import { within } from '@storybook/test';
|
||||
import { graphql, HttpResponse } from 'msw';
|
||||
import { userEvent, within } from '@storybook/test';
|
||||
import { HttpResponse, graphql } from 'msw';
|
||||
|
||||
import { SettingsDevelopersApiKeyDetail } from '~/pages/settings/developers/api-keys/SettingsDevelopersApiKeyDetail';
|
||||
import {
|
||||
@ -8,6 +8,7 @@ import {
|
||||
PageDecoratorArgs,
|
||||
} from '~/testing/decorators/PageDecorator';
|
||||
import { graphqlMocks } from '~/testing/graphqlMocks';
|
||||
import { sleep } from '~/utils/sleep';
|
||||
|
||||
const meta: Meta<PageDecoratorArgs> = {
|
||||
title: 'Pages/Settings/Developers/ApiKeys/SettingsDevelopersApiKeyDetail',
|
||||
@ -50,6 +51,56 @@ export const Default: Story = {
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await canvas.findByText('Settings');
|
||||
await canvas.findByText('Regenerate an Api key');
|
||||
await canvas.findByText('sfsfdsf API Key');
|
||||
},
|
||||
};
|
||||
|
||||
export const RegenerateApiKey: Story = {
|
||||
play: async ({ canvasElement, step }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await canvas.findByText('Settings');
|
||||
|
||||
await userEvent.click(canvas.getByText('Regenerate Key'));
|
||||
|
||||
await canvas.findByText('Cancel');
|
||||
const confirmationInput = await canvas.findByPlaceholderText('yes');
|
||||
await userEvent.click(confirmationInput);
|
||||
await userEvent.keyboard('y');
|
||||
await userEvent.keyboard('e');
|
||||
await userEvent.keyboard('s');
|
||||
|
||||
const confirmButton = await canvas.findByTestId(
|
||||
'confirmation-modal-confirm-button',
|
||||
);
|
||||
|
||||
await step('Click on confirm button', async () => {
|
||||
await sleep(1000);
|
||||
await userEvent.click(confirmButton);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export const DeleteApiKey: Story = {
|
||||
play: async ({ canvasElement, step }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await canvas.findByText('Settings');
|
||||
|
||||
await userEvent.click(canvas.getByText('Delete'));
|
||||
|
||||
await canvas.findByText('Cancel');
|
||||
const confirmationInput = await canvas.findByPlaceholderText('yes');
|
||||
await userEvent.click(confirmationInput);
|
||||
await userEvent.keyboard('y');
|
||||
await userEvent.keyboard('e');
|
||||
await userEvent.keyboard('s');
|
||||
|
||||
const confirmButton = await canvas.findByTestId(
|
||||
'confirmation-modal-confirm-button',
|
||||
);
|
||||
|
||||
await step('Click on confirm button', async () => {
|
||||
await sleep(1000);
|
||||
await userEvent.click(confirmButton);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import styled from '@emotion/styled';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { DateTime } from 'luxon';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { H2Title, IconRepeat, IconSettings, IconTrash } from 'twenty-ui';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user