diff --git a/web/src/components/CommentsCell/CommentsCell.mock.ts b/web/src/components/CommentsCell/CommentsCell.mock.ts new file mode 100644 index 000000000..45c124ea5 --- /dev/null +++ b/web/src/components/CommentsCell/CommentsCell.mock.ts @@ -0,0 +1,4 @@ +// Define your own mock data here: +export const standard = (/* vars, { ctx, req } */) => ({ + comments: [{ id: 42 }, { id: 43 }, { id: 44 }], +}) diff --git a/web/src/components/CommentsCell/CommentsCell.stories.tsx b/web/src/components/CommentsCell/CommentsCell.stories.tsx new file mode 100644 index 000000000..01ef259ea --- /dev/null +++ b/web/src/components/CommentsCell/CommentsCell.stories.tsx @@ -0,0 +1,22 @@ +import type { ComponentStory } from '@storybook/react' + +import { Loading, Empty, Failure, Success } from './CommentsCell' +import { standard } from './CommentsCell.mock' + +export const loading = () => { + return Loading ? : <> +} + +export const empty = () => { + return Empty ? : <> +} + +export const failure: ComponentStory = (args) => { + return Failure ? : <> +} + +export const success: ComponentStory = (args) => { + return Success ? : <> +} + +export default { title: 'Cells/CommentsCell' } diff --git a/web/src/components/CommentsCell/CommentsCell.test.tsx b/web/src/components/CommentsCell/CommentsCell.test.tsx new file mode 100644 index 000000000..80b687dc0 --- /dev/null +++ b/web/src/components/CommentsCell/CommentsCell.test.tsx @@ -0,0 +1,41 @@ +import { render } from '@redwoodjs/testing/web' +import { Loading, Empty, Failure, Success } from './CommentsCell' +import { standard } from './CommentsCell.mock' + +// Generated boilerplate tests do not account for all circumstances +// and can fail without adjustments, e.g. Float and DateTime types. +// Please refer to the RedwoodJS Testing Docs: +// https://redwoodjs.com/docs/testing#testing-cells +// https://redwoodjs.com/docs/testing#jest-expect-type-considerations + +describe('CommentsCell', () => { + it('renders Loading successfully', () => { + expect(() => { + render() + }).not.toThrow() + }) + + it('renders Empty successfully', async () => { + expect(() => { + render() + }).not.toThrow() + }) + + it('renders Failure successfully', async () => { + expect(() => { + render() + }).not.toThrow() + }) + + // When you're ready to test the actual output of your component render + // you could test that, for example, certain text is present: + // + // 1. import { screen } from '@redwoodjs/testing/web' + // 2. Add test: expect(screen.getByText('Hello, world')).toBeInTheDocument() + + it('renders Success successfully', async () => { + expect(() => { + render() + }).not.toThrow() + }) +}) diff --git a/web/src/components/CommentsCell/CommentsCell.tsx b/web/src/components/CommentsCell/CommentsCell.tsx new file mode 100644 index 000000000..4a77d9ed8 --- /dev/null +++ b/web/src/components/CommentsCell/CommentsCell.tsx @@ -0,0 +1,29 @@ +import type { CommentsQuery } from 'types/graphql' +import type { CellSuccessProps, CellFailureProps } from '@redwoodjs/web' + + +export const QUERY = gql` + query CommentsQuery { + comments { + id + } + } +` + +export const Loading = () =>
Loading...
+ +export const Empty = () =>
Empty
+ +export const Failure = ({ error }: CellFailureProps) => ( +
Error: {error?.message}
+) + +export const Success = ({ comments }: CellSuccessProps) => { + return ( +
    + {comments.map((item) => { + return
  • {JSON.stringify(item)}
  • + })} +
+ ) +}