From eb1dc38bc56f1e170b5865c9753f3161ab8a2477 Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Wed, 15 May 2024 21:31:31 +0300 Subject: [PATCH] Temporarily remove preferences test Signed-off-by: Olga Bulat --- .../test/playwright/e2e/preferences.spec.ts | 95 ------------------- 1 file changed, 95 deletions(-) delete mode 100644 frontend/test/playwright/e2e/preferences.spec.ts diff --git a/frontend/test/playwright/e2e/preferences.spec.ts b/frontend/test/playwright/e2e/preferences.spec.ts deleted file mode 100644 index b06eeea6de9..00000000000 --- a/frontend/test/playwright/e2e/preferences.spec.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { test, expect, Page } from "@playwright/test" - -import { preparePageForTests } from "~~/test/playwright/utils/navigation" - -import featureData from "~~/feat/feature-flags.json" - -import { getFlagStatus } from "~/stores/feature-flag" -import type { FeatureFlag, FlagName } from "~/types/feature-flag" - -const getFeatureCookies = async (page: Page, cookieName: string) => { - const cookies = await page.context().cookies() - const cookieValue = cookies.find( - (cookie) => cookie.name === cookieName - )?.value - if (!cookieValue) { - return {} - } - return JSON.parse(decodeURIComponent(cookieValue)) -} - -/** - * Ensure that the features to be tested are not out of sync with the feature flags. - */ -const getFeaturesToTest = () => { - const testableFeatures = { - fetch_sensitive: "off", - analytics: "on", - } as const - for (const [name, state] of Object.entries(testableFeatures)) { - const flag = featureData.features[name as FlagName] as FeatureFlag - if (getFlagStatus(flag) !== "switchable") { - throw new Error(`Feature ${name} is not switchable`) - } - if (flag.defaultState !== state) { - throw new Error(`Feature ${name} is not in the expected state ${state}`) - } - } - return testableFeatures -} - -const features = getFeaturesToTest() - -const getSwitchableInput = async ( - page: Page, - name: string, - checked: boolean -) => { - const checkbox = page.locator(`input[type=checkbox]#${name}`).first() - await expect(checkbox).toBeEnabled() - if (checked) { - await expect(checkbox).toBeChecked() - } else { - await expect(checkbox).not.toBeChecked() - } - return checkbox -} - -test.describe("switchable features", () => { - test.beforeEach(async ({ page }) => { - await preparePageForTests(page, "xl") - }) - - for (const [name, defaultState] of Object.entries(features)) { - const checked = defaultState === "on" - - test(`can switch ${name} from ${defaultState}`, async ({ page }) => { - await page.goto(`/preferences`) - const featureFlag = await getSwitchableInput(page, name, checked) - await featureFlag.click() - - // eslint-disable-next-line playwright/no-conditional-in-test - if (checked) { - // eslint-disable-next-line playwright/no-conditional-expect - await expect(featureFlag).not.toBeChecked() - } else { - // eslint-disable-next-line playwright/no-conditional-expect - await expect(featureFlag).toBeChecked() - } - }) - - test(`switching ${name} from ${defaultState} saves state in a cookie`, async ({ - page, - }) => { - await page.goto(`/preferences`) - const featureFlag = await getSwitchableInput(page, name, checked) - await featureFlag.click() - - const storageCookie = { cookie: "features", session: "sessionFeatures" }[ - featureData.features[name as FlagName].storage as "cookie" | "session" - ] - const featureCookie = await getFeatureCookies(page, storageCookie) - expect(featureCookie[name]).toEqual(defaultState === "on" ? "off" : "on") - }) - } -})