From 3856a83fa4a6095ba0f4c532be083ea8f0a9d0e7 Mon Sep 17 00:00:00 2001 From: Tiago Behenck Date: Tue, 21 Jun 2022 20:15:59 -0300 Subject: [PATCH] create a user with mutation and connect to the form --- .../FormSignIn/__snapshots__/test.tsx.snap | 8 +- .../FormSignUp/__snapshots__/test.tsx.snap | 15 ++- src/components/FormSignUp/index.tsx | 119 ++++++++++++------ src/components/FormSignUp/test.tsx | 13 +- .../TextField/__snapshots__/test.tsx.snap | 6 + src/components/TextField/index.tsx | 6 +- src/components/TextField/test.tsx | 18 +-- src/graphql/generated/MutationRegister.ts | 23 ++++ src/graphql/generated/globalTypes.ts | 6 + src/graphql/mutations/register.ts | 9 ++ 10 files changed, 165 insertions(+), 58 deletions(-) create mode 100644 src/graphql/generated/MutationRegister.ts create mode 100644 src/graphql/mutations/register.ts diff --git a/src/components/FormSignIn/__snapshots__/test.tsx.snap b/src/components/FormSignIn/__snapshots__/test.tsx.snap index 37d2056..e622cc7 100644 --- a/src/components/FormSignIn/__snapshots__/test.tsx.snap +++ b/src/components/FormSignIn/__snapshots__/test.tsx.snap @@ -51,6 +51,12 @@ exports[` should render the form 1`] = ` width: 100%; } +.c5:-webkit-autofill { + -webkit-box-shadow: 0 0 0 2.4rem #EAEAEA inset; + -webkit-filter: none; + filter: none; +} + .c8 { display: -webkit-inline-box; display: -webkit-inline-flex; @@ -234,4 +240,4 @@ exports[` should render the form 1`] = ` -` +`; diff --git a/src/components/FormSignUp/__snapshots__/test.tsx.snap b/src/components/FormSignUp/__snapshots__/test.tsx.snap index ad57df7..0324991 100644 --- a/src/components/FormSignUp/__snapshots__/test.tsx.snap +++ b/src/components/FormSignUp/__snapshots__/test.tsx.snap @@ -51,6 +51,12 @@ exports[` should render the form 1`] = ` width: 100%; } +.c5:-webkit-autofill { + -webkit-box-shadow: 0 0 0 2.4rem #EAEAEA inset; + -webkit-filter: none; + filter: none; +} + .c7 { display: -webkit-inline-box; display: -webkit-inline-flex; @@ -142,9 +148,9 @@ exports[` should render the form 1`] = ` @@ -270,6 +276,7 @@ exports[` should render the form 1`] = ` -const FormSignUp = () => ( - - - } - /> - } - /> - } - /> - } - /> - - - - - Already have an account?{' '} - - Sign in - - - - -) + + Already have an account?{' '} + + Sign in + + + + + ) +} export default FormSignUp diff --git a/src/components/FormSignUp/test.tsx b/src/components/FormSignUp/test.tsx index 83c02b1..9a68bd0 100644 --- a/src/components/FormSignUp/test.tsx +++ b/src/components/FormSignUp/test.tsx @@ -1,10 +1,15 @@ +import { MockedProvider } from '@apollo/client/testing' import { render, screen } from 'utils/test-utils' import FormSignUp from '.' describe('', () => { it('should render the form', () => { - const { container } = render() + const { container } = render( + + + + ) expect(screen.getByPlaceholderText(/name/i)).toBeInTheDocument() expect(screen.getByPlaceholderText(/email/i)).toBeInTheDocument() @@ -18,7 +23,11 @@ describe('', () => { }) it('should render text and link to sign in', () => { - render() + render( + + + + ) expect(screen.getByRole('link', { name: /sign in/i })).toBeInTheDocument() expect(screen.getByText(/already have an account\?/i)).toBeInTheDocument() diff --git a/src/components/TextField/__snapshots__/test.tsx.snap b/src/components/TextField/__snapshots__/test.tsx.snap index 72d77ef..320dace 100644 --- a/src/components/TextField/__snapshots__/test.tsx.snap +++ b/src/components/TextField/__snapshots__/test.tsx.snap @@ -66,6 +66,12 @@ exports[` should render with error 1`] = ` width: 100%; } +.c8:-webkit-autofill { + -webkit-box-shadow: 0 0 0 2.4rem #EAEAEA inset; + -webkit-filter: none; + filter: none; +} + .c9 { color: #FF6347; font-size: 1.2rem; diff --git a/src/components/TextField/index.tsx b/src/components/TextField/index.tsx index 9ede4b9..9af04a2 100644 --- a/src/components/TextField/index.tsx +++ b/src/components/TextField/index.tsx @@ -3,7 +3,7 @@ import React, { useState, InputHTMLAttributes } from 'react' import * as S from './styles' export type TextFieldProps = { - onInput?: (value: string) => void + onInputChange?: (value: string) => void label?: string initialValue?: string icon?: React.ReactNode @@ -13,7 +13,7 @@ export type TextFieldProps = { } & InputHTMLAttributes const TextField = ({ - onInput, + onInputChange, label, name, initialValue = '', @@ -29,7 +29,7 @@ const TextField = ({ const newValue = e.currentTarget.value setValue(newValue) - !!onInput && onInput(newValue) + !!onInputChange && onInputChange(newValue) } return ( diff --git a/src/components/TextField/test.tsx b/src/components/TextField/test.tsx index fdb7d5c..a52405d 100644 --- a/src/components/TextField/test.tsx +++ b/src/components/TextField/test.tsx @@ -19,9 +19,13 @@ describe('', () => { }) it('Changes its value when typing', async () => { - const onInput = jest.fn() + const onInputChange = jest.fn() render( - + ) const input = screen.getByRole('textbox') @@ -30,16 +34,16 @@ describe('', () => { await waitFor(() => { expect(input).toHaveValue(text) - expect(onInput).toHaveBeenCalledTimes(text.length) + expect(onInputChange).toHaveBeenCalledTimes(text.length) }) - expect(onInput).toHaveBeenCalledWith(text) + expect(onInputChange).toHaveBeenCalledWith(text) }) it('Does not changes its value when disabled', async () => { - const onInput = jest.fn() + const onInputChange = jest.fn() render( ', () => { await waitFor(() => { expect(input).not.toHaveValue(text) }) - expect(onInput).not.toHaveBeenCalled() + expect(onInputChange).not.toHaveBeenCalled() }) it('Is accessible by tab', () => { diff --git a/src/graphql/generated/MutationRegister.ts b/src/graphql/generated/MutationRegister.ts new file mode 100644 index 0000000..a353235 --- /dev/null +++ b/src/graphql/generated/MutationRegister.ts @@ -0,0 +1,23 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +import { UsersPermissionsRegisterInput } from "./globalTypes"; + +// ==================================================== +// GraphQL mutation operation: MutationRegister +// ==================================================== + +export interface MutationRegister_register { + __typename: "UsersPermissionsLoginPayload"; + jwt: string | null; +} + +export interface MutationRegister { + register: MutationRegister_register; +} + +export interface MutationRegisterVariables { + input: UsersPermissionsRegisterInput; +} diff --git a/src/graphql/generated/globalTypes.ts b/src/graphql/generated/globalTypes.ts index adbcf1c..e7d6ebe 100644 --- a/src/graphql/generated/globalTypes.ts +++ b/src/graphql/generated/globalTypes.ts @@ -31,6 +31,12 @@ export enum ENUM_GAME_RATING { BR18 = "BR18", } +export interface UsersPermissionsRegisterInput { + username: string; + email: string; + password: string; +} + //============================================================== // END Enums and Input Objects //============================================================== diff --git a/src/graphql/mutations/register.ts b/src/graphql/mutations/register.ts new file mode 100644 index 0000000..0e2fc59 --- /dev/null +++ b/src/graphql/mutations/register.ts @@ -0,0 +1,9 @@ +import { gql } from '@apollo/client' + +export const MUTATION_REGISTER = gql` + mutation MutationRegister($input: UsersPermissionsRegisterInput!) { + register(input: $input) { + jwt + } + } +`