From c14f783d946ebbd4c5fe59b20edcc2c3940a6a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Tue, 25 Jun 2024 15:16:13 +0200 Subject: [PATCH] :sparkles: Remove redundant locators for Dashboard POM --- frontend/playwright/ui/pages/DashboardPage.js | 9 ++---- .../playwright/ui/specs/dashboard.spec.js | 4 +-- .../ui/visual-specs/visual-dashboard.spec.js | 32 ++++++++----------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/frontend/playwright/ui/pages/DashboardPage.js b/frontend/playwright/ui/pages/DashboardPage.js index 995d8e15a..95b63befd 100644 --- a/frontend/playwright/ui/pages/DashboardPage.js +++ b/frontend/playwright/ui/pages/DashboardPage.js @@ -58,30 +58,25 @@ export class DashboardPage extends BaseWebSocketPage { this.sidebar = page.getByTestId("dashboard-sidebar"); this.sidebarMenu = this.sidebar.getByRole("menu"); + this.mainHeading = page.getByRole("heading", { level: 1 }); - this.projectsHeading = page.getByRole("heading", { name: "Projects" }); this.addProjectButton = page.getByRole("button", { name: "+ NEW PROJECT" }); this.projectName = page.getByText("Project 1"); - this.draftsTitle = page.getByRole("heading", { name: "Drafts" }); this.draftsLink = this.sidebar.getByText("Drafts"); this.draftsFile = page.getByText(/New File 1/); this.fontsLink = this.sidebar.getByText("Fonts"); - this.fontsTitle = page.getByRole("heading", { name: "Fonts", level: 1 }); this.libsLink = this.sidebar.getByText("Libraries"); - this.libsTitle = page.getByRole("heading", { name: "Libraries", level: 1 }); this.searchButton = page.getByRole("button", { name: "dashboard-search" }); - this.searchTitle = page.getByRole("heading", { name: "Search results" }); this.searchInput = page.getByPlaceholder("Search…"); this.newFileName = page.getByText("New File 3"); this.teamDropdown = this.sidebar.getByRole("button", { name: "Your Penpot" }); this.userAccount = this.sidebar.getByRole("button", { name: /Princesa Leia/ }); this.userProfileOption = this.sidebarMenu.getByText("Your account"); - this.userAccountHeading = page.getByRole("heading", { name: "Your account" }); } async setupDraftsEmpty() { @@ -153,7 +148,7 @@ export class DashboardPage extends BaseWebSocketPage { async goToDashboard() { await this.page.goto(`#/dashboard/team/${DashboardPage.anyTeamId}/projects`); - await expect(this.projectsHeading).toBeVisible(); + await expect(this.mainHeading).toBeVisible(); } async goToSecondTeamDashboard() { diff --git a/frontend/playwright/ui/specs/dashboard.spec.js b/frontend/playwright/ui/specs/dashboard.spec.js index 5dc110d35..515ad2b77 100644 --- a/frontend/playwright/ui/specs/dashboard.spec.js +++ b/frontend/playwright/ui/specs/dashboard.spec.js @@ -12,7 +12,7 @@ test("Dashboad page has title ", async ({ page }) => { await dashboardPage.goToDashboard(); await expect(dashboardPage.page).toHaveURL(/dashboard/); - await expect(dashboardPage.projectsHeading).toBeVisible(); + await expect(dashboardPage.mainHeading).toBeVisible(); }); test("User can create a new project", async ({ page }) => { @@ -32,7 +32,7 @@ test("User goes to draft page", async ({ page }) => { await dashboardPage.goToDashboard(); await dashboardPage.draftsLink.click(); - await expect(dashboardPage.draftsTitle).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Drafts"); }); test("User loads the draft page", async ({ page }) => { diff --git a/frontend/playwright/ui/visual-specs/visual-dashboard.spec.js b/frontend/playwright/ui/visual-specs/visual-dashboard.spec.js index b2ddc888d..c157d9159 100644 --- a/frontend/playwright/ui/visual-specs/visual-dashboard.spec.js +++ b/frontend/playwright/ui/visual-specs/visual-dashboard.spec.js @@ -11,7 +11,7 @@ test("User goes to an empty dashboard", async ({ page }) => { await dashboardPage.goToDashboard(); - await expect(dashboardPage.projectsHeading).toBeVisible(); + await expect(dashboardPage.mainHeading).toBeVisible(); await expect(dashboardPage.page).toHaveScreenshot(); }); @@ -24,7 +24,7 @@ test("User goes to an empty draft page", async ({ page }) => { await dashboardPage.goToDashboard(); await dashboardPage.draftsLink.click(); - await expect(dashboardPage.draftsTitle).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Drafts"); await expect(dashboardPage.page).toHaveScreenshot(); }); @@ -34,7 +34,7 @@ test("User goes to an empty fonts page", async ({ page }) => { await dashboardPage.goToDashboard(); await dashboardPage.fontsLink.click(); - await expect(dashboardPage.fontsTitle).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Fonts"); await expect(dashboardPage.page).toHaveScreenshot(); }); @@ -45,7 +45,7 @@ test("User goes to an empty libraries page", async ({ page }) => { await dashboardPage.goToDashboard(); await dashboardPage.libsLink.click(); - await expect(dashboardPage.libsTitle).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Libraries"); await expect(dashboardPage.page).toHaveScreenshot(); }); @@ -55,7 +55,7 @@ test("User goes to an empty search page", async ({ page }) => { await dashboardPage.goToSearch(); - await expect(dashboardPage.searchTitle).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Search results"); await expect(dashboardPage.page).toHaveScreenshot(); }); @@ -81,40 +81,40 @@ test("User goes to a full dashboard", async ({ page }) => { await expect(dashboardPage.page).toHaveScreenshot(); }); -test("User goes to an full draft page", async ({ page }) => { +test("User goes to a full draft page", async ({ page }) => { const dashboardPage = new DashboardPage(page); await dashboardPage.setupDashboardFull(); await dashboardPage.goToDashboard(); await dashboardPage.draftsLink.click(); - await expect(dashboardPage.draftsTitle).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Drafts"); await expect(dashboardPage.page).toHaveScreenshot(); }); -test("User goes to an full library page", async ({ page }) => { +test("User goes to a full library page", async ({ page }) => { const dashboardPage = new DashboardPage(page); await dashboardPage.setupDashboardFull(); await dashboardPage.goToDashboard(); await dashboardPage.libsLink.click(); - await expect(dashboardPage.libsTitle).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Libraries"); await expect(dashboardPage.page).toHaveScreenshot(); }); -test("User goes to an full fonts page", async ({ page }) => { +test("User goes to a full fonts page", async ({ page }) => { const dashboardPage = new DashboardPage(page); await dashboardPage.setupDashboardFull(); await dashboardPage.goToDashboard(); await dashboardPage.fontsLink.click(); - await expect(dashboardPage.fontsTitle).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Fonts"); await expect(dashboardPage.page).toHaveScreenshot(); }); -test("User goes to an full search page", async ({ page }) => { +test("User goes to a full search page", async ({ page }) => { const dashboardPage = new DashboardPage(page); await dashboardPage.setupDashboardFull(); @@ -123,7 +123,7 @@ test("User goes to an full search page", async ({ page }) => { await dashboardPage.searchInput.fill("New"); - await expect(dashboardPage.searchTitle).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Search results"); await expect(dashboardPage.newFileName).toBeVisible(); await expect(dashboardPage.page).toHaveScreenshot(); }); @@ -146,7 +146,7 @@ test("User goes to user profile", async ({ page }) => { await dashboardPage.goToDashboard(); await dashboardPage.goToAccount(); - await expect(dashboardPage.userAccountHeading).toBeVisible(); + await expect(dashboardPage.mainHeading).toHaveText("Your account"); await expect(dashboardPage.page).toHaveScreenshot(); }); @@ -180,8 +180,6 @@ test("User opens teams selector with only one team", async ({ page }) => { const dashboardPage = new DashboardPage(page); await dashboardPage.goToDashboard(); - await expect(dashboardPage.projectsHeading).toBeVisible(); - await dashboardPage.teamDropdown.click(); await expect(page.getByText("Create new team")).toBeVisible(); @@ -193,8 +191,6 @@ test("User opens teams selector with more than one team", async ({ page }) => { await dashboardPage.setupDashboardFull(); await dashboardPage.goToDashboard(); - await expect(dashboardPage.projectsHeading).toBeVisible(); - await dashboardPage.teamDropdown.click(); await expect(page.getByText("Second Team")).toBeVisible();