From f863c79ac86c81137aafaee37593924811578306 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Wed, 14 Feb 2024 11:03:49 +0100 Subject: [PATCH 1/2] RSC: test-project EmptyUser --- .../api/db/dev.db | Bin 24576 -> 32768 bytes .../20240212134007_empty_user/migration.sql | 9 ++ .../api/db/schema.prisma | 6 ++ .../api/package.json | 4 +- .../api/src/graphql/emptyUsers.sdl.ts | 29 ++++++ .../emptyUsers/emptyUsers.scenarios.ts | 11 ++ .../services/emptyUsers/emptyUsers.test.ts | 59 +++++++++++ .../api/src/services/emptyUsers/emptyUsers.ts | 39 +++++++ .../package.json | 4 +- .../web/package.json | 8 +- .../web/src/Routes.tsx | 8 ++ .../EditEmptyUserCell/EditEmptyUserCell.tsx | 85 +++++++++++++++ .../EmptyUser/EmptyUser/EmptyUser.tsx | 90 ++++++++++++++++ .../EmptyUser/EmptyUserCell/EmptyUserCell.tsx | 41 ++++++++ .../EmptyUser/EmptyUserForm/EmptyUserForm.tsx | 82 +++++++++++++++ .../EmptyUser/EmptyUsers/EmptyUsers.tsx | 98 ++++++++++++++++++ .../EmptyUsersCell/EmptyUsersCell.tsx | 48 +++++++++ .../EmptyUser/NewEmptyUser/NewEmptyUser.tsx | 57 ++++++++++ .../web/src/entries.ts | 4 + .../EditEmptyUserPage/EditEmptyUserPage.tsx | 11 ++ .../EmptyUser/EmptyUserPage/EmptyUserPage.tsx | 11 ++ .../EmptyUsersPage/EmptyUsersPage.tsx | 7 ++ .../NewEmptyUserPage/NewEmptyUserPage.tsx | 7 ++ 23 files changed, 710 insertions(+), 8 deletions(-) create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/api/db/migrations/20240212134007_empty_user/migration.sql create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/api/src/graphql/emptyUsers.sdl.ts create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.scenarios.ts create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.test.ts create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.ts create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EditEmptyUserCell/EditEmptyUserCell.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUser/EmptyUser.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUserCell/EmptyUserCell.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUserForm/EmptyUserForm.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUsers/EmptyUsers.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUsersCell/EmptyUsersCell.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/NewEmptyUser/NewEmptyUser.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EditEmptyUserPage/EditEmptyUserPage.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EmptyUserPage/EmptyUserPage.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EmptyUsersPage/EmptyUsersPage.tsx create mode 100644 __fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/NewEmptyUserPage/NewEmptyUserPage.tsx diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/api/db/dev.db b/__fixtures__/test-project-rsc-external-packages-and-cells/api/db/dev.db index a6912d6c19c2da7d2963ffa8c1c8fd6dc36b3246..bcc8cda86ca87674025a293a7fdba41862d73103 100644 GIT binary patch delta 503 zcmZoTz}V2hG(lRBi-CcG1BhXOb)t^3G#7(j+ACiE9}Mi=NesN#_&4(!@jT$k;XcQm zw6XC8SA7;cySTADVbFWoU6~QG9A{VrEW!c4{SDh{HL^)iK0XA=J+^ zFw|AS)6c~KlcbxI!CwS?w7ZSUFA8EYeJp zOiXl>EfP(2O$^dZbQ6=4lXVSEjZ=+{QY}nOO^glFQY;e_4UUY4TxcYd7_T7I6H%0+ACiE9}KKKISjnl_&4(!@jT$k*(@mV yjeBzr&kSZZM*ac@{({Yd3Tgb43*@H&`8OE&Z)_HHILFVd&Kx?qMqYK1fdK$vC>XH- diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/api/db/migrations/20240212134007_empty_user/migration.sql b/__fixtures__/test-project-rsc-external-packages-and-cells/api/db/migrations/20240212134007_empty_user/migration.sql new file mode 100644 index 000000000000..3c29dc91d808 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/api/db/migrations/20240212134007_empty_user/migration.sql @@ -0,0 +1,9 @@ +-- CreateTable +CREATE TABLE "EmptyUser" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "email" TEXT NOT NULL, + "name" TEXT +); + +-- CreateIndex +CREATE UNIQUE INDEX "EmptyUser_email_key" ON "EmptyUser"("email"); diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/api/db/schema.prisma b/__fixtures__/test-project-rsc-external-packages-and-cells/api/db/schema.prisma index 8c8666606f09..e82dee06da4a 100644 --- a/__fixtures__/test-project-rsc-external-packages-and-cells/api/db/schema.prisma +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/api/db/schema.prisma @@ -22,3 +22,9 @@ model UserExample { email String @unique name String? } + +model EmptyUser { + id Int @id @default(autoincrement()) + email String @unique + name String? +} diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/api/package.json b/__fixtures__/test-project-rsc-external-packages-and-cells/api/package.json index 5b6cd9a185f7..fa2cdc33e721 100644 --- a/__fixtures__/test-project-rsc-external-packages-and-cells/api/package.json +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/api/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": true, "dependencies": { - "@redwoodjs/api": "7.0.0-canary.983", - "@redwoodjs/graphql-server": "7.0.0-canary.983" + "@redwoodjs/api": "7.0.0-canary.993", + "@redwoodjs/graphql-server": "7.0.0-canary.993" } } diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/graphql/emptyUsers.sdl.ts b/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/graphql/emptyUsers.sdl.ts new file mode 100644 index 000000000000..14e3879255b1 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/graphql/emptyUsers.sdl.ts @@ -0,0 +1,29 @@ +export const schema = gql` + type EmptyUser { + id: Int! + email: String! + name: String + } + + type Query { + emptyUsers: [EmptyUser!]! @requireAuth + emptyUser(id: Int!): EmptyUser @requireAuth + } + + input CreateEmptyUserInput { + email: String! + name: String + } + + input UpdateEmptyUserInput { + email: String + name: String + } + + type Mutation { + createEmptyUser(input: CreateEmptyUserInput!): EmptyUser! @requireAuth + updateEmptyUser(id: Int!, input: UpdateEmptyUserInput!): EmptyUser! + @requireAuth + deleteEmptyUser(id: Int!): EmptyUser! @requireAuth + } +` diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.scenarios.ts b/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.scenarios.ts new file mode 100644 index 000000000000..f0edd8a561e8 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.scenarios.ts @@ -0,0 +1,11 @@ +import type { Prisma, EmptyUser } from '@prisma/client' +import type { ScenarioData } from '@redwoodjs/testing/api' + +export const standard = defineScenario({ + emptyUser: { + one: { data: { email: 'String5770021' } }, + two: { data: { email: 'String5278315' } }, + }, +}) + +export type StandardScenario = ScenarioData diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.test.ts b/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.test.ts new file mode 100644 index 000000000000..2a7c46b22084 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.test.ts @@ -0,0 +1,59 @@ +import type { EmptyUser } from '@prisma/client' + +import { + emptyUsers, + emptyUser, + createEmptyUser, + updateEmptyUser, + deleteEmptyUser, +} from './emptyUsers' +import type { StandardScenario } from './emptyUsers.scenarios' + +// Generated boilerplate tests do not account for all circumstances +// and can fail without adjustments, e.g. Float. +// Please refer to the RedwoodJS Testing Docs: +// https://redwoodjs.com/docs/testing#testing-services +// https://redwoodjs.com/docs/testing#jest-expect-type-considerations + +describe('emptyUsers', () => { + scenario('returns all emptyUsers', async (scenario: StandardScenario) => { + const result = await emptyUsers() + + expect(result.length).toEqual(Object.keys(scenario.emptyUser).length) + }) + + scenario('returns a single emptyUser', async (scenario: StandardScenario) => { + const result = await emptyUser({ id: scenario.emptyUser.one.id }) + + expect(result).toEqual(scenario.emptyUser.one) + }) + + scenario('creates a emptyUser', async () => { + const result = await createEmptyUser({ + input: { email: 'String8450568' }, + }) + + expect(result.email).toEqual('String8450568') + }) + + scenario('updates a emptyUser', async (scenario: StandardScenario) => { + const original = (await emptyUser({ + id: scenario.emptyUser.one.id, + })) as EmptyUser + const result = await updateEmptyUser({ + id: original.id, + input: { email: 'String82168002' }, + }) + + expect(result.email).toEqual('String82168002') + }) + + scenario('deletes a emptyUser', async (scenario: StandardScenario) => { + const original = (await deleteEmptyUser({ + id: scenario.emptyUser.one.id, + })) as EmptyUser + const result = await emptyUser({ id: original.id }) + + expect(result).toEqual(null) + }) +}) diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.ts b/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.ts new file mode 100644 index 000000000000..382f3586e71f --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/api/src/services/emptyUsers/emptyUsers.ts @@ -0,0 +1,39 @@ +import type { QueryResolvers, MutationResolvers } from 'types/graphql' + +import { db } from 'src/lib/db' + +export const emptyUsers: QueryResolvers['emptyUsers'] = () => { + return db.emptyUser.findMany() +} + +export const emptyUser: QueryResolvers['emptyUser'] = ({ id }) => { + return db.emptyUser.findUnique({ + where: { id }, + }) +} + +export const createEmptyUser: MutationResolvers['createEmptyUser'] = ({ + input, +}) => { + return db.emptyUser.create({ + data: input, + }) +} + +export const updateEmptyUser: MutationResolvers['updateEmptyUser'] = ({ + id, + input, +}) => { + return db.emptyUser.update({ + data: input, + where: { id }, + }) +} + +export const deleteEmptyUser: MutationResolvers['deleteEmptyUser'] = ({ + id, +}) => { + return db.emptyUser.delete({ + where: { id }, + }) +} diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/package.json b/__fixtures__/test-project-rsc-external-packages-and-cells/package.json index fd5b86b8a24b..69d912133b5c 100644 --- a/__fixtures__/test-project-rsc-external-packages-and-cells/package.json +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/package.json @@ -7,8 +7,8 @@ ] }, "devDependencies": { - "@redwoodjs/core": "7.0.0-canary.983", - "@redwoodjs/project-config": "7.0.0-canary.983" + "@redwoodjs/core": "7.0.0-canary.993", + "@redwoodjs/project-config": "7.0.0-canary.993" }, "eslintConfig": { "extends": "@redwoodjs/eslint-config", diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/package.json b/__fixtures__/test-project-rsc-external-packages-and-cells/web/package.json index 7fa222698074..1bdede320657 100644 --- a/__fixtures__/test-project-rsc-external-packages-and-cells/web/package.json +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/package.json @@ -12,9 +12,9 @@ }, "dependencies": { "@apollo/experimental-nextjs-app-support": "0.0.0-commit-b8a73fe", - "@redwoodjs/forms": "7.0.0-canary.983", - "@redwoodjs/router": "7.0.0-canary.983", - "@redwoodjs/web": "7.0.0-canary.983", + "@redwoodjs/forms": "7.0.0-canary.993", + "@redwoodjs/router": "7.0.0-canary.993", + "@redwoodjs/web": "7.0.0-canary.993", "@tobbe.dev/rsc-test": "0.0.3", "client-only": "0.0.1", "react": "0.0.0-experimental-e5205658f-20230913", @@ -22,7 +22,7 @@ "server-only": "0.0.1" }, "devDependencies": { - "@redwoodjs/vite": "7.0.0-canary.983", + "@redwoodjs/vite": "7.0.0-canary.993", "@types/react": "^18.2.55", "@types/react-dom": "^18.2.19" } diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/Routes.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/Routes.tsx index 19e058bd2eec..fe3db4769408 100644 --- a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/Routes.tsx +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/Routes.tsx @@ -18,10 +18,18 @@ const AboutPage = serve('AboutPage') const HomePage = serve('HomePage') const UserExampleUserExamplesPage = serve('UserExampleUserExamplesPage') const UserExampleNewUserExamplePage = serve('UserExampleNewUserExamplePage') +const EmptyUserEmptyUsersPage = serve('EmptyUserEmptyUsersPage') +const EmptyUserNewEmptyUserPage = serve('EmptyUserNewEmptyUserPage') const Routes = () => { return ( + + + {/* + */} + + {/* diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EditEmptyUserCell/EditEmptyUserCell.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EditEmptyUserCell/EditEmptyUserCell.tsx new file mode 100644 index 000000000000..bc63812f849d --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EditEmptyUserCell/EditEmptyUserCell.tsx @@ -0,0 +1,85 @@ +import type { + EditEmptyUserById, + UpdateEmptyUserInput, + UpdateEmptyUserMutationVariables, +} from 'types/graphql' + +import { navigate, routes } from '@redwoodjs/router' +import type { + CellSuccessProps, + CellFailureProps, + TypedDocumentNode, +} from '@redwoodjs/web' +import { useMutation } from '@redwoodjs/web' +import { toast } from '@redwoodjs/web/toast' + +import EmptyUserForm from 'src/components/EmptyUser/EmptyUserForm' + +export const QUERY: TypedDocumentNode = gql` + query EditEmptyUserById($id: Int!) { + emptyUser: emptyUser(id: $id) { + id + email + name + } + } +` + +const UPDATE_EMPTY_USER_MUTATION: TypedDocumentNode< + EditEmptyUserById, + UpdateEmptyUserMutationVariables +> = gql` + mutation UpdateEmptyUserMutation($id: Int!, $input: UpdateEmptyUserInput!) { + updateEmptyUser(id: $id, input: $input) { + id + email + name + } + } +` + +export const Loading = () =>
Loading...
+ +export const Failure = ({ error }: CellFailureProps) => ( +
{error?.message}
+) + +export const Success = ({ emptyUser }: CellSuccessProps) => { + const [updateEmptyUser, { loading, error }] = useMutation( + UPDATE_EMPTY_USER_MUTATION, + { + onCompleted: () => { + toast.success('EmptyUser updated') + navigate(routes.emptyUsers()) + }, + onError: (error) => { + toast.error(error.message) + }, + } + ) + + const onSave = ( + input: UpdateEmptyUserInput, + id: EditEmptyUserById['emptyUser']['id'] + ) => { + updateEmptyUser({ variables: { id, input } }) + } + + return ( +
+
+

+ Edit EmptyUser {emptyUser?.id} +

+
+
+ +
+
+ ) +} diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUser/EmptyUser.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUser/EmptyUser.tsx new file mode 100644 index 000000000000..cdcbe139f90e --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUser/EmptyUser.tsx @@ -0,0 +1,90 @@ +import type { + DeleteEmptyUserMutation, + DeleteEmptyUserMutationVariables, + FindEmptyUserById, +} from 'types/graphql' + +import { Link, routes, navigate } from '@redwoodjs/router' +import { useMutation } from '@redwoodjs/web' +import type { TypedDocumentNode } from '@redwoodjs/web' +import { toast } from '@redwoodjs/web/toast' + +import {} from 'src/lib/formatters' + +const DELETE_EMPTY_USER_MUTATION: TypedDocumentNode< + DeleteEmptyUserMutation, + DeleteEmptyUserMutationVariables +> = gql` + mutation DeleteEmptyUserMutation($id: Int!) { + deleteEmptyUser(id: $id) { + id + } + } +` + +interface Props { + emptyUser: NonNullable +} + +const EmptyUser = ({ emptyUser }: Props) => { + const [deleteEmptyUser] = useMutation(DELETE_EMPTY_USER_MUTATION, { + onCompleted: () => { + toast.success('EmptyUser deleted') + navigate(routes.emptyUsers()) + }, + onError: (error) => { + toast.error(error.message) + }, + }) + + const onDeleteClick = (id: DeleteEmptyUserMutationVariables['id']) => { + if (confirm('Are you sure you want to delete emptyUser ' + id + '?')) { + deleteEmptyUser({ variables: { id } }) + } + } + + return ( + <> +
+
+

+ EmptyUser {emptyUser.id} Detail +

+
+ + + + + + + + + + + + + + + +
Id{emptyUser.id}
Email{emptyUser.email}
Name{emptyUser.name}
+
+ + + ) +} + +export default EmptyUser diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUserCell/EmptyUserCell.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUserCell/EmptyUserCell.tsx new file mode 100644 index 000000000000..fadaeaffc92c --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUserCell/EmptyUserCell.tsx @@ -0,0 +1,41 @@ +import type { + FindEmptyUserById, + FindEmptyUserByIdVariables, +} from 'types/graphql' + +import type { + CellSuccessProps, + CellFailureProps, + TypedDocumentNode, +} from '@redwoodjs/web' + +import EmptyUser from 'src/components/EmptyUser/EmptyUser' + +export const QUERY: TypedDocumentNode< + FindEmptyUserById, + FindEmptyUserByIdVariables +> = gql` + query FindEmptyUserById($id: Int!) { + emptyUser: emptyUser(id: $id) { + id + email + name + } + } +` + +export const Loading = () =>
Loading...
+ +export const Empty = () =>
EmptyUser not found
+ +export const Failure = ({ + error, +}: CellFailureProps) => ( +
{error?.message}
+) + +export const Success = ({ + emptyUser, +}: CellSuccessProps) => { + return +} diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUserForm/EmptyUserForm.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUserForm/EmptyUserForm.tsx new file mode 100644 index 000000000000..400bbb0cfb07 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUserForm/EmptyUserForm.tsx @@ -0,0 +1,82 @@ +import type { EditEmptyUserById, UpdateEmptyUserInput } from 'types/graphql' + +import type { RWGqlError } from '@redwoodjs/forms' +import { + Form, + FormError, + FieldError, + Label, + TextField, + Submit, +} from '@redwoodjs/forms' + +type FormEmptyUser = NonNullable + +interface EmptyUserFormProps { + emptyUser?: EditEmptyUserById['emptyUser'] + onSave: (data: UpdateEmptyUserInput, id?: FormEmptyUser['id']) => void + error: RWGqlError + loading: boolean +} + +const EmptyUserForm = (props: EmptyUserFormProps) => { + const onSubmit = (data: FormEmptyUser) => { + props.onSave(data, props?.emptyUser?.id) + } + + return ( +
+ onSubmit={onSubmit} error={props.error}> + + + + + + + + + + + + + + +
+ + Save + +
+ +
+ ) +} + +export default EmptyUserForm diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUsers/EmptyUsers.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUsers/EmptyUsers.tsx new file mode 100644 index 000000000000..f4a1f120301f --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUsers/EmptyUsers.tsx @@ -0,0 +1,98 @@ +import type { + DeleteEmptyUserMutation, + DeleteEmptyUserMutationVariables, + FindEmptyUsers, +} from 'types/graphql' + +import { Link, routes } from '@redwoodjs/router' +import { useMutation } from '@redwoodjs/web' +import type { TypedDocumentNode } from '@redwoodjs/web' +import { toast } from '@redwoodjs/web/toast' + +import { QUERY } from 'src/components/EmptyUser/EmptyUsersCell' +import { truncate } from 'src/lib/formatters' + +const DELETE_EMPTY_USER_MUTATION: TypedDocumentNode< + DeleteEmptyUserMutation, + DeleteEmptyUserMutationVariables +> = gql` + mutation DeleteEmptyUserMutation($id: Int!) { + deleteEmptyUser(id: $id) { + id + } + } +` + +const EmptyUsersList = ({ emptyUsers }: FindEmptyUsers) => { + const [deleteEmptyUser] = useMutation(DELETE_EMPTY_USER_MUTATION, { + onCompleted: () => { + toast.success('EmptyUser deleted') + }, + onError: (error) => { + toast.error(error.message) + }, + // This refetches the query on the list page. Read more about other ways to + // update the cache over here: + // https://www.apollographql.com/docs/react/data/mutations/#making-all-other-cache-updates + refetchQueries: [{ query: QUERY }], + awaitRefetchQueries: true, + }) + + const onDeleteClick = (id: DeleteEmptyUserMutationVariables['id']) => { + if (confirm('Are you sure you want to delete emptyUser ' + id + '?')) { + deleteEmptyUser({ variables: { id } }) + } + } + + return ( +
+ + + + + + + + + + + {emptyUsers.map((emptyUser) => ( + + + + + + + ))} + +
IdEmailName 
{truncate(emptyUser.id)}{truncate(emptyUser.email)}{truncate(emptyUser.name)} + +
+
+ ) +} + +export default EmptyUsersList diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUsersCell/EmptyUsersCell.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUsersCell/EmptyUsersCell.tsx new file mode 100644 index 000000000000..d0adba58b523 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/EmptyUsersCell/EmptyUsersCell.tsx @@ -0,0 +1,48 @@ +'use client' + +import type { FindEmptyUsers, FindEmptyUsersVariables } from 'types/graphql' + +import { Link, routes } from '@redwoodjs/router' +import type { + CellSuccessProps, + CellFailureProps, + TypedDocumentNode, +} from '@redwoodjs/web' + +import EmptyUsers from 'src/components/EmptyUser/EmptyUsers' + +export const QUERY: TypedDocumentNode< + FindEmptyUsers, + FindEmptyUsersVariables +> = gql` + query FindEmptyUsers { + emptyUsers { + id + email + name + } + } +` + +export const Loading = () =>
Loading...
+ +export const Empty = () => { + return ( +
+ {'No emptyUsers yet. '} + + {'Create one?'} + +
+ ) +} + +export const Failure = ({ error }: CellFailureProps) => ( +
{error?.message}
+) + +export const Success = ({ + emptyUsers, +}: CellSuccessProps) => { + return +} diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/NewEmptyUser/NewEmptyUser.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/NewEmptyUser/NewEmptyUser.tsx new file mode 100644 index 000000000000..50b6532b5b07 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/components/EmptyUser/NewEmptyUser/NewEmptyUser.tsx @@ -0,0 +1,57 @@ +'use client' + +import type { + CreateEmptyUserMutation, + CreateEmptyUserInput, + CreateEmptyUserMutationVariables, +} from 'types/graphql' + +import { navigate, routes } from '@redwoodjs/router' +import { useMutation } from '@redwoodjs/web' +import type { TypedDocumentNode } from '@redwoodjs/web' +import { toast } from '@redwoodjs/web/toast' + +import EmptyUserForm from 'src/components/EmptyUser/EmptyUserForm' + +const CREATE_EMPTY_USER_MUTATION: TypedDocumentNode< + CreateEmptyUserMutation, + CreateEmptyUserMutationVariables +> = gql` + mutation CreateEmptyUserMutation($input: CreateEmptyUserInput!) { + createEmptyUser(input: $input) { + id + } + } +` + +const NewEmptyUser = () => { + const [createEmptyUser, { loading, error }] = useMutation( + CREATE_EMPTY_USER_MUTATION, + { + onCompleted: () => { + toast.success('EmptyUser created') + navigate(routes.emptyUsers()) + }, + onError: (error) => { + toast.error(error.message) + }, + } + ) + + const onSave = (input: CreateEmptyUserInput) => { + createEmptyUser({ variables: { input } }) + } + + return ( +
+
+

New EmptyUser

+
+
+ +
+
+ ) +} + +export default NewEmptyUser diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/entries.ts b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/entries.ts index 7f2e1aaa6923..e8cdc8d0b4f0 100644 --- a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/entries.ts +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/entries.ts @@ -14,6 +14,10 @@ export default defineEntries( return import( './pages/UserExample/NewUserExamplePage/NewUserExamplePage' ) + case 'EmptyUserEmptyUsersPage': + return import('./pages/EmptyUser/EmptyUsersPage/EmptyUsersPage') + case 'EmptyUserNewEmptyUserPage': + return import('./pages/EmptyUser/NewEmptyUserPage/NewEmptyUserPage') default: return null } diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EditEmptyUserPage/EditEmptyUserPage.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EditEmptyUserPage/EditEmptyUserPage.tsx new file mode 100644 index 000000000000..44ea0a5d2705 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EditEmptyUserPage/EditEmptyUserPage.tsx @@ -0,0 +1,11 @@ +import EditEmptyUserCell from 'src/components/EmptyUser/EditEmptyUserCell' + +type EmptyUserPageProps = { + id: number +} + +const EditEmptyUserPage = ({ id }: EmptyUserPageProps) => { + return +} + +export default EditEmptyUserPage diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EmptyUserPage/EmptyUserPage.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EmptyUserPage/EmptyUserPage.tsx new file mode 100644 index 000000000000..580c79a6b640 --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EmptyUserPage/EmptyUserPage.tsx @@ -0,0 +1,11 @@ +import EmptyUserCell from 'src/components/EmptyUser/EmptyUserCell' + +type EmptyUserPageProps = { + id: number +} + +const EmptyUserPage = ({ id }: EmptyUserPageProps) => { + return +} + +export default EmptyUserPage diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EmptyUsersPage/EmptyUsersPage.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EmptyUsersPage/EmptyUsersPage.tsx new file mode 100644 index 000000000000..a1dc7b2dd46b --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/EmptyUsersPage/EmptyUsersPage.tsx @@ -0,0 +1,7 @@ +import EmptyUsersCell from 'src/components/EmptyUser/EmptyUsersCell' + +const EmptyUsersPage = () => { + return +} + +export default EmptyUsersPage diff --git a/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/NewEmptyUserPage/NewEmptyUserPage.tsx b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/NewEmptyUserPage/NewEmptyUserPage.tsx new file mode 100644 index 000000000000..6ad34b95e84a --- /dev/null +++ b/__fixtures__/test-project-rsc-external-packages-and-cells/web/src/pages/EmptyUser/NewEmptyUserPage/NewEmptyUserPage.tsx @@ -0,0 +1,7 @@ +import NewEmptyUser from 'src/components/EmptyUser/NewEmptyUser' + +const NewEmptyUserPage = () => { + return +} + +export default NewEmptyUserPage From abf7752828525b537f9184e59fe1a5b9f9ba810f Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Wed, 14 Feb 2024 11:36:37 +0100 Subject: [PATCH 2/2] Add playwright tests for client cell empty state and navigation --- .../rsc-external-packages-and-cells.spec.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tasks/smoke-tests/rsc-external-packages-and-cells/tests/rsc-external-packages-and-cells.spec.ts b/tasks/smoke-tests/rsc-external-packages-and-cells/tests/rsc-external-packages-and-cells.spec.ts index bb9bde185b8f..82f71d7877f1 100644 --- a/tasks/smoke-tests/rsc-external-packages-and-cells/tests/rsc-external-packages-and-cells.spec.ts +++ b/tasks/smoke-tests/rsc-external-packages-and-cells/tests/rsc-external-packages-and-cells.spec.ts @@ -51,3 +51,37 @@ test('Page with Cell', async ({ page }) => { page.close() }) + +test("'use client' cell Empty state", async ({ page }) => { + await page.goto('/empty-users') + + const h1 = await page.locator('h1').innerHTML() + expect(h1).toMatch(/EmptyUsers - emptyUsers/) + + await expect(page.getByText('No emptyUsers yet.')).toBeVisible() + + const createLink = page.locator('a').getByText('Create one?') + await expect(createLink).toBeVisible() + + page.close() +}) + +test("'use client' cell navigation", async ({ page }) => { + await page.goto('/empty-users') + + await expect(page.getByText('No emptyUsers yet.')).toBeVisible() + + const createLink = page.locator('a').getByText('Create one?') + await expect(createLink).toBeVisible() + + await createLink.click() + + page.waitForURL('/empty-users/new') + + await expect(page.getByText('New EmptyUser')).toBeVisible() + await expect(page.getByText('Email')).toBeVisible() + await expect(page.getByText('Name')).toBeVisible() + await expect(page.getByText('Save')).toBeVisible() + + page.close() +})