Skip to content

Commit

Permalink
test: flaky cypress listing search (bloom-housing#4335)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyjablonski committed Sep 25, 2024
1 parent 32f6bcd commit 3379b50
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 31 deletions.
8 changes: 2 additions & 6 deletions sites/partners/cypress/e2e/default/03-listing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ describe("Listing Management Tests", () => {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function verifyDetails(cy: Cypress.cy, listing: any): void {
cy.visit("/")
cy.getByTestId("ag-search-input").type(listing["name"])
cy.getByTestId(listing["name"]).first().click()
cy.findAndOpenListing(listing["name"])
cy.getByID("jurisdictions.name").contains(listing["jurisdiction.id"])
cy.getByID("name").contains(listing["name"])
cy.getByID("developer").contains(listing["developer"])
Expand Down Expand Up @@ -351,9 +349,7 @@ describe("Listing Management Tests", () => {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function verifyOpenListingWarning(cy: Cypress.cy, listing: any): void {
cy.visit("/")
cy.getByTestId("ag-search-input").type(listing["name"])
cy.getByTestId(listing["name"]).first().click()
cy.findAndOpenListing(listing["name"])
cy.getByID("listingEditButton").contains("Edit").click()
cy.getByTestId("nameField")
.should("be.visible")
Expand Down
24 changes: 7 additions & 17 deletions sites/partners/cypress/e2e/default/09-lottery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ describe("Lottery Tests", () => {
cy.addMinimalApplication(uniqueListingName)

// Close the listing and view lottery tab
cy.visit("/")
cy.contains("Listings")
cy.getByTestId("ag-search-input").type(uniqueListingName)
cy.getByTestId(uniqueListingName).first().click()
cy.findAndOpenListing(uniqueListingName)
cy.getByID("listingEditButton").contains("Edit").click()
cy.getByID("closeButton").contains("Close").click()
cy.getByID("close-listing-modal-button").contains("Close").click()
Expand All @@ -45,18 +42,17 @@ describe("Lottery Tests", () => {
cy.visit("/")
cy.getByTestId("Users-1").click()
cy.contains("Users")
cy.getByTestId("ag-search-input").type("partner-user@example.com")
cy.getByTestId("ag-search-input")
.should("be.visible")
.type("partner-user@example.com", { force: true })
cy.getByID("user-link-partner@example.com").first().click()
cy.getByTestId("listings-all-Alameda").check()
cy.getByID("save-user").click()

// Login as partner and view lottery tab
cy.signOut()
cy.login("partnerUser")
cy.visit("/")
cy.contains("Listings")
cy.getByTestId("ag-search-input").type(uniqueListingName)
cy.getByTestId(uniqueListingName).first().click()
cy.findAndOpenListing(uniqueListingName)
cy.get(`[role="tab"]`).eq(2).click()
cy.get("h2").contains("Publish lottery data")

Expand All @@ -68,10 +64,7 @@ describe("Lottery Tests", () => {
// Login as admin and view lottery tab
cy.signOut()
cy.login()
cy.visit("/")
cy.contains("Listings")
cy.getByTestId("ag-search-input").type(uniqueListingName)
cy.getByTestId(uniqueListingName).first().click()
cy.findAndOpenListing(uniqueListingName)
cy.get(`[role="tab"]`).eq(2).click()
cy.get("h2").contains("Export lottery data")

Expand All @@ -83,10 +76,7 @@ describe("Lottery Tests", () => {
// Login as partner and view lottery tab, ensure no data
cy.signOut()
cy.login("partnerUser")
cy.visit("/")
cy.contains("Listings")
cy.getByTestId("ag-search-input").type(uniqueListingName)
cy.getByTestId(uniqueListingName).first().click()
cy.findAndOpenListing(uniqueListingName)
cy.get(`[role="tab"]`).eq(2).click()
cy.get("h2").contains("No lottery data")
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Listings approval feature", () => {

// Admin: Request changes
cy.login("user")
searchAndOpenListing(cy, uniqueListingName)
cy.findAndOpenListing(uniqueListingName)
cy.getByID("listing-status-pending-review").should("be.visible")
cy.getByID("listingEditButton").click()
cy.getByID("requestChangesButton").click()
Expand All @@ -23,7 +23,7 @@ describe("Listings approval feature", () => {

// Partner: Can see the requested changes, edit the listing, and resubmit for approval
cy.login("jurisdictionalAdminUser")
searchAndOpenListing(cy, uniqueListingName)
cy.findAndOpenListing(uniqueListingName)
cy.getByID("listing-status-changes-requested").should("be.visible")
cy.getByID("requestedChanges").contains("Requested changes test summary")
cy.getByID("requestedChangesUser").contains("First Last")
Expand All @@ -36,17 +36,12 @@ describe("Listings approval feature", () => {

// Admin: Approve and publish
cy.login("user")
searchAndOpenListing(cy, uniqueListingNameEdited)
cy.findAndOpenListing(uniqueListingNameEdited)
cy.getByID("listingEditButton").click()
cy.getByID("saveAndContinueButton").should("be.visible")
cy.getByID("listing-status-pending-review").should("be.visible")
cy.getByID("approveAndPublishButton").click()
cy.getByID("listing-status-active").should("be.visible")
cy.signOut()
})

function searchAndOpenListing(cy: Cypress.cy, name: string): void {
cy.getByTestId("ag-search-input").type(name)
cy.getByTestId(name).click()
}
})
7 changes: 7 additions & 0 deletions sites/partners/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,10 @@ Cypress.Commands.add("addMinimalApplication", (listingName) => {
})
cy.getByID("submitApplicationButton").click()
})

Cypress.Commands.add("findAndOpenListing", (listingName) => {
cy.visit("/")
cy.contains("Listings")
cy.getByTestId("ag-search-input").should("be.visible").type(listingName, { force: true })
cy.getByTestId(listingName).first().click()
})
1 change: 1 addition & 0 deletions sites/partners/cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ declare namespace Cypress {
jurisdiction: boolean
): Chainable
addMinimalApplication(listingName: string): Chainable
findAndOpenListing(listingName: string): Chainable
}
}
/* eslint-enable @typescript-eslint/no-unused-vars */

0 comments on commit 3379b50

Please sign in to comment.