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

Use data-cy attribute for add patient spec #6859

Merged
merged 1 commit into from
Oct 31, 2023
Merged
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
5 changes: 4 additions & 1 deletion cypress/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"plugins": ["cypress"],
"extends": ["plugin:cypress/recommended"]
"extends": ["plugin:cypress/recommended"],
"rules": {
"cypress/require-data-selectors": "warn"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ can change this to "error" after we fix the rest of the specs

}
}
97 changes: 44 additions & 53 deletions cypress/e2e/02-add_patient.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,50 @@ describe("Adding a single patient", () => {
setupRunData(currentSpecRunVersionName);
})
});
it("navigates to the add patient form", () => {
cy.visit("/");
cy.get(".usa-nav-container");
cy.get("#desktop-patient-nav-link").click();
cy.get(".prime-container");
cy.get("#add-patient").click();
cy.get("#individual_add-patient").click();
cy.get(".prime-edit-patient").contains("Add new patient");
it("navigates to and fills out add patient form", () => {
cy.visit('/');
cy.get('[data-cy="desktop-patient-nav-link"]').click();
cy.get('[data-cy="add-patients-button"]').click();
cy.get('[data-cy="individual"]').click();
cy.get('[data-cy="add-patient-header"]').contains("Add new patient");
cy.injectSRAxe();
cy.checkAccessibility(); // Patient form
});
it("fills out some of the form fields", () => {
cy.get('input[name="firstName"]').type(patient.firstName);
cy.get('input[name="birthDate"]').type(patient.dobForInput);
cy.get('input[name="number"]').type(patient.phone);
cy.get('input[value="MOBILE"]+label').click();
cy.get('input[name="gender"][value="female"]+label').click();
cy.get('input[name="genderIdentity"][value="female"]+label').click();
cy.get('input[name="street"]').type(patient.address);
cy.get('select[name="state"]').select(patient.state);
cy.get('input[name="zipCode"]').type(patient.zip);
cy.get('select[name="role"]').select("STUDENT");
cy.get(".prime-edit-patient").contains("Student ID");
cy.get('input[name="lookupId"]').type(patient.studentId);
cy.get('input[name="race"][value="other"]+label').click();
cy.get('input[name="ethnicity"][value="refused"]+label').click();
cy.get('input[name="residentCongregateSetting"][value="NO"]+label').click();
cy.get('input[name="employedInHealthcare"][value="NO"]+label').click();
});
it("shows what fields are missing on submit", () => {
cy.get(".prime-save-patient-changes").first().click();

cy.get(".prime-edit-patient").contains("Last name is missing");
cy.get(".prime-edit-patient").contains("Testing facility is missing");
cy.get(".prime-edit-patient").contains("City is missing");
});
it("fills out the remaining fields, submits and checks for the patient", () => {
cy.get('input[name="lastName"]').type(patient.lastName);
cy.get('input[name="city"]').type(patient.city);
cy.get('select[name="facilityId"]').select("All facilities");
cy.get(".prime-save-patient-changes").first().click();
cy.get(
'.modal__container input[name="addressSelect-person"][value="userAddress"]+label',
).click();

cy.checkAccessibility();

cy.get(".modal__container #save-confirmed-address").click();
cy.get(".usa-card__header").contains("Patients");
cy.get(".usa-card__header").contains("Showing");
cy.get("#search-field-small").type(patient.lastName);
cy.get(".prime-container").contains(patient.fullName);

cy.checkAccessibility();
cy.checkAccessibility(); // empty patient form
// fill out form
cy.get('[data-cy="personForm-firstName-input"]').type(patient.firstName);
cy.get('[data-cy="personForm-dob-input"]').type(patient.dobForInput);
cy.get('[data-cy="phone-input-0"]').type(patient.phone);
cy.get('[data-cy="radio-group-option-phoneType-0-MOBILE"]').click();
cy.get('[data-cy="radio-group-option-genderIdentity-female"]').click();
cy.get('[data-cy="radio-group-option-gender-female"]').click();
cy.get('[data-cy="street-input"]').type(patient.address);
cy.get('[data-cy="state-input"]').select(patient.state);
cy.get('[data-cy="zip-input"]').type(patient.zip);
cy.get('[data-cy="personForm-role-input"]').select("STUDENT");
cy.get('[data-cy="add-patient-page"]').contains("Student ID");
cy.get('[data-cy="personForm-lookupId-input"]').type(patient.studentId);
cy.get('[data-cy="radio-group-option-race-other"]').click();
cy.get('[data-cy="radio-group-option-ethnicity-refused"]').click();
cy.get('[data-cy="radio-group-option-residentCongregateSetting-NO"]').click();
cy.get('[data-cy="radio-group-option-employedInHealthcare-NO"]').click();
cy.get('[data-cy="add-patient-save-button"]').eq(0).click();
// check for errors
cy.get('[data-cy="add-patient-page"]').contains("Last name is missing");
cy.get('[data-cy="add-patient-page"]').contains("Testing facility is missing");
cy.get('[data-cy="add-patient-page"]').contains("City is missing");
cy.checkAccessibility(); // patient form with errors
// fill out remaining form
cy.get('[data-cy="personForm-lastName-input"]').type(patient.lastName);
cy.get('[data-cy="city-input"]').type(patient.city);
cy.get('[data-cy="personForm-facility-input"]').select("All facilities");
cy.get('[data-cy="add-patient-save-button"]').eq(0).click();
cy.get('[data-cy="radio-group-option-addressSelect-person-userAddress"]').click();
cy.checkAccessibility(); // address validation modal
cy.get('[data-cy="save-address-confirmation-button"]').click();
// check for newly created patient on Manage Patients page
cy.get('[data-cy="manage-patients-header"]').contains("Patients");
cy.get('[data-cy="manage-patients-header"]').contains("Showing");
cy.get('[data-cy="manage-patients-search-input"]').type(patient.lastName);
cy.get('[data-cy="manage-patients-page"]').contains(patient.fullName);
cy.checkAccessibility(); // manage patients page
});
});
11 changes: 5 additions & 6 deletions cypress/e2e/10-save_and_start_covid_test.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ describe("Save and start covid test", () => {
context("edit patient and save and start test", () => {
it("searches for the patient", () => {
cy.visit("/");
cy.get(".usa-nav-container");
cy.get("#desktop-patient-nav-link").click();
cy.get(".sr-patient-list").should("exist");
cy.get(".sr-patient-list").contains("Loading...").should("not.exist");
cy.get("#search-field-small").type(lastName);
cy.get('[data-cy="desktop-patient-nav-link"]').click();
cy.get('[data-cy="manage-patients-header"]').contains("Patients");
cy.get('[data-cy="manage-patients-header"]').contains("Showing");
cy.get('[data-cy="manage-patients-search-input"]').type(lastName);
cy.wait("@GetPatientsByFacility");
cy.get(".sr-patient-list").contains(patientName).should("exist");
cy.get('[data-cy="manage-patients-page"]').contains(patientName);
});

it("edits the found patient and clicks save and start test ", () => {
Expand Down
6 changes: 3 additions & 3 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const getDobFormat = () => {
// Generate a random patient
export const generatePatient = () => {
const patient = {};
patient.firstName = faker.name.firstName();
patient.lastName = faker.name.lastName();
patient.firstName = faker.person.firstName();
patient.lastName = faker.person.lastName();
patient.fullName = `${patient.lastName}, ${patient.firstName}`;
patient.dob = dayjs(
faker.date.between({ from: "1920-01-01", to: "2002-12-31" }),
Expand All @@ -44,7 +44,7 @@ export const generatePatient = () => {
patient.city = "Definitely not Washington";
patient.state = "DC";
patient.zip = "20503";
patient.studentId = faker.datatype.uuid();
patient.studentId = faker.string.uuid();
return patient;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export const AddressConfirmationModal = <T extends string>({
disabled={addressSuggestionConfig.some(
({ key }) => !selectedAddress[key]
)}
dataCy="save-address-confirmation-button"
>
{t("address.save")}
</Button>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/app/commonComponents/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface Props {
ariaHidden?: boolean;
ariaLabel?: string;
ref?: React.RefObject<HTMLButtonElement> | null;
dataCy?: string;
}

const Button = ({
Expand All @@ -40,6 +41,7 @@ const Button = ({
id,
ariaHidden,
ariaLabel,
dataCy,
}: Props) => (
<button
type={type}
Expand All @@ -56,6 +58,7 @@ const Button = ({
onClick={onClick}
aria-describedby={ariaDescribedBy || undefined}
aria-label={ariaLabel}
data-cy={dataCy}
>
{icon && <FontAwesomeIcon icon={icon} className="margin-right-1" />}
{label || children}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/app/commonComponents/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface Props {
validationStatus?: "error" | "success";
selectClassName?: string;
hintText?: string | React.ReactNode;
dataCy?: string;
registrationProps?: UseFormRegisterReturn<any>;
}

Expand All @@ -50,6 +51,7 @@ const Dropdown: React.FC<Props & SelectProps> = ({
errorMessage,
selectClassName,
hintText,
dataCy,
registrationProps,
...inputProps
}) => {
Expand Down Expand Up @@ -98,6 +100,7 @@ const Dropdown: React.FC<Props & SelectProps> = ({
onChange={onChange}
value={selectedValue || defaultOption || ""}
disabled={disabled}
data-cy={dataCy}
{...inputProps}
{...(validationStatus === "error"
? { "aria-describedby": `error_${id}`, "aria-invalid": true }
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/commonComponents/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const Header: React.FC<{}> = () => {
onClick={() => setMenuVisible(false)}
className={item.className}
id={`${deviceType}-${item.key}`}
data-cy={`${deviceType}-${item.key}`}
>
{item.displayText}
</LinkWithQuery>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/app/commonComponents/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Props<T> {
hintText?: string;
min?: number | string;
max?: number | string;
dataCy?: string;
}

export const Input = <T extends { [key: string]: any }>({
Expand All @@ -36,6 +37,7 @@ export const Input = <T extends { [key: string]: any }>({
hintText,
min,
max,
dataCy,
}: Props<T>): React.ReactElement => {
const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange(field)(e.target.value);
Expand Down Expand Up @@ -66,6 +68,7 @@ export const Input = <T extends { [key: string]: any }>({
min={min}
max={max}
hintText={hintText}
dataCy={dataCy}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/commonComponents/MenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const MenuButton = (props: Props) => (
? `${item.name.split(" ")[0].toLowerCase()}_${props.id}`
: undefined
}
data-cy={item.name}
>
{item.content ?? item.name}
</MenuItem>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/commonComponents/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const RadioGroup = <T extends string>({
<label
className={labelClasses}
htmlFor={uid(c.value)}
data-cy={`radio-group-option-${c.value}`}
data-cy={`radio-group-option-${name}-${c.value}`}
>
{c.label}
{c.labelDescription && (
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/app/commonComponents/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface Props<T> {
selectClassName?: string;
disabled?: boolean;
className?: string;
dataCy?: string;
registrationProps?: UseFormRegisterReturn<any>;
}

Expand All @@ -42,6 +43,7 @@ const Select = <T extends string>({
selectClassName,
disabled,
className,
dataCy,
registrationProps,
}: Props<T>): React.ReactElement => {
const onChangeWrapper = (e: React.ChangeEvent<HTMLSelectElement>) => {
Expand All @@ -64,6 +66,7 @@ const Select = <T extends string>({
selectClassName={selectClassName}
disabled={disabled}
className={className}
dataCy={dataCy}
registrationProps={registrationProps}
/>
);
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/app/commonComponents/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface Props {
labelClassName?: string;
min?: number | string;
max?: number | string;
dataCy?: string;
registrationProps?: UseFormRegisterReturn<any>;
}

Expand Down Expand Up @@ -74,6 +75,7 @@ export const TextInput = ({
labelClassName,
min,
max,
dataCy,
registrationProps,
...inputProps
}: Props & InputProps): React.ReactElement => {
Expand Down Expand Up @@ -129,6 +131,7 @@ export const TextInput = ({
ref={inputRef}
data-format={format}
data-format-message={formatMessage}
data-cy={dataCy}
{...inputProps}
{...(validationStatus === "error"
? { "aria-describedby": `error_${id}`, "aria-invalid": true }
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/patients/AddPatient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ const AddPatient = () => {
label={
loading ? `${t("common.button.saving")}...` : t("common.button.save")
}
dataCy={"add-patient-save-button"}
/>
</>
);
Expand Down Expand Up @@ -344,7 +345,7 @@ const AddPatient = () => {
}

return (
<div className={"prime-edit-patient prime-home"}>
<div className={"prime-edit-patient prime-home"} data-cy="add-patient-page">
<div className={"grid-container margin-bottom-4 maxw-desktop-lg"}>
<DuplicatePatientModal
showModal={
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/patients/Components/AddPatientsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Props {
export const AddPatientHeader = (props: Props) => {
return (
<>
<div className="display-flex flex-justify">
<div className="display-flex flex-justify" data-cy="add-patient-header">
<div>
<div className="display-flex flex-align-center">
<svg
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/patients/Components/FacilitySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Props {
validationStatus: (name: keyof PersonFormData) => "error" | undefined;
errors: { [key: string]: string | undefined };
hidden?: boolean;
dataCy?: string;
}

const ALL_FACILITIES = "~~ALL-FACILITIES~~";
Expand Down Expand Up @@ -47,6 +48,7 @@ const FacilitySelect: React.FC<Props> = (props) => {
options={facilityList}
defaultSelect={true}
required
dataCy={props.dataCy}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ const ManagePhoneNumbers: React.FC<Props> = ({
validateField(idx, "type");
}}
errors={errors[idx] || {}}
dataCy={`phone-input-${idx}`}
/>
{!isPrimary && (
<div className="flex-align-self-end">
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/patients/Components/PersonAddressField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const PersonAddressField: React.FC<PersonAddressFieldProps> = (
field="street"
label={t("patient.form.contact.street1")}
required
dataCy={"street-input"}
/>
</div>
<div className="usa-form">
Expand All @@ -86,6 +87,7 @@ const PersonAddressField: React.FC<PersonAddressFieldProps> = (
field="city"
label={t("patient.form.contact.city")}
required
dataCy={"city-input"}
/>
{view !== PersonFormView.SELF_REGISTRATION && (
<Input
Expand All @@ -111,6 +113,7 @@ const PersonAddressField: React.FC<PersonAddressFieldProps> = (
validationStatus={errors.state ? "error" : undefined}
errorMessage={errors.state}
required
dataCy={"state-input"}
/>
</div>
<div className="mobile-lg:grid-col-6">
Expand All @@ -119,6 +122,7 @@ const PersonAddressField: React.FC<PersonAddressFieldProps> = (
field="zipCode"
label={t("patient.form.contact.zip")}
required
dataCy={"zip-input"}
/>
</div>
</div>
Expand Down
Loading