Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Enable new header in staging (#2102)
Browse files Browse the repository at this point in the history
* Enable new header in staging

* Update the cookie sameSite in the unit tests based on flags

* Set flag back to switchable with default of on

* Fix the tests

Co-authored-by: Olga Bulat <obulat@gmail.com>
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 18, 2023
1 parent 7da02a7 commit cbd039c
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion feat/feature-flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"production": "disabled"
},
"description": "Toggle the new header, including recent searches.",
"defaultState": "off"
"defaultState": "on"
},
"feat_disabled": {
"status": "disabled",
Expand Down
13 changes: 8 additions & 5 deletions test/playwright/e2e/homepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { expect, Page, test } from "@playwright/test"

import { mockProviderApis } from "~~/test/playwright/utils/route"
import {
enableNewHeader,
goToSearchTerm,
OLD_HEADER,
searchTypePath,
t,
} from "~~/test/playwright/utils/navigation"

import { supportedSearchTypes } from "~/constants/media"
Expand All @@ -19,23 +20,25 @@ for (const searchType of supportedSearchTypes) {
test(`can change type and search for ${searchType} from homepage`, async ({
page,
}) => {
await enableNewHeader(page)
await goToSearchTerm(page, "cat", {
searchType,
mode: "CSR",
headerMode: OLD_HEADER,
})

const expectedUrl = `/search/${searchTypePath(searchType)}?q=cat`
await expect(page).toHaveURL(expectedUrl)
})
}

const searchTypePopover = "[aria-labelledby='search-type-button'] > div"

const popoverIsVisible = async (page: Page) =>
await expect(page.locator(".popover-content")).toBeVisible()
await expect(page.locator(searchTypePopover)).toBeVisible()
const popoverIsNotVisible = async (page: Page) =>
await expect(page.locator(".popover-content")).not.toBeVisible()
await expect(page.locator(searchTypePopover)).not.toBeVisible()
const clickPopoverButton = async (page: Page) =>
await page.click('button[aria-label="All content"]')
await page.getByRole("button", { name: t("search-type.all") }).click()

test("can close the search type popover by clicking outside", async ({
page,
Expand Down
5 changes: 4 additions & 1 deletion test/playwright/e2e/migration-banner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { test, expect } from "@playwright/test"

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

test.describe.configure({ mode: "parallel" })

test.describe("migration banner", () => {
Expand Down Expand Up @@ -32,14 +34,15 @@ test.describe("migration banner", () => {
})

test("migration banner goes away on navigation", async ({ page }) => {
await enableNewHeader(page)
await page.goto("/?referrer=creativecommons.org")

const migrationNotice = page.locator('[data-testid="banner-cc-referral"]')
await expect(migrationNotice).toBeVisible()

// Navigate away from the page
await Promise.all([
page.locator("a.homepage-image").first().click(),
page.locator("a.home-cell").first().click(),
page.waitForLoadState("domcontentloaded"),
])
await expect(migrationNotice).toBeHidden()
Expand Down
8 changes: 6 additions & 2 deletions test/playwright/e2e/mobile-menu-old.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { test, expect } from "@playwright/test"
import { expect, test } from "@playwright/test"

import {
closeMobileMenu,
enableOldHeader,
goToSearchTerm,
OLD_HEADER,
openContentTypes,
Expand All @@ -19,6 +20,7 @@ test.use(mobileFixture)
test.describe.configure({ mode: "parallel" })

test("Can open filters menu on mobile at least twice", async ({ page }) => {
await enableOldHeader(page)
await page.goto("/search/?q=cat")

await openFilters(page, OLD_HEADER)
Expand All @@ -37,6 +39,7 @@ test("Can open filters menu on mobile at least twice", async ({ page }) => {
})

test("Can open mobile menu at least twice", async ({ page }) => {
await enableOldHeader(page)
await goToSearchTerm(page, "cat")
await openContentTypes(page, OLD_HEADER)
await expect(page.locator("button", { hasText: "Close" })).toBeVisible()
Expand All @@ -47,7 +50,8 @@ test("Can open mobile menu at least twice", async ({ page }) => {
})

test("Selecting a search type closes the modal", async ({ page }) => {
await goToSearchTerm(page, "cat")
await enableOldHeader(page)
await goToSearchTerm(page, "cat", { headerMode: OLD_HEADER })
await openContentTypes(page, OLD_HEADER)
await expect(page.locator("button", { hasText: "Close" })).toBeVisible()
await page.locator('a[role="radio"]:has-text("Audio")').click()
Expand Down
6 changes: 4 additions & 2 deletions test/playwright/e2e/translation-banner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { test, expect } from "@playwright/test"

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

const russianSearchPath = "/ru/search?q=dog"

test.describe.configure({ mode: "parallel" })
Expand All @@ -8,6 +10,7 @@ test.describe("translation banner", () => {
test("Can see the translation banner and go to the correct link", async ({
page,
}) => {
await enableNewHeader(page)
await page.goto(russianSearchPath)
await expect(
page.locator(
Expand Down Expand Up @@ -50,8 +53,7 @@ test.describe("translation banner", () => {
const banner = page.locator('.span:has-text("Help us get to 100 percent")')
await expect(banner).not.toBeVisible({ timeout: 500 })
// Test that the banner does not re-appear when navigating to the 'About us' page
await page.click('[aria-label="меню"]')
await page.click('a[role="menuitemcheckbox"]:has-text("Наша история")')
await page.locator('a[href="/ru/about"]').click()
await expect(banner).not.toBeVisible({ timeout: 500 })

await page.goto(russianSearchPath)
Expand Down
12 changes: 12 additions & 0 deletions test/playwright/utils/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,18 @@ export const enableNewHeader = async (page: Page) => {
])
}

export const enableOldHeader = async (page: Page) => {
// Add the new_header cookie
await page.context().addCookies([
{
name: "features",
value: "%7B%22new_header%22%3A%22off%22%7D",
domain: "localhost",
path: "/",
},
])
}

export const setCookies = async (
context: BrowserContext,
cookies: Record<string, string | boolean | string[]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { test } from "@playwright/test"
import breakpoints from "~~/test/playwright/utils/breakpoints"
import {
closeFilters,
enableOldHeader,
OLD_HEADER,
setCookies,
} from "~~/test/playwright/utils/navigation"
Expand All @@ -11,6 +12,7 @@ test.describe.configure({ mode: "parallel" })

test.describe("audio results", () => {
test.beforeEach(async ({ page }) => {
await enableOldHeader(page)
await page.goto("/search/audio?q=birds")
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import breakpoints from "~~/test/playwright/utils/breakpoints"
import { hideInputCursors } from "~~/test/playwright/utils/page"
import {
closeFilters,
enableOldHeader,
goToSearchTerm,
languageDirections,
OLD_HEADER,
Expand All @@ -19,6 +20,7 @@ const headerSelector = ".main-header"
for (const dir of languageDirections) {
test.describe(dir, () => {
test.beforeEach(async ({ page }) => {
await enableOldHeader(page)
await goToSearchTerm(page, "birds", { dir: dir })
})

Expand Down
2 changes: 2 additions & 0 deletions test/playwright/visual-regression/pages/homepage-old.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
dismissTranslationBanner,
pathWithDir,
languageDirections,
enableOldHeader,
} from "~~/test/playwright/utils/navigation"

test.describe.configure({ mode: "parallel" })
Expand All @@ -23,6 +24,7 @@ for (const dir of languageDirections) {
test.describe(`${dir} homepage snapshots`, () => {
const path = pathWithDir("/", dir)
test.beforeEach(async ({ page }) => {
await enableOldHeader(page)
await page.goto(path)
await dismissTranslationBanner(page)
await deleteImageCarousel(page)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
pathWithDir,
languageDirections,
setCookies,
enableOldHeader,
} from "~~/test/playwright/utils/navigation"

test.describe.configure({ mode: "parallel" })
Expand All @@ -16,6 +17,7 @@ for (const contentPage of contentPages) {
test.describe(`${contentPage} ${dir} page snapshots`, () => {
breakpoints.describeEvery(({ breakpoint, expectSnapshot }) => {
test("full page", async ({ context, page }) => {
await enableOldHeader(page)
await setCookies(context, {
uiBreakpoint: breakpoint,
uiDismissedBanners: ["translation-ar"],
Expand Down
9 changes: 8 additions & 1 deletion test/unit/specs/stores/ui-store.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setActivePinia, createPinia } from "~~/test/unit/test-utils/pinia"

import { useFeatureFlagStore } from "~/stores/feature-flag"
import { useUiStore } from "~/stores/ui"

const initialState = {
Expand Down Expand Up @@ -31,13 +32,19 @@ const NOT_VISIBLE_AND_NOT_DISMISSED = {
const cookieOptions = {
maxAge: 5184000,
path: "/",
sameSite: "none",
sameSite: "strict",
secure: false,
}

describe("Ui Store", () => {
beforeEach(() => {
setActivePinia(createPinia())
const featureFlagStore = useFeatureFlagStore()
if (featureFlagStore.isOn("new_header")) {
cookieOptions.sameSite = "strict"
} else {
cookieOptions.sameSite = "none"
}
})
describe("state", () => {
it("sets the initial state correctly", () => {
Expand Down

0 comments on commit cbd039c

Please sign in to comment.