From b68d3f8b199a0e86b3645c103842c0f0126af873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Sun, 22 Oct 2023 19:35:38 +0200 Subject: [PATCH] Ported success with errors test --- .../success-with-errors.spec.ts | 75 +++++++++++++++++++ __tests__/frontend/success-with-errors.cy.ts | 60 --------------- 2 files changed, 75 insertions(+), 60 deletions(-) create mode 100644 __tests__/frontend-playwright/success-with-errors.spec.ts delete mode 100644 __tests__/frontend/success-with-errors.cy.ts diff --git a/__tests__/frontend-playwright/success-with-errors.spec.ts b/__tests__/frontend-playwright/success-with-errors.spec.ts new file mode 100644 index 00000000..5b8f0e52 --- /dev/null +++ b/__tests__/frontend-playwright/success-with-errors.spec.ts @@ -0,0 +1,75 @@ +import { expect, test } from "@playwright/test"; + +import { setup } from "../test-utils-playwright/stub-endpoints"; + +test("works and displays moving errors", async ({ page }) => { + await page.goto("/"); + const getCalls = await setup(page); + + await page.evaluate(() => { + window._endpointStubs.listSharedDrives = [ + { + status: "success", + value: { status: "success", response: [] }, + }, + { + status: "success", + value: { status: "success", response: [] }, + }, + ]; + window._endpointStubs.move = [ + { + status: "success", + value: { + status: "success", + response: { + errors: [ + { file: ["PATH", "TO", "FILE"], error: "ERROR MESSAGE 1" }, + { + file: ["PATH", "TO", "SECOND", "FILE"], + error: "ERROR MESSAGE 2", + }, + ], + }, + }, + }, + ]; + }); + + await expect( + page.getByText("Shared drive mover", { exact: true }), + ).toBeVisible(); + await page.getByText("Continue").click(); + await page.getByText("My Drive").click(); + await page.getByText("Continue").click(); + await page.getByText("My Drive").click(); + await page.getByText("Continue").click(); + await expect( + page.getByText( + 'contents of the folder "My Drive" into the folder "My Drive"', + ), + ).toBeVisible(); + await page.getByText("Move", { exact: true }).click(); + await expect(page.getByText("Done!", { exact: true })).toBeVisible(); + await expect(page.getByText("Successfully moved")).toBeVisible(); + await expect(page.getByText("errors were encountered")).toBeVisible(); + + /* eslint-disable playwright/no-raw-locators, playwright/no-nth-methods */ + await expect(page.locator(".mdc-data-table__row").first()).toContainText( + "PATH/TO/FILE", + ); + await expect(page.locator(".mdc-data-table__row").first()).toContainText( + "ERROR MESSAGE 1", + ); + await expect(page.locator(".mdc-data-table__row").nth(1)).toContainText( + "PATH/TO/SECOND/FILE", + ); + await expect(page.locator(".mdc-data-table__row").nth(1)).toContainText( + "ERROR MESSAGE 2", + ); + /* eslint-enable */ + + const moveCalls = getCalls("move"); + expect(moveCalls).toHaveLength(1); + expect(moveCalls[0]).toStrictEqual(["root", "root", true, true, false]); +}); diff --git a/__tests__/frontend/success-with-errors.cy.ts b/__tests__/frontend/success-with-errors.cy.ts deleted file mode 100644 index 1289b023..00000000 --- a/__tests__/frontend/success-with-errors.cy.ts +++ /dev/null @@ -1,60 +0,0 @@ -/// - -import { stubEndpoints } from "../test-utils/stubEndpoints"; - -const stubs = stubEndpoints({ - listFolders: (successHandler) => { - successHandler({ status: "success", response: [] }); - }, - listSharedDrives: (successHandler) => { - successHandler({ status: "success", response: [] }); - }, - move: (successHandler) => { - setTimeout(() => { - successHandler({ - status: "success", - response: { - errors: [ - { file: ["PATH", "TO", "FILE"], error: "ERROR MESSAGE 1" }, - { - file: ["PATH", "TO", "SECOND", "FILE"], - error: "ERROR MESSAGE 2", - }, - ], - }, - }); - }, 100); - }, -}); - -it("works and displays moving errors", () => { - cy.visit("http://localhost:8080"); - cy.contains("Shared drive mover"); - cy.contains("Continue").click(); - cy.contains("My Drive").click(); - cy.contains("Continue").click(); - cy.contains("My Drive").click(); - cy.contains("Continue").click(); - cy.contains('contents of the folder "My Drive" into the folder "My Drive"'); - cy.contains("Move").click(); - cy.contains("Done!"); - cy.contains("errors were encountered"); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - cy.get(".mdc-data-table") - .getTable() - .should((tableData) => { - expect(tableData).to.deep.equal([ - { File: "PATH/TO/FILE", "Error message": "ERROR MESSAGE 1" }, - { File: "PATH/TO/SECOND/FILE", "Error message": "ERROR MESSAGE 2" }, - ]); - }); - cy.contains("Successfully moved").then(() => { - expect(stubs.move).to.have.been.calledOnceWith( - "root", - "root", - true, - true, - false, - ); - }); -});