-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #418 from NYPL/SCC-4389/my-account-2.0-qa
SCC-4389: My Account 2.0 QA round 1 and VQA/a11y round 2
- Loading branch information
Showing
9 changed files
with
227 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,9 @@ describe("email form", () => { | |
fireEvent.click(screen.getByRole("button", { name: /edit/i })) | ||
|
||
await waitFor(() => | ||
expect(screen.getByLabelText("Update email address 2")).toHaveFocus() | ||
expect( | ||
screen.getByLabelText("Update primary email address") | ||
).toHaveFocus() | ||
) | ||
|
||
fireEvent.click(screen.getByRole("button", { name: /cancel/i })) | ||
|
@@ -82,7 +84,7 @@ describe("email form", () => { | |
|
||
await waitFor(() => expect(screen.getAllByRole("textbox")[2]).toHaveFocus()) | ||
|
||
fireEvent.click(screen.getAllByLabelText("Remove email")[1]) | ||
fireEvent.click(screen.getByLabelText("Remove email 2")) | ||
|
||
await waitFor(() => expect(screen.getAllByRole("textbox")[1]).toHaveFocus()) | ||
}) | ||
|
@@ -121,7 +123,7 @@ describe("email form", () => { | |
|
||
fireEvent.click(screen.getByRole("button", { name: /edit/i })) | ||
|
||
fireEvent.click(screen.getByLabelText("Remove email")) | ||
fireEvent.click(screen.getByLabelText("Remove email 2")) | ||
|
||
expect( | ||
screen.queryByDisplayValue("[email protected]") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { render, screen, fireEvent, waitFor } from "@testing-library/react" | ||
import { filteredPickupLocations } from "../../../../__test__/fixtures/processedMyAccountData" | ||
import { PatronDataProvider } from "../../../context/PatronDataContext" | ||
import { processedPatron } from "../../../../__test__/fixtures/processedMyAccountData" | ||
import { | ||
processedPatron, | ||
emptyPatron, | ||
} from "../../../../__test__/fixtures/processedMyAccountData" | ||
import { pickupLocations } from "../../../../__test__/fixtures/rawSierraAccountData" | ||
import SettingsSelectForm from "./SettingsSelectForm" | ||
import type { Patron } from "../../../types/myAccountTypes" | ||
|
@@ -34,33 +37,79 @@ describe("notification preference form", () => { | |
(pref) => pref.code === processedPatron.notificationPreference | ||
)?.name | ||
|
||
const component = ( | ||
<PatronDataProvider | ||
testSpy={accountFetchSpy} | ||
value={{ | ||
patron: processedPatron, | ||
pickupLocations: filteredPickupLocations, | ||
}} | ||
> | ||
<SettingsSelectForm | ||
patronData={processedPatron} | ||
settingsState={mockSettingsState} | ||
pickupLocations={pickupLocations} | ||
type="notification" | ||
/> | ||
</PatronDataProvider> | ||
) | ||
const processedPatronWithNone = { | ||
notificationPreference: "-", | ||
username: "pastadisciple", | ||
name: "Strega Nonna", | ||
barcode: "23333121538324", | ||
formattedBarcode: "2 3333 12153 8324", | ||
expirationDate: "March 28, 2025", | ||
emails: ["[email protected]", "[email protected]"], | ||
phones: [ | ||
{ | ||
number: "123-456-7890", | ||
type: "t", | ||
}, | ||
], | ||
homeLibrary: { code: "sn ", name: "SNFL (formerly Mid-Manhattan)" }, | ||
id: 6742743, | ||
} as Patron | ||
|
||
const processedPatronWithNothing = { | ||
notificationPreference: "-", | ||
username: "pastadisciple", | ||
name: "Strega Nonna", | ||
barcode: "23333121538324", | ||
formattedBarcode: "2 3333 12153 8324", | ||
expirationDate: "March 28, 2025", | ||
emails: [], | ||
phones: [], | ||
homeLibrary: { code: "sn ", name: "SNFL (formerly Mid-Manhattan)" }, | ||
id: 6742743, | ||
} as Patron | ||
|
||
const processedPatronWithNoPhone = { | ||
notificationPreference: "-", | ||
username: "pastadisciple", | ||
name: "Strega Nonna", | ||
barcode: "23333121538324", | ||
formattedBarcode: "2 3333 12153 8324", | ||
expirationDate: "March 28, 2025", | ||
emails: ["[email protected]", "[email protected]"], | ||
phones: [], | ||
homeLibrary: { code: "sn ", name: "SNFL (formerly Mid-Manhattan)" }, | ||
id: 6742743, | ||
} as Patron | ||
|
||
const component = (patron) => { | ||
return ( | ||
<PatronDataProvider | ||
testSpy={accountFetchSpy} | ||
value={{ | ||
patron: patron, | ||
pickupLocations: filteredPickupLocations, | ||
}} | ||
> | ||
<SettingsSelectForm | ||
patronData={patron} | ||
settingsState={mockSettingsState} | ||
pickupLocations={pickupLocations} | ||
type="notification" | ||
/> | ||
</PatronDataProvider> | ||
) | ||
} | ||
|
||
it("renders correctly with initial preference", () => { | ||
render(component) | ||
render(component(processedPatron)) | ||
|
||
expect(screen.getByText(processedPatronPref)).toBeInTheDocument() | ||
|
||
expect(screen.getByRole("button", { name: /edit/i })).toBeInTheDocument() | ||
}) | ||
|
||
it("allows editing when edit button is clicked", () => { | ||
render(component) | ||
render(component(processedPatron)) | ||
fireEvent.click(screen.getByRole("button", { name: /edit/i })) | ||
|
||
expect( | ||
|
@@ -78,7 +127,7 @@ describe("notification preference form", () => { | |
}) | ||
|
||
it("manages focus", async () => { | ||
render(component) | ||
render(component(processedPatron)) | ||
fireEvent.click(screen.getByRole("button", { name: /edit/i })) | ||
|
||
await waitFor(() => expect(screen.getByRole("combobox")).toHaveFocus()) | ||
|
@@ -90,8 +139,36 @@ describe("notification preference form", () => { | |
) | ||
}) | ||
|
||
it("disables editing the none preference when user has no phone or email", () => { | ||
render(component(processedPatronWithNothing)) | ||
|
||
expect(screen.getByLabelText("Edit notification")).toBeInTheDocument() | ||
|
||
expect(screen.getByLabelText("Edit notification")).toBeDisabled() | ||
|
||
expect(screen.getByText("None")).toBeInTheDocument() | ||
|
||
expect( | ||
screen.getByText( | ||
"Please set a phone number or email address to choose a notification preference." | ||
) | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it("disables the corresponding dropdown field when user doesn't have that contact method", () => { | ||
render(component(processedPatronWithNoPhone)) | ||
|
||
fireEvent.click(screen.getByRole("button", { name: /edit/i })) | ||
|
||
const phoneOption = screen.getByRole("option", { name: "Phone" }) | ||
expect(phoneOption).toBeDisabled() | ||
|
||
const emailOption = screen.getByRole("option", { name: "Email" }) | ||
expect(emailOption).not.toBeDisabled() | ||
}) | ||
|
||
it("calls submit with valid data", async () => { | ||
render(component) | ||
render(component(processedPatron)) | ||
|
||
fireEvent.click(screen.getByRole("button", { name: /edit/i })) | ||
|
||
|
@@ -116,48 +193,15 @@ describe("notification preference form", () => { | |
}) | ||
|
||
it("displays none as an option if that's already user's selection", async () => { | ||
const processedPatronWithNone = { | ||
notificationPreference: "-", | ||
username: "pastadisciple", | ||
name: "Strega Nonna", | ||
barcode: "23333121538324", | ||
formattedBarcode: "2 3333 12153 8324", | ||
expirationDate: "March 28, 2025", | ||
emails: ["[email protected]", "[email protected]"], | ||
phones: [ | ||
{ | ||
number: "123-456-7890", | ||
type: "t", | ||
}, | ||
], | ||
homeLibrary: { code: "sn ", name: "SNFL (formerly Mid-Manhattan)" }, | ||
id: 6742743, | ||
} as Patron | ||
const component = ( | ||
<PatronDataProvider | ||
testSpy={accountFetchSpy} | ||
value={{ | ||
patron: processedPatronWithNone, | ||
pickupLocations: filteredPickupLocations, | ||
}} | ||
> | ||
<SettingsSelectForm | ||
patronData={processedPatronWithNone} | ||
settingsState={mockSettingsState} | ||
pickupLocations={pickupLocations} | ||
type="notification" | ||
/> | ||
</PatronDataProvider> | ||
) | ||
render(component) | ||
render(component(processedPatronWithNone)) | ||
|
||
fireEvent.click(screen.getByRole("button", { name: /edit/i })) | ||
|
||
expect(screen.getByText("None")).toBeInTheDocument() | ||
}) | ||
|
||
it("cancels editing and reverts state", () => { | ||
render(component) | ||
render(component(processedPatron)) | ||
|
||
fireEvent.click(screen.getByRole("button", { name: /edit/i })) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.