Skip to content

Commit

Permalink
Fix flaky e2e preferences test
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Oct 18, 2024
1 parent a57c131 commit 22e52a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion frontend/src/pages/preferences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const doneHydrating = computed(() => useHydrating())
@change="handleChange"
>
<div>
<strong>{{ flag.name }}</strong>
<strong>{{ flag.name }}{{ `: ${flag.state}` }}</strong>
<br />
{{ flag.description }}
</div>
Expand Down
29 changes: 6 additions & 23 deletions frontend/test/playwright/e2e/preferences.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Page, test } from "@playwright/test"
import { type Page, expect, test } from "@playwright/test"

import { preparePageForTests } from "~~/test/playwright/utils/navigation"

Expand Down Expand Up @@ -81,29 +81,12 @@ const toggleChecked = async (
originalChecked: boolean | undefined
) => {
const featureFlag = await getSwitchableInput(page, name, originalChecked)
await featureFlag.setChecked(!originalChecked)

// If the switch knob wasn't rendered yet, wait for it to be rendered.
// The knob's color is `bg-default` when off and `bg-tertiary` when on.
await page.evaluate(
async ([name, className]) => {
const getKnobClasses = () => {
return (
document
.getElementById(`#${name}`)
?.parentElement?.querySelector("span")?.className ?? ""
)
}
const expectedChecked = !originalChecked
await featureFlag.setChecked(expectedChecked)

for (const waitTime of [100, 200, 500]) {
if (getKnobClasses().includes(className)) {
return
}
await new Promise((resolve) => setTimeout(resolve, waitTime))
}
},
[name, !originalChecked ? "bg-tertiary" : "bg-default"] as const
)
const expectedText = `${name}: ${expectedChecked ? "on" : "off"}`

await expect(page.getByText(expectedText).first()).toBeVisible()
}

test.describe("switchable features", () => {
Expand Down

0 comments on commit 22e52a5

Please sign in to comment.