Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove typescript errors #817

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/run-tests-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ jobs:
run: |
echo "COGNITO_REGION set"
tox -e releasetest
test-app:
test-frontend:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./app
working-directory: ./frontend
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
cache-dependency-path: app/package-lock.json
cache-dependency-path: frontend/package-lock.json
- name: Run npm CI
run: npm ci
- name: Test app
- name: Test frontend
run: npm run test -- --no-color --run
- name: Run E2E tests
uses: cypress-io/github-action@v5
with:
install: false
start: npm run dev
working-directory: ./app
working-directory: ./frontend
wait-on: "http://[::1]:4040/"
4,132 changes: 2,665 additions & 1,467 deletions frontend/package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions frontend/src/features/authentication/SignInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {PasswordField} from './PasswordField';
interface SignInFormProps {
isLoading: boolean;
onSubmit: ({email, password}: SignInRequest) => Promise<void>;
// signInIsLoading: boolean;
getTokenIsLoading?: boolean;
type?: 'coordinator' | 'guest' | 'host';
}

const validationSchema = object({
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/features/authentication/SignUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface SignUpFormProps {
firstName,
lastName,
}: Omit<SignUpRequest, 'role'>) => Promise<void>;
getTokenIsLoading?: boolean;
signUpHostIsLoading?: boolean;
signUpCoordinatorIsLoading?: boolean;
type?: string;
}

export const SignUpForm = ({onSubmit, isLoading}: SignUpFormProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const prepare = () => {
<BrowserRouter>
<SignInForm
onSubmit={onSubmit}
signInIsLoading={false}
isLoading={false}
getTokenIsLoading={false}
/>
</BrowserRouter>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
type: 'coordinator',
getTokenIsLoading: false,
signUpCoordinatorIsLoading: false,
signUpHostIsLoading: false,
isLoading: false,
...initialProps,
};

Expand Down Expand Up @@ -100,11 +100,11 @@
const {submitButton} = prepare({getTokenIsLoading: true});

expect(submitButton).toBeDisabled();
expect(screen.getByRole('progressbar')).toBeInTheDocument();

Check failure on line 103 in frontend/src/features/authentication/__tests__/SignUpForm.test.tsx

View workflow job for this annotation

GitHub Actions / test-frontend

src/features/authentication/__tests__/SignUpForm.test.tsx > <SignUpForm /> > displays loading spinner when token is loading

TestingLibraryElementError: Unable to find an accessible element with the role "progressbar" Here are the accessible roles: textbox: Name "First name": <input aria-invalid="false" autocomplete="username" class="MuiInputBase-input MuiOutlinedInput-input css-1t8l2tu-MuiInputBase-input-MuiOutlinedInput-input" id="firstName" name="firstName" type="text" value="" /> Name "Last name": <input aria-invalid="false" autocomplete="username" class="MuiInputBase-input MuiOutlinedInput-input css-1t8l2tu-MuiInputBase-input-MuiOutlinedInput-input" id="lastName" name="lastName" type="text" value="" /> Name "Email address": <input aria-invalid="false" autocomplete="username" class="MuiInputBase-input MuiOutlinedInput-input css-1t8l2tu-MuiInputBase-input-MuiOutlinedInput-input" id="email" name="email" type="text" value="" /> -------------------------------------------------- button: Name "toggle password visibility": <button aria-label="toggle password visibility" class="MuiButtonBase-root MuiIconButton-root MuiIconButton-edgeEnd MuiIconButton-sizeMedium css-1yq5fb3-MuiButtonBase-root-MuiIconButton-root" tabindex="0" type="button" /> Name "Sign up": <button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeLarge MuiButton-containedSizeLarge MuiButton-colorPrimary MuiButton-disableElevation MuiButton-fullWidth Mui-disabled MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeLarge MuiButton-containedSizeLarge MuiButton-colorPrimary MuiButton-disableElevation MuiButton-fullWidth css-13a105y-MuiButtonBase-root-MuiButton-root" disabled="" tabindex="-1" type="submit" /> -------------------------------------------------- Ignored nodes: comments, script, style <body> <div> <form class="MuiStack-root css-o3b74m-MuiStack-root" > <div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-wb57ya-MuiFormControl-root-MuiTextField-root" > <label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-outlined MuiFormLabel-colorPrimary MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-outlined css-1qvw4ml-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" for="firstName" id="firstName-label" > First name </label> <div class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl css-dy9lmd-MuiInputBase-root-MuiOutlinedInput-root" > <input aria-invalid="false" autocomplete="username" class="MuiInputBase-input MuiOutlinedInput-input css-1t8l2tu-MuiInputBase-input-MuiOutlinedInput-input" id="firstName" name="firstName" type="text" value="" /> <fieldset aria-hidden="true" class="MuiOutlinedInput-notchedOutline css-1d3z3hw-MuiOutlinedInput-notchedOutline" > <legend class="css-yjsfm1" > <span> First name </span> </legend> </fieldset> </div> </div> <div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-wb57ya-MuiFormControl-root-MuiTextField-root" > <label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-outlined MuiFormLabel-colorPrimary MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-outlined css-1qvw4ml-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" for="lastName" id="lastNa
});

it('displays loading spinner when signing up as host', () => {
const {submitButton} = prepare({signUpHostIsLoading: true});
const {submitButton} = prepare({isLoading: true});

expect(submitButton).toBeDisabled();
expect(screen.getByRole('progressbar')).toBeInTheDocument();
Expand All @@ -114,6 +114,6 @@
const {submitButton} = prepare({signUpCoordinatorIsLoading: true});

expect(submitButton).toBeDisabled();
expect(screen.getByRole('progressbar')).toBeInTheDocument();

Check failure on line 117 in frontend/src/features/authentication/__tests__/SignUpForm.test.tsx

View workflow job for this annotation

GitHub Actions / test-frontend

src/features/authentication/__tests__/SignUpForm.test.tsx > <SignUpForm /> > displays loading spinner when signing up as coordinator

TestingLibraryElementError: Unable to find an accessible element with the role "progressbar" Here are the accessible roles: textbox: Name "First name": <input aria-invalid="false" autocomplete="username" class="MuiInputBase-input MuiOutlinedInput-input css-1t8l2tu-MuiInputBase-input-MuiOutlinedInput-input" id="firstName" name="firstName" type="text" value="" /> Name "Last name": <input aria-invalid="false" autocomplete="username" class="MuiInputBase-input MuiOutlinedInput-input css-1t8l2tu-MuiInputBase-input-MuiOutlinedInput-input" id="lastName" name="lastName" type="text" value="" /> Name "Email address": <input aria-invalid="false" autocomplete="username" class="MuiInputBase-input MuiOutlinedInput-input css-1t8l2tu-MuiInputBase-input-MuiOutlinedInput-input" id="email" name="email" type="text" value="" /> -------------------------------------------------- button: Name "toggle password visibility": <button aria-label="toggle password visibility" class="MuiButtonBase-root MuiIconButton-root MuiIconButton-edgeEnd MuiIconButton-sizeMedium css-1yq5fb3-MuiButtonBase-root-MuiIconButton-root" tabindex="0" type="button" /> Name "Sign up": <button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeLarge MuiButton-containedSizeLarge MuiButton-colorPrimary MuiButton-disableElevation MuiButton-fullWidth Mui-disabled MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeLarge MuiButton-containedSizeLarge MuiButton-colorPrimary MuiButton-disableElevation MuiButton-fullWidth css-13a105y-MuiButtonBase-root-MuiButton-root" disabled="" tabindex="-1" type="submit" /> -------------------------------------------------- Ignored nodes: comments, script, style <body> <div> <form class="MuiStack-root css-o3b74m-MuiStack-root" > <div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-wb57ya-MuiFormControl-root-MuiTextField-root" > <label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-outlined MuiFormLabel-colorPrimary MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-outlined css-1qvw4ml-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" for="firstName" id="firstName-label" > First name </label> <div class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl css-dy9lmd-MuiInputBase-root-MuiOutlinedInput-root" > <input aria-invalid="false" autocomplete="username" class="MuiInputBase-input MuiOutlinedInput-input css-1t8l2tu-MuiInputBase-input-MuiOutlinedInput-input" id="firstName" name="firstName" type="text" value="" /> <fieldset aria-hidden="true" class="MuiOutlinedInput-notchedOutline css-1d3z3hw-MuiOutlinedInput-notchedOutline" > <legend class="css-yjsfm1" > <span> First name </span> </legend> </fieldset> </div> </div> <div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-wb57ya-MuiFormControl-root-MuiTextField-root" > <label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-outlined MuiFormLabel-colorPrimary MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-outlined css-1qvw4ml-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" for="lastName" id="lastNa
});
});
15 changes: 8 additions & 7 deletions frontend/src/features/intake-profile/IntakeProfileGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@mui/material';
import {useFormikContext} from 'formik';
import {useOutletContext} from 'react-router-dom';
import {InitialValues} from 'src/pages/intake-profile';
import {InitialValues} from 'src/pages/intake-profile/IntakeProfile';
import {AdditionalGuestsField} from './fields/AdditionaGuestsField';
import {FieldGroup, Fields, Guest, Pet} from 'src/services/profile';
import {AdditionalPetsField} from './fields/AdditionalPetsField';
Expand Down Expand Up @@ -216,20 +216,21 @@ export const RenderFields = ({groupId, field}: RenderFieldProps) => {
);
case 'contact_method':
// eslint-disable-next-line no-case-declarations
const {emailFieldId, phoneFieldId} = field.linkedFields;
const {emailFieldId, phoneFieldId} = field.linkedFields || {};
// eslint-disable-next-line no-case-declarations
let isEmailFilled = false;
// eslint-disable-next-line no-case-declarations
let isPhoneFilled = false;
if (emailFieldId) {
// This isn't best practice and can be replaced with validator library to verify email
isEmailFilled = Boolean(
values[emailFieldId] && /\S+@\S+\.\S+/.test(values[emailFieldId]),
);
const emailValue = values[emailFieldId];
isEmailFilled =
typeof emailValue === 'string' && /\S+@\S+\.\S+/.test(emailValue);
}
// eslint-disable-next-line no-case-declarations
if (phoneFieldId) {
isPhoneFilled = phoneRegExp.test(values[phoneFieldId]);
const phoneValue = values[phoneFieldId];
isPhoneFilled =
typeof phoneValue === 'string' && phoneRegExp.test(phoneValue);
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
FieldArray,
useFormikContext,
} from 'formik';
import {InitialValues} from 'src/pages/intake-profile';
import {InitialValues} from 'src/pages/intake-profile/IntakeProfile';
import {Guest} from '../../../services/profile';
import {DatePickerField} from './DatePickerField';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {Stack, Button, TextField, Typography} from '@mui/material';
import {FormikErrors, FieldArray, useFormikContext} from 'formik';
import {Pet} from '../../../services/profile';
import Autocomplete from '@mui/material/Autocomplete';
import {InitialValues} from 'src/pages/intake-profile';

import {InitialValues} from 'src/pages/intake-profile/IntakeProfile';
interface Values {
pets: Pet[];
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/SystemAdminDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
DashboardDataResponse,
useAdminDeleteUserMutation,
useGetAllDashboardDataMutation,
AdminApiError,
} from '../services/coordinator';
import ChangeCircleRoundedIcon from '@mui/icons-material/ChangeCircleRounded';

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/__tests__/ForgotPasswordCode.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
fireEvent,
userEvent,
} from '../../utils/testing/test-utils';
import {ForgotPasswordCode} from '../ForgotPasswordCode';
import {ForgotPasswordCode} from '../authentication/ForgotPasswordCode';
import {BrowserRouter} from 'react-router-dom';
import {Formik} from 'formik';
import {server} from '../../utils/testing/server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const typeValidations = {
email: string().email('Must be a valid email address'),
yes_no: string(),
dropdown: string(),
// date: date().required('Date is required').typeError('Invalid date'),
date: date().typeError('DOB is not a valid date'),
additional_guests: array().of(
object().shape({
Expand All @@ -37,6 +38,8 @@ export const typeValidations = {
type: string().required('Type of pet is required'),
}),
),
contact_method: string(),
multiple_choice: array().of(string().required('Choice is required')),
};

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand All @@ -53,7 +56,7 @@ const merge = (...schemas) => {
};

const createFieldValidationSchema = ({type, validations}: Fields) => {
if (!typeValidations[type]) {
if (!(type in typeValidations)) {
console.error(
`No schema exists in typeValidations hashmap in IntakeProfile/constants/index.ts for type: ${type}`,
);
Expand Down
33 changes: 25 additions & 8 deletions frontend/src/pages/intake-profile/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {faker} from '@faker-js/faker';
import {array, object, string} from 'yup';

import {InitialValues} from '../IntakeProfile';
import {
FieldGroup,
Expand Down Expand Up @@ -114,7 +115,6 @@ export const typeValidations = {
relationship: string().required('Relationship is required'),
}),
),
// array of strings of the type of pets
pets: array().of(
object().shape({
type: string().required('Type of pet is required'),
Expand All @@ -125,24 +125,41 @@ export const typeValidations = {

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// const merge = (...schemas) => {
// const [first, ...rest] = schemas;

// const merged = rest.reduce(
// (mergedSchemas, schema) => mergedSchemas.concat(schema),
// first,
// );

// return merged;
// };

const merge = (...schemas) => {
const [first, ...rest] = schemas;
const validSchemas = schemas.filter(schema => schema !== undefined);

const merged = rest.reduce(
(mergedSchemas, schema) => mergedSchemas.concat(schema),
first,
);
if (validSchemas.length === 0) {
return [];
}

const [first, ...rest] = validSchemas;

const merged = rest.reduce((mergedSchemas, schema) => {
return mergedSchemas.concat(schema);
}, first);

return merged;
};

const createFieldValidationSchema = ({type, validations}: Fields) => {
if (!typeValidations[type]) {
if (!(type in typeValidations)) {
console.error(
`No schema exists in typeValidations hashmap in IntakeProfile/constants/index.ts for type: ${type}`,
);
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
let schema = typeValidations[type];

if (validations.required) {
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/services/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const fieldTypes = [
'additional_guests',
'pets',
'contact_method',
'multiple_choice',
] as const;

type FieldTypeTuple = typeof fieldTypes;
Expand Down Expand Up @@ -45,8 +46,8 @@ export interface Fields {
required_if?: ReduiredIf;
};
linkedFields?: {
emailFieldId?: string;
phoneFieldId?: string;
emailFieldId: string;
phoneFieldId: string;
};
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default defineConfig(({mode}) => {
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/utils/test/setupTests.ts',
setupFiles: './src/utils/testing/setupTests.ts',
},
};
});
Loading