Skip to content

Commit 14a5934

Browse files
nssensalonssensalo
andauthored
Debugging broken browse-bills and testimony playwright tests (#1972)
* Debugging broken browse-bills and testimony playwright tests * re-submitting after running linting --------- Co-authored-by: nssensalo <nssen@Anna.localdomain>
1 parent c2d6f3e commit 14a5934

File tree

4 files changed

+66
-24
lines changed

4 files changed

+66
-24
lines changed

tests/e2e/browse-bills.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ import { test, expect } from "@playwright/test"
22
import { BillPage } from "./page_objects/billPage"
33

44
test.beforeEach(async ({ page }) => {
5-
await page.goto("http://localhost:3000/bills")
6-
await page.waitForSelector("li.ais-Hits-item a")
5+
const billpage = new BillPage(page)
6+
await billpage.goto()
7+
await billpage.removePresetCourtfilter()
78
})
89

910
test.describe("Search result test", () => {
1011
test("should search for bills", async ({ page }) => {
1112
const billpage = new BillPage(page)
1213

1314
const searchTerm = billpage.searchWord
14-
const resultCount = billpage.resultCount
15-
const initialResultCount = await resultCount.textContent()
1615

1716
await billpage.search(searchTerm)
1817

19-
const searchResultCount = await resultCount.textContent()
20-
await expect(searchResultCount).not.toBe(initialResultCount)
18+
await expect(billpage.queryFilter).toBeVisible()
19+
20+
await expect(billpage.queryFilter).toContainText(searchTerm)
21+
22+
await expect(billpage.firstBill).toBeVisible()
2123
})
2224

2325
test("should show search query", async ({ page }) => {
@@ -30,7 +32,7 @@ test.describe("Search result test", () => {
3032

3133
const queryFilter = await billpage.queryFilter
3234

33-
await expect(queryFilter).toContainText("query:")
35+
await expect(queryFilter).toContainText("Query:")
3436
await expect(queryFilter).toContainText(searchTerm)
3537
})
3638

@@ -50,7 +52,7 @@ test.describe("Search result test", () => {
5052
const searchTerm = "nonexistentsearchterm12345"
5153
const billpage = new BillPage(page)
5254

53-
billpage.search(searchTerm)
55+
await billpage.search(searchTerm)
5456

5557
const noResultsText = await page.getByText("Looks Pretty Empty Here")
5658
const noResultsImg = page.getByAltText("No Results")
@@ -118,7 +120,7 @@ test.describe("Filter Bills test", () => {
118120
"%27"
119121
)
120122
await expect(page).toHaveURL(
121-
new RegExp(`court%5D%5B1%5D=${encodedFilterLabel}`)
123+
new RegExp(`court%5D%5B0%5D=${encodedFilterLabel}`)
122124
)
123125
})
124126

tests/e2e/page_objects/billPage.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class BillPage {
1212
readonly currentCategorySelector: string
1313
readonly basicCategorySelector: string
1414
readonly billPageBackToList: Locator
15+
readonly resultsCountText: Locator
1516

1617
constructor(page: Page) {
1718
this.page = page
@@ -26,23 +27,21 @@ export class BillPage {
2627
"li:nth-child(2) input.ais-RefinementList-checkbox"
2728
this.currentCategorySelector = ".ais-CurrentRefinements-item"
2829
this.basicCategorySelector = "div.ais-RefinementList.mb-4"
30+
this.resultsCountText = page.getByText("Results").first()
2931
}
3032

3133
async goto() {
3234
await this.page.goto("http://localhost:3000/bills")
33-
await this.page.waitForSelector("li.ais-Hits-item a")
35+
await this.resultCount.waitFor({ state: "visible", timeout: 30000 })
36+
// await this.page.waitForSelector("li.ais-Hits-item a",{timeout:90000})
3437
}
3538

3639
async search(query: string) {
37-
const initialResult = await this.firstBill.textContent()
40+
await this.searchBar.focus()
3841
await this.searchBar.fill(query)
39-
await this.page.waitForFunction(initialResult => {
40-
const searchResult = document.querySelector("li.ais-Hits-item a")
41-
return (
42-
!searchResult ||
43-
(searchResult && searchResult.textContent != initialResult)
44-
)
45-
}, initialResult)
42+
const activeQueryFilter = this.page.getByText(`Query: ${query}`).first()
43+
44+
await activeQueryFilter.waitFor({ state: "visible", timeout: 50000 })
4645
}
4746

4847
async sort(option: string) {
@@ -152,4 +151,17 @@ export class BillPage {
152151

153152
return filterLabel
154153
}
154+
155+
async removePresetCourtfilter() {
156+
const activeCourtCheckbox = this.page
157+
.locator("div, span, label", { has: this.page.getByText(/Court/i) })
158+
.getByRole("checkbox", { checked: true })
159+
160+
await activeCourtCheckbox.click({ noWaitAfter: true, timeout: 0 })
161+
162+
await this.page
163+
.getByText("Results")
164+
.first()
165+
.waitFor({ state: "visible", timeout: 60000 })
166+
}
155167
}

tests/e2e/page_objects/testimony.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,21 @@ export class TestimonyPage {
3838
}
3939

4040
async sort(option: string) {
41-
await this.page.getByText("Sort by New -> Old").click()
41+
// previoud code: await this.page.getByText("Sort by New -> Old").click()
42+
await this.page
43+
.getByText(/Sort by/i)
44+
.first()
45+
.click()
4246
await this.page.getByRole("option", { name: option }).click()
4347
}
48+
49+
async removePresetCourtfilter() {
50+
const activeCourtCheckbox = this.page
51+
.locator("div, span, label", { has: this.page.getByText(/Court/i) })
52+
.getByRole("checkbox", { checked: true })
53+
54+
await activeCourtCheckbox.click({ noWaitAfter: true, timeout: 0 })
55+
56+
await this.resultsCountText.waitFor({ state: "visible", timeout: 60000 })
57+
}
4458
}

tests/e2e/testimony.spec.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { test, expect } from "@playwright/test"
22
import { TestimonyPage } from "./page_objects/testimony"
3+
import { waitFor } from "@testing-library/dom"
34

45
test.beforeEach(async ({ page }) => {
56
await page.goto("http://localhost:3000/testimony")
@@ -34,7 +35,7 @@ test.describe("Testimony Search", () => {
3435
await testimonyPage.search(queryText)
3536

3637
const { queryFilterItem, resultsCountText } = testimonyPage
37-
await expect(queryFilterItem).toContainText("query:")
38+
await expect(queryFilterItem).toContainText("Query:")
3839
await expect(queryFilterItem).toContainText(queryText)
3940
await expect(resultsCountText).toBeVisible()
4041
})
@@ -102,33 +103,47 @@ test.describe("Testimony Filtering", () => {
102103
})
103104

104105
test("should filter by position: endorse", async ({ page }) => {
105-
await page.getByRole("checkbox", { name: "endorse" }).check()
106106
const testimonyPage = new TestimonyPage(page)
107+
testimonyPage.removePresetCourtfilter()
108+
109+
const endorseCheckbox = page.getByRole("checkbox", { name: /endorse/i })
110+
await endorseCheckbox.check({ timeout: 30000 })
111+
107112
await expect(testimonyPage.positionFilterItem).toContainText("endorse")
108113
await expect(page).toHaveURL(/.*position%5D%5B0%5D=endorse/)
109114
})
110115

111116
test("should filter by position: neutral", async ({ page }) => {
112-
await page.getByRole("checkbox", { name: "neutral" }).check()
113117
const testimonyPage = new TestimonyPage(page)
118+
testimonyPage.removePresetCourtfilter()
119+
120+
const checkNeutral = page.getByRole("checkbox", { name: "neutral" })
121+
await checkNeutral.check({ timeout: 30000 })
122+
await page.getByRole("checkbox", { name: "neutral" }).check()
123+
114124
await expect(testimonyPage.positionFilterItem).toContainText("neutral")
115125
await expect(page).toHaveURL(/.*position%5D%5B0%5D=neutral/)
116126
})
117127

118128
test("should filter by bill", async ({ page }) => {
129+
const testimonyPage = new TestimonyPage(page)
130+
testimonyPage.removePresetCourtfilter()
131+
119132
const billCheckbox = page.getByLabel(/^[S|H]\d{1,4}$/).first()
120133
const billId = await billCheckbox.inputValue()
121134
expect(billId).toBeTruthy()
122135

123136
if (billId) {
124137
await billCheckbox.check()
125-
const testimonyPage = new TestimonyPage(page)
126138
await expect(testimonyPage.billFilterItem).toContainText(billId as string)
127139
await expect(page).toHaveURL(new RegExp(`.*billId%5D%5B0%5D=${billId}`))
128140
}
129141
})
130142

131143
test("should filter by author", async ({ page }) => {
144+
const testimonyPage = new TestimonyPage(page)
145+
testimonyPage.removePresetCourtfilter()
146+
132147
const writtenByText = await page
133148
.getByText(/Written by/)
134149
.first()
@@ -138,7 +153,6 @@ test.describe("Testimony Filtering", () => {
138153
if (writtenByText) {
139154
const authorName = writtenByText.slice(11)
140155
await page.getByRole("checkbox", { name: authorName }).check()
141-
const testimonyPage = new TestimonyPage(page)
142156
await expect(testimonyPage.authorFilterItem).toContainText(authorName)
143157
await expect(page).toHaveURL(
144158
new RegExp(

0 commit comments

Comments
 (0)