-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add storybook tests for User & Metadata loading (#5650)
### Description Add storybook tests for User & Metadata loading ### Refs #5590 ### Demo https://github.com/twentyhq/twenty/assets/140154534/2434fc50-8d95-420b-9f62-6fbdf43ce9e5 Fixes #5590 --------- Co-authored-by: gitstart-twenty <[email protected]> Co-authored-by: v1b3m <[email protected]> Co-authored-by: Thiago Nascimbeni <[email protected]>
- Loading branch information
1 parent
3f9f2c3
commit cd9ac52
Showing
44 changed files
with
175 additions
and
95 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/twenty-front/src/loading/components/__stories__/PrefetchLoading.stories.tsx
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { expect } from '@storybook/jest'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { within } from '@storybook/test'; | ||
|
||
import { RecordIndexPage } from '~/pages/object-record/RecordIndexPage'; | ||
import { | ||
PageDecorator, | ||
PageDecoratorArgs, | ||
} from '~/testing/decorators/PageDecorator'; | ||
import { PrefetchLoadingDecorator } from '~/testing/decorators/PrefetchLoadingDecorator'; | ||
import { graphqlMocks } from '~/testing/graphqlMocks'; | ||
|
||
const meta: Meta<PageDecoratorArgs> = { | ||
title: 'App/Loading/PrefetchLoading', | ||
component: RecordIndexPage, | ||
args: { | ||
routePath: '/objects/:objectNamePlural', | ||
routeParams: { | ||
':objectNamePlural': 'companies', | ||
}, | ||
}, | ||
parameters: { | ||
msw: graphqlMocks, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export type Story = StoryObj<typeof RecordIndexPage>; | ||
|
||
export const Default: Story = { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
decorators: [PrefetchLoadingDecorator, PageDecorator], | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
|
||
await canvas.findByText('Search'); | ||
await canvas.findByText('Settings'); | ||
await canvas.findByText('Tasks'); | ||
|
||
expect(canvas.queryByText('People')).toBeNull(); | ||
expect(canvas.queryByText('Opportunities')).toBeNull(); | ||
expect(canvas.queryByText('Listings')).toBeNull(); | ||
expect(canvas.queryByText('My Customs')).toBeNull(); | ||
}, | ||
}; |
87 changes: 87 additions & 0 deletions
87
packages/twenty-front/src/loading/components/__stories__/UserOrMetadataLoader.stories.tsx
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { getOperationName } from '@apollo/client/utilities'; | ||
import { expect } from '@storybook/jest'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { within } from '@storybook/test'; | ||
import { graphql, HttpResponse } from 'msw'; | ||
|
||
import { GET_CLIENT_CONFIG } from '@/client-config/graphql/queries/getClientConfig'; | ||
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '@/object-metadata/graphql/queries'; | ||
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser'; | ||
import { RecordIndexPage } from '~/pages/object-record/RecordIndexPage'; | ||
import { | ||
PageDecorator, | ||
PageDecoratorArgs, | ||
} from '~/testing/decorators/PageDecorator'; | ||
import { graphqlMocks, metadataGraphql } from '~/testing/graphqlMocks'; | ||
import { mockedClientConfig } from '~/testing/mock-data/config'; | ||
import { mockedUsersData } from '~/testing/mock-data/users'; | ||
|
||
const userMetadataLoaderMocks = { | ||
msw: { | ||
handlers: [ | ||
graphql.query(getOperationName(GET_CURRENT_USER) ?? '', () => { | ||
return HttpResponse.json({ | ||
data: { | ||
currentUser: mockedUsersData[0], | ||
}, | ||
}); | ||
}), | ||
graphql.query(getOperationName(GET_CLIENT_CONFIG) ?? '', () => { | ||
return HttpResponse.json({ | ||
data: { | ||
clientConfig: mockedClientConfig, | ||
}, | ||
}); | ||
}), | ||
metadataGraphql.query( | ||
getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? '', | ||
() => { | ||
return HttpResponse.json({ | ||
data: { | ||
objects: { | ||
// simulate no metadata items | ||
edges: [], | ||
}, | ||
}, | ||
}); | ||
}, | ||
), | ||
], | ||
}, | ||
}; | ||
|
||
const meta: Meta<PageDecoratorArgs> = { | ||
title: 'App/Loading/UserOrMetadataLoader', | ||
component: RecordIndexPage, | ||
args: { | ||
routePath: '/objects/:objectNamePlural', | ||
routeParams: { | ||
':objectNamePlural': 'companies', | ||
}, | ||
}, | ||
parameters: { | ||
msw: graphqlMocks, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export type Story = StoryObj<typeof RecordIndexPage>; | ||
|
||
export const Default: Story = { | ||
parameters: userMetadataLoaderMocks, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
decorators: [PageDecorator], | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
|
||
expect(canvas.queryByText('Search')).toBeNull(); | ||
expect(canvas.queryByText('Settings')).toBeNull(); | ||
expect(canvas.queryByText('Tasks')).toBeNull(); | ||
expect(canvas.queryByText('People')).toBeNull(); | ||
expect(canvas.queryByText('Opportunities')).toBeNull(); | ||
expect(canvas.queryByText('Listings')).toBeNull(); | ||
expect(canvas.queryByText('My Customs')).toBeNull(); | ||
}, | ||
}; |
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
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
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
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
Oops, something went wrong.