From a82b0981f188e7d1be525f2daab39d83adc4fbd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane?= Date: Tue, 31 Oct 2023 17:55:46 +0100 Subject: [PATCH] test(e2e): update e2e tests --- e2e/colorScheme.spec.ts | 2 -- e2e/dashboard.spec.ts | 2 -- e2e/favorites.spec.ts | 3 ++- e2e/playlists.spec.ts | 10 +++++----- e2e/search.spec.ts | 6 ++++-- e2e/utils.ts | 13 +++++++------ package.json | 2 +- playwright.config.ts | 16 ++++++++-------- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/e2e/colorScheme.spec.ts b/e2e/colorScheme.spec.ts index acffc42..987489c 100644 --- a/e2e/colorScheme.spec.ts +++ b/e2e/colorScheme.spec.ts @@ -15,6 +15,4 @@ test("colorscheme interface", async ({ page }) => { await expect( page.locator("html[data-mantine-color-scheme=dark]"), ).toBeVisible(); - - await expect(page).toHaveScreenshot(); }); diff --git a/e2e/dashboard.spec.ts b/e2e/dashboard.spec.ts index fc43b0b..815e71d 100644 --- a/e2e/dashboard.spec.ts +++ b/e2e/dashboard.spec.ts @@ -9,6 +9,4 @@ test("default blocks are visible", async ({ page }) => { await expect( page.getByRole("list", { name: "Moods & genres" }).getByRole("listitem"), ).toHaveCount(113); - - await expect(page).toHaveScreenshot(); }); diff --git a/e2e/favorites.spec.ts b/e2e/favorites.spec.ts index 70cad73..2ec2f1a 100644 --- a/e2e/favorites.spec.ts +++ b/e2e/favorites.spec.ts @@ -1,9 +1,10 @@ import { expect, test } from "@playwright/test"; -import { navigateTo } from "./utils"; +import { navigateTo, selectedInstance } from "./utils"; test("save card in favorites", async ({ page }) => { await page.goto("localhost:3000"); + await selectedInstance(page, "invidious.fdn.fr"); // Go to Trending page await page.getByRole("button", { name: "Trending" }).click(); diff --git a/e2e/playlists.spec.ts b/e2e/playlists.spec.ts index 84bc7e1..124fb25 100644 --- a/e2e/playlists.spec.ts +++ b/e2e/playlists.spec.ts @@ -5,9 +5,11 @@ import { navigateTo, search, selectSearchType, + selectedInstance, } from "./utils"; const createPlaylist = async (page, title: string) => { + await selectedInstance(page, "invidious.fdn.fr"); await navigateTo(page, "Playlists", "Playlists"); // Open modal to create playlist @@ -85,7 +87,7 @@ test.describe.serial("playlists", () => { .getByRole("form", { name: "Form add to playlist" }) .getByPlaceholder("Your playlist") .click(); - await page.getByRole("option", { name: "My first playlist" }).click(); + await page.locator('[value="My first playlist"]').click(); await expect( page .getByRole("form", { name: "Form add to playlist" }) @@ -105,7 +107,7 @@ test.describe.serial("playlists", () => { await expect(page.getByRole("listitem")).toContainText("1 videos"); // Save remote playlist to user playlists - await selectSearchType(page, "Playlists"); + await selectSearchType(page, "playlist"); await search(page, "Tomorrowland 2018"); await page @@ -167,9 +169,7 @@ test.describe.serial("playlists", () => { .click(); // Verify notification visibility - await expect(page.getByRole("alert")).toContainText( - /Awesome playlist updated has been updated/, - ); + await checkNotification(page, /Awesome playlist updated has been updated/); await page.reload(); diff --git a/e2e/search.spec.ts b/e2e/search.spec.ts index a49d028..6465289 100644 --- a/e2e/search.spec.ts +++ b/e2e/search.spec.ts @@ -1,11 +1,13 @@ import { expect, test } from "@playwright/test"; -import { search } from "./utils"; +import { listVisibility, search, selectSearchType, selectedInstance } from "./utils"; test.describe.serial("search", () => { test("search an artist", async ({ page }) => { await page.goto("localhost:3000"); + await selectedInstance(page, "invidious.fdn.fr"); + await search(page, "Eminem"); await search(page, "Dubstep"); @@ -43,7 +45,7 @@ test.describe.serial("search", () => { await page.goto("localhost:3000"); await search(page, "Defqon 2018"); - await selectSearchType(page, "Playlists"); + await selectSearchType(page, "playlist"); await listVisibility(page, "Defqon 2018"); }); }); diff --git a/e2e/utils.ts b/e2e/utils.ts index 1059cd6..772245f 100644 --- a/e2e/utils.ts +++ b/e2e/utils.ts @@ -46,14 +46,15 @@ export const selectSearchType = async ( .getByRole("menu", { name: "Search filters" }) .getByRole("textbox", { name: "Type filter" }) .click(); - await expect(page.getByRole("listbox")).toBeVisible(); - await expect( - page.getByRole("listbox").getByRole("option", { selected: true }), - ).toContainText(currentType); - await page.getByRole("listbox").getByRole("option", { name: type }).click(); + // await expect( + // page.getByRole("listbox").getByRole("option", { selected: true }), + // ).toContainText(currentType); + // await page.getByRole("listbox").getByRole("option", { name: type }).click(); + await expect(page.locator('[role="option"][value="video"][aria-selected="true"]')).toContainText(currentType); + await page.locator(`[role="option"][value=${type}]`).click(); }; -const listVisibility = async (page: Page, label: string) => { +export const listVisibility = async (page: Page, label: string) => { await expect( page.getByRole("heading", { name: `Search results : ${label}` }), ).toBeVisible(); diff --git a/package.json b/package.json index 3340ad2..1543b5a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "license": "MIT", "private": true, "scripts": { - "postinstall": "cp .env.dist .env", + "postinstall": "cp .env.dist .env && playwright install", "start": "craco start", "build": "craco build", "ts:check": "tsc", diff --git a/playwright.config.ts b/playwright.config.ts index 1161388..1ac3a02 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -37,15 +37,15 @@ export default defineConfig({ use: { ...devices["Desktop Chrome"] }, }, - { - name: "firefox", - use: { ...devices["Desktop Firefox"] }, - }, + // { + // name: "firefox", + // use: { ...devices["Desktop Firefox"] }, + // }, - { - name: "webkit", - use: { ...devices["Desktop Safari"] }, - }, + // { + // name: "webkit", + // use: { ...devices["Desktop Safari"] }, + // }, /* Test against mobile viewports. */ // {