Skip to content

Commit

Permalink
Fix flaky test from #4995 (#4999)
Browse files Browse the repository at this point in the history
* Fix flaky test from #4995

* Fix flaky preferences test
  • Loading branch information
obulat authored Sep 27, 2024
1 parent 3fe95ae commit d4e8465
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions frontend/src/pages/preferences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { useFeatureFlagStore } from "~/stores/feature-flag"
import { isFlagName } from "~/types/feature-flag"
import { SWITCHABLE, ON, OFF } from "~/constants/feature-flag"
import { useHydrating } from "~/composables/use-hydrating"
import VContentPage from "~/components/VContentPage.vue"
import VCheckbox from "~/components/VCheckbox/VCheckbox.vue"
Expand Down Expand Up @@ -50,6 +52,8 @@ const flagsBySwitchable = computed(() => {
const featureGroups = computed(() => {
return featureFlagStore.getFeatureGroups()
})
const doneHydrating = computed(() => useHydrating())
</script>

<template>
Expand Down Expand Up @@ -86,6 +90,7 @@ const featureGroups = computed(() => {
class="flex-row items-center"
:checked="flag.state === ON"
is-switch
:disabled="!doneHydrating"
@change="handleChange"
>{{ $t(`prefPage.features.${flag.name}`) }}</VCheckbox
>
Expand Down
5 changes: 4 additions & 1 deletion frontend/test/playwright/e2e/attribution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ const copyAttribution = async (
) => {
const formatPattern = new RegExp(formatTitle[formatId], "i")

// Ensure the page is fully hydrated before interacting with it.
const copyButton = getCopyButton(page)
await expect(copyButton).toBeEnabled()

await page.getByRole("tab", { name: formatPattern }).click()

await expect(
page.getByRole("tabpanel", { name: formatPattern })
).toBeVisible()

const copyButton = getCopyButton(page)
await expect(copyButton).toHaveAttribute("id", `copyattr-${formatId}`)
await copyButton.click()

Expand Down
6 changes: 5 additions & 1 deletion frontend/test/playwright/e2e/preferences.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect, Page } from "@playwright/test"
import { expect, Page, test } from "@playwright/test"

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

Expand Down Expand Up @@ -114,8 +114,12 @@ test.describe("switchable features", () => {
}) => {
await page.goto(`/preferences`)
const featureFlag = await getSwitchableInput(page, name, checked)

await featureFlag.click()

// Ensure the feature flag is updated
await getSwitchableInput(page, name, !checked)

const storageCookie = { cookie: "features", session: "sessionFeatures" }[
featureData.features[name as FlagName].storage as "cookie" | "session"
]
Expand Down

0 comments on commit d4e8465

Please sign in to comment.