From 3a7d187110eb3152a19bf656465beaeef9636499 Mon Sep 17 00:00:00 2001 From: Pablo Alba <pablo.alba@kaleidos.net> Date: Fri, 15 Nov 2024 17:47:28 +0100 Subject: [PATCH] :sparkles: Add integration tests to viewer role --- .../data/dashboard/get-all-projects.json | 12 ++++ .../logged-in-user/get-teams-role-viewer.json | 25 +++++++ .../data/workspace/get-team-default.json | 2 +- .../data/workspace/get-team-role-viewer.json | 23 +++++++ frontend/playwright/ui/pages/DashboardPage.js | 5 ++ .../ui/specs/dashboard-viewer-role.spec.js | 66 +++++++++++++++++++ .../playwright/ui/specs/dashboard.spec.js | 44 +++++++++++++ .../ui/specs/workspace-viewer-role.spec.js | 34 ++++++++++ .../playwright/ui/specs/workspace.spec.js | 25 +++++++ .../main/ui/ds/product/empty_placeholder.cljs | 2 +- 10 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 frontend/playwright/data/dashboard/get-all-projects.json create mode 100644 frontend/playwright/data/logged-in-user/get-teams-role-viewer.json create mode 100644 frontend/playwright/data/workspace/get-team-role-viewer.json create mode 100644 frontend/playwright/ui/specs/dashboard-viewer-role.spec.js create mode 100644 frontend/playwright/ui/specs/workspace-viewer-role.spec.js diff --git a/frontend/playwright/data/dashboard/get-all-projects.json b/frontend/playwright/data/dashboard/get-all-projects.json new file mode 100644 index 000000000..a36aa8749 --- /dev/null +++ b/frontend/playwright/data/dashboard/get-all-projects.json @@ -0,0 +1,12 @@ +[ + { + "~:id": "c7ce0794-0992-8105-8004-38e630f7920b", + "~:team-id": "c7ce0794-0992-8105-8004-38e630f40f6d", + "~:created-at": "~m1723794627396", + "~:modified-at": "~m1731671259822", + "~:is-default": true, + "~:name": "Drafts", + "~:team-name": "Default", + "~:is-default-team": true + } +] \ No newline at end of file diff --git a/frontend/playwright/data/logged-in-user/get-teams-role-viewer.json b/frontend/playwright/data/logged-in-user/get-teams-role-viewer.json new file mode 100644 index 000000000..9e4d428d3 --- /dev/null +++ b/frontend/playwright/data/logged-in-user/get-teams-role-viewer.json @@ -0,0 +1,25 @@ +[ + { + "~:features": { + "~#set": [ + "layout/grid", + "styles/v2", + "fdata/pointer-map", + "fdata/objects-map", + "components/v2", + "fdata/shape-data-type" + ] + }, + "~:permissions": { + "~:type": "~:membership", + "~:is-owner": true, + "~:is-admin": true, + "~:can-edit": false + }, + "~:name": "Default", + "~:modified-at": "~m1713533116375", + "~:id": "~uc7ce0794-0992-8105-8004-38e630f40f6d", + "~:created-at": "~m1713533116375", + "~:is-default": true + } +] \ No newline at end of file diff --git a/frontend/playwright/data/workspace/get-team-default.json b/frontend/playwright/data/workspace/get-team-default.json index e31dcf90c..f805d68c5 100644 --- a/frontend/playwright/data/workspace/get-team-default.json +++ b/frontend/playwright/data/workspace/get-team-default.json @@ -20,4 +20,4 @@ "~:id": "~uc7ce0794-0992-8105-8004-38e630f40f6d", "~:created-at": "~m1713533116375", "~:is-default": true -} +} \ No newline at end of file diff --git a/frontend/playwright/data/workspace/get-team-role-viewer.json b/frontend/playwright/data/workspace/get-team-role-viewer.json new file mode 100644 index 000000000..a0c035ce4 --- /dev/null +++ b/frontend/playwright/data/workspace/get-team-role-viewer.json @@ -0,0 +1,23 @@ +{ + "~:features": { + "~#set": [ + "layout/grid", + "styles/v2", + "fdata/pointer-map", + "fdata/objects-map", + "components/v2", + "fdata/shape-data-type" + ] + }, + "~:permissions": { + "~:type": "~:membership", + "~:is-owner": false, + "~:is-admin": false, + "~:can-edit": false + }, + "~:name": "Default", + "~:modified-at": "~m1713533116375", + "~:id": "~uc7ce0794-0992-8105-8004-38e630f40f6d", + "~:created-at": "~m1713533116375", + "~:is-default": true +} \ No newline at end of file diff --git a/frontend/playwright/ui/pages/DashboardPage.js b/frontend/playwright/ui/pages/DashboardPage.js index 6d340c62e..75464cd0b 100644 --- a/frontend/playwright/ui/pages/DashboardPage.js +++ b/frontend/playwright/ui/pages/DashboardPage.js @@ -259,6 +259,11 @@ export class DashboardPage extends BaseWebSocketPage { await expect(this.mainHeading).toHaveText("Drafts"); } + async goToFonts() { + await this.page.goto(`#/dashboard/team/${DashboardPage.anyTeamId}/fonts`); + await expect(this.mainHeading).toHaveText("Fonts"); + } + async goToAccount() { await this.userAccount.click(); diff --git a/frontend/playwright/ui/specs/dashboard-viewer-role.spec.js b/frontend/playwright/ui/specs/dashboard-viewer-role.spec.js new file mode 100644 index 000000000..55197be03 --- /dev/null +++ b/frontend/playwright/ui/specs/dashboard-viewer-role.spec.js @@ -0,0 +1,66 @@ +import { test, expect } from "@playwright/test"; +import DashboardPage from "../pages/DashboardPage"; + +test.beforeEach(async ({ page }) => { + await DashboardPage.init(page); + await DashboardPage.mockRPC( + page, + "get-profile", + "logged-in-user/get-profile-logged-in-no-onboarding.json", + ); + await DashboardPage.mockRPC( + page, + "get-teams", + "logged-in-user/get-teams-role-viewer.json", + ); +}); + +test("User can't create a new project", async ({ page }) => { + const dashboardPage = new DashboardPage(page); + await dashboardPage.goToDashboard(); + await expect(dashboardPage.addProjectButton).toBeHidden(); +}); + +test("User has an empty placeholder", async ({ page }) => { + const dashboardPage = new DashboardPage(page); + await dashboardPage.goToDashboard(); + await expect( + dashboardPage.page.getByTestId("empty-placeholder"), + ).toBeVisible(); +}); + +test("User hasn't context menu options for edit file", async ({ page }) => { + await DashboardPage.mockRPC( + page, + "get-all-projects", + "dashboard/get-all-projects.json", + ); + + const dashboardPage = new DashboardPage(page); + await dashboardPage.setupDrafts(); + await dashboardPage.goToDrafts(); + + const button = dashboardPage.page.getByRole("button", { name: /New File 2/ }); + await button.click(); + await button.click({ button: "right" }); + + await expect(dashboardPage.page.getByText("rename")).toBeHidden(); + await expect(dashboardPage.page.getByText("duplicate")).toBeHidden(); + await expect( + dashboardPage.page.getByText("add as shared library"), + ).toBeHidden(); + await expect(dashboardPage.page.getByText("delete")).toBeHidden(); +}); + +test("User hasn't create file button", async ({ page }) => { + const dashboardPage = new DashboardPage(page); + await dashboardPage.setupDrafts(); + await dashboardPage.goToDrafts(); + await expect(dashboardPage.page.getByText("+ New File")).toBeHidden(); +}); + +test("User hasn't add font button", async ({ page }) => { + const dashboardPage = new DashboardPage(page); + await dashboardPage.goToFonts(); + await expect(dashboardPage.page.getByText("add custom font")).toBeHidden(); +}); diff --git a/frontend/playwright/ui/specs/dashboard.spec.js b/frontend/playwright/ui/specs/dashboard.spec.js index b11e1a326..b4ef9d6e5 100644 --- a/frontend/playwright/ui/specs/dashboard.spec.js +++ b/frontend/playwright/ui/specs/dashboard.spec.js @@ -52,3 +52,47 @@ test("Lists files in the drafts page", async ({ page }) => { dashboardPage.page.getByRole("button", { name: /New File 2/ }), ).toBeVisible(); }); + +test("User hasn't an empty placeholder", async ({ page }) => { + const dashboardPage = new DashboardPage(page); + await dashboardPage.goToDashboard(); + await expect( + dashboardPage.page.getByTestId("empty-placeholder"), + ).toBeHidden(); +}); + +test("User has context menu options for edit file", async ({ page }) => { + await DashboardPage.mockRPC( + page, + "get-all-projects", + "dashboard/get-all-projects.json", + ); + + const dashboardPage = new DashboardPage(page); + await dashboardPage.setupDrafts(); + await dashboardPage.goToDrafts(); + + const button = dashboardPage.page.getByRole("button", { name: /New File 2/ }); + await button.click(); + await button.click({ button: "right" }); + + await expect(dashboardPage.page.getByText("rename")).toBeVisible(); + await expect(dashboardPage.page.getByText("duplicate")).toBeVisible(); + await expect( + dashboardPage.page.getByText("add as shared library"), + ).toBeVisible(); + await expect(dashboardPage.page.getByText("delete")).toBeVisible(); +}); + +test("User has create file button", async ({ page }) => { + const dashboardPage = new DashboardPage(page); + await dashboardPage.setupDrafts(); + await dashboardPage.goToDrafts(); + await expect(dashboardPage.page.getByText("+ New File")).toBeVisible(); +}); + +test("User has add font button", async ({ page }) => { + const dashboardPage = new DashboardPage(page); + await dashboardPage.goToFonts(); + await expect(dashboardPage.page.getByText("add custom font")).toBeVisible(); +}); diff --git a/frontend/playwright/ui/specs/workspace-viewer-role.spec.js b/frontend/playwright/ui/specs/workspace-viewer-role.spec.js new file mode 100644 index 000000000..9830d39b5 --- /dev/null +++ b/frontend/playwright/ui/specs/workspace-viewer-role.spec.js @@ -0,0 +1,34 @@ +import { test, expect } from "@playwright/test"; +import { WorkspacePage } from "../pages/WorkspacePage"; +import { presenceFixture } from "../../data/workspace/ws-notifications"; + +test.beforeEach(async ({ page }) => { + await WorkspacePage.init(page); + + const workspacePage = new WorkspacePage(page); + await workspacePage.setupEmptyFile(page); + await WorkspacePage.mockRPC( + page, + "get-team?id=*", + "workspace/get-team-role-viewer.json", + ); + + await workspacePage.goToWorkspace(); +}); + +test("User haven't toolbar", async ({ page }) => { + await expect(page.getByTitle("toggle toolbar")).toBeHidden(); + await expect(page.getByTitle("design")).toBeHidden(); +}); + +test("User haven't edition menu entries", async ({ page }) => { + await page.getByTitle("main menu").click(); + await page.getByText("file").last().click(); + + await expect(page.getByText("Add as Shared Library")).toBeHidden(); + + await page.getByText("edit").click(); + + await expect(page.getByText("Undo")).toBeHidden(); + await expect(page.getByText("Redo")).toBeHidden(); +}); diff --git a/frontend/playwright/ui/specs/workspace.spec.js b/frontend/playwright/ui/specs/workspace.spec.js index a95931328..2356d5fae 100644 --- a/frontend/playwright/ui/specs/workspace.spec.js +++ b/frontend/playwright/ui/specs/workspace.spec.js @@ -225,3 +225,28 @@ test("Bug 9066 - Problem with grid layout", async ({ page }) => { page.getByTestId("children-6ad3e6b9-c5a0-80cf-8005-283bbe378bcb"), ).toHaveText(["CBCDEF"]); }); + +test("User have toolbar", async ({ page }) => { + const workspacePage = new WorkspacePage(page); + await workspacePage.setupEmptyFile(page); + await workspacePage.goToWorkspace(); + + await expect(page.getByTitle("toggle toolbar")).toBeVisible(); + await expect(page.getByTitle("design")).toBeVisible(); +}); + +test("User have edition menu entries", async ({ page }) => { + const workspacePage = new WorkspacePage(page); + await workspacePage.setupEmptyFile(page); + await workspacePage.goToWorkspace(); + + await page.getByTitle("Main menu").click(); + await page.getByText("file").last().click(); + + await expect(page.getByText("Add as Shared Library")).toBeVisible(); + + await page.getByText("edit").click(); + + await expect(page.getByText("Undo")).toBeVisible(); + await expect(page.getByText("Redo")).toBeVisible(); +}); diff --git a/frontend/src/app/main/ui/ds/product/empty_placeholder.cljs b/frontend/src/app/main/ui/ds/product/empty_placeholder.cljs index cbbeb4173..40b9fdc1b 100644 --- a/frontend/src/app/main/ui/ds/product/empty_placeholder.cljs +++ b/frontend/src/app/main/ui/ds/product/empty_placeholder.cljs @@ -27,7 +27,7 @@ [{:keys [class title subtitle type children] :rest props}] (let [class (dm/str class " " (stl/css :empty-placeholder)) - props (mf/spread-props props {:class class}) + props (mf/spread-props props {:class class :data-testid "empty-placeholder"}) type (or type 1) decoration-type (dm/str "empty-placeholder-" (str type))] [:> "div" props