From 7d2e65077b6c5a265e6663f3ca890fe393c47cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Sun, 22 Oct 2023 16:58:04 +0200 Subject: [PATCH] Ported non-empty error test --- .../frontend-playwright/non-empty.spec.ts | 74 +++++++++++++++++++ __tests__/frontend/non-empty.cy.ts | 47 ------------ 2 files changed, 74 insertions(+), 47 deletions(-) create mode 100644 __tests__/frontend-playwright/non-empty.spec.ts delete mode 100644 __tests__/frontend/non-empty.cy.ts diff --git a/__tests__/frontend-playwright/non-empty.spec.ts b/__tests__/frontend-playwright/non-empty.spec.ts new file mode 100644 index 00000000..809fac93 --- /dev/null +++ b/__tests__/frontend-playwright/non-empty.spec.ts @@ -0,0 +1,74 @@ +import { expect, test } from "@playwright/test"; + +import { setup } from "../test-utils-playwright/stub-endpoints"; + +test("works with non-empty destination folder", 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: [] }, + }, + { + status: "success", + value: { status: "success", response: [] }, + }, + ]; + window._endpointStubs.move = [ + { + status: "success", + delay: 500, + value: { status: "error", type: "notEmpty" }, + }, + { + status: "success", + delay: 500, + value: { status: "error", type: "notEmpty" }, + }, + { + status: "success", + value: { status: "success", response: { errors: [] } }, + }, + ]; + }); + + 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("Destination not empty", { exact: true }), + ).toBeVisible(); + await page.getByText("No", { exact: true }).click(); + await page.getByText("Continue").click(); + await page.getByText("Move", { exact: true }).click(); + await expect( + page.getByText("Destination not empty", { exact: true }), + ).toBeVisible(); + await page.getByText("Yes").click(); + await expect(page.getByText("Done!", { exact: true })).toBeVisible(); + await expect(page.getByText("Successfully moved")).toBeVisible(); + + const moveCalls = getCalls("move"); + expect(moveCalls).toHaveLength(3); + expect(moveCalls[0]).toStrictEqual(["root", "root", true, true, false]); + expect(moveCalls[1]).toStrictEqual(["root", "root", true, true, false]); + expect(moveCalls[2]).toStrictEqual(["root", "root", true, true, true]); +}); diff --git a/__tests__/frontend/non-empty.cy.ts b/__tests__/frontend/non-empty.cy.ts deleted file mode 100644 index cb535cfc..00000000 --- a/__tests__/frontend/non-empty.cy.ts +++ /dev/null @@ -1,47 +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, _, parameters) => { - setTimeout(() => { - if (parameters[4] === true) { - successHandler({ status: "success", response: { errors: [] } }); - } else { - successHandler({ status: "error", type: "notEmpty" }); - } - }, 100); - }, -}); - -it("works with non-empty destination folder", () => { - 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("Destination not empty").should("be.visible"); - cy.contains("No").click(); - cy.contains("Continue").click(); - cy.contains("Move").click(); - cy.contains("Destination not empty").should("be.visible"); - cy.contains("Yes").click(); - cy.contains("Done!"); - cy.contains("Successfully moved").then(() => { - expect(stubs.move).to.have.been.calledWith( - "root", - "root", - true, - true, - true, - ); - }); -});