From 48e6172b6e87649a7e2f0562d0fc0e110c118576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Sun, 22 Oct 2023 18:18:04 +0200 Subject: [PATCH] Ported source and destination folder navigation test --- .../source-destination-selection.spec.ts | 191 ++++++++++++++++++ .../source-destination-selection.cy.ts | 113 ----------- 2 files changed, 191 insertions(+), 113 deletions(-) create mode 100644 __tests__/frontend-playwright/source-destination-selection.spec.ts delete mode 100644 __tests__/frontend/source-destination-selection.cy.ts diff --git a/__tests__/frontend-playwright/source-destination-selection.spec.ts b/__tests__/frontend-playwright/source-destination-selection.spec.ts new file mode 100644 index 00000000..87e628ce --- /dev/null +++ b/__tests__/frontend-playwright/source-destination-selection.spec.ts @@ -0,0 +1,191 @@ +import { expect, test } from "@playwright/test"; + +import { setup } from "../test-utils-playwright/stub-endpoints"; + +test("works with folder selection", async ({ page }) => { + await page.goto("/"); + const getCalls = await setup(page); + + await page.evaluate(() => { + window._endpointStubs.listFolders = [ + { + status: "success", + value: { + status: "success", + response: [], + }, + }, + { + status: "success", + value: { + status: "success", + response: [ + { + id: "ID_DRIVE_1_FOLDER_1", + name: "FOLDER 1 IN DRIVE 1", + }, + { + id: "ID_DRIVE_1_FOLDER_2", + name: "FOLDER 2 IN DRIVE 1", + }, + ], + }, + }, + { + status: "success", + value: { + status: "success", + response: [ + { + id: "ID_MY_DRIVE_FOLDER_1", + name: "FOLDER 1 IN MY DRIVE", + }, + { + id: "ID_MY_DRIVE_FOLDER_2", + name: "FOLDER 2 IN MY DRIVE", + }, + ], + }, + }, + { + status: "success", + value: { + status: "success", + response: [ + { + id: "ID_MY_DRIVE_FOLDER_2_FOLDER_1", + name: "FOLDER 1 IN FOLDER 2 IN MY DRIVE", + }, + { + id: "ID_MY_DRIVE_FOLDER_2_FOLDER_2", + name: "FOLDER 2 IN FOLDER 2 IN MY DRIVE", + }, + ], + }, + }, + { + status: "success", + value: { + status: "success", + response: [ + { + id: "ID_MY_DRIVE_FOLDER_1", + name: "FOLDER 1 IN MY DRIVE", + }, + { + id: "ID_MY_DRIVE_FOLDER_2", + name: "FOLDER 2 IN MY DRIVE", + }, + ], + }, + }, + { + status: "success", + value: { + status: "success", + response: [ + { + id: "ID_MY_DRIVE_FOLDER_1_FOLDER_1", + name: "FOLDER 1 IN FOLDER 1 IN MY DRIVE", + }, + { + id: "ID_MY_DRIVE_FOLDER_1_FOLDER_2", + name: "FOLDER 2 IN FOLDER 1 IN MY DRIVE", + }, + ], + }, + }, + ]; + window._endpointStubs.listSharedDrives = [ + { + status: "success", + value: { + status: "success", + response: [ + { id: "ID_DRIVE_1", name: "DRIVE 1" }, + { id: "ID_DRIVE_2", name: "DRIVE 2" }, + ], + }, + }, + { + status: "success", + value: { + status: "success", + response: [ + { id: "ID_DRIVE_1", name: "DRIVE 1" }, + { id: "ID_DRIVE_2", name: "DRIVE 2" }, + ], + }, + }, + { + status: "success", + value: { + status: "success", + response: [ + { id: "ID_DRIVE_1", name: "DRIVE 1" }, + { id: "ID_DRIVE_2", name: "DRIVE 2" }, + ], + }, + }, + { + status: "success", + value: { + status: "success", + response: [ + { id: "ID_DRIVE_1", name: "DRIVE 1" }, + { id: "ID_DRIVE_2", name: "DRIVE 2" }, + ], + }, + }, + ]; + window._endpointStubs.move = [ + { + 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("DRIVE 2").dblclick(); + await page.getByText("Drive Selection").dblclick(); + await page.getByText("DRIVE 1").dblclick(); + await page.getByText("FOLDER 2 IN DRIVE 1").click(); + await page.getByText("Continue").click(); + await page.getByText("My Drive").dblclick(); + await page.getByText("FOLDER 2 IN MY DRIVE").dblclick(); + await page.getByText("My Drive", { exact: true }).click(); + await page.getByText("FOLDER 1 IN MY DRIVE").dblclick(); + await page.getByText("FOLDER 2 IN FOLDER 1 IN MY DRIVE").click(); + await page.getByText("Continue").click(); + await expect( + page.getByText( + 'contents of the folder "DRIVE 1/FOLDER 2 IN DRIVE 1" into the folder "My Drive/FOLDER 1 IN MY DRIVE/FOLDER 2 IN FOLDER 1 IN 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(); + + const listFolderCalls = getCalls("listFolders"); + expect(listFolderCalls).toHaveLength(6); + expect(listFolderCalls[0]).toStrictEqual(["ID_DRIVE_2"]); + expect(listFolderCalls[1]).toStrictEqual(["ID_DRIVE_1"]); + expect(listFolderCalls[2]).toStrictEqual(["root"]); + expect(listFolderCalls[3]).toStrictEqual(["ID_MY_DRIVE_FOLDER_2"]); + expect(listFolderCalls[4]).toStrictEqual(["root"]); + expect(listFolderCalls[5]).toStrictEqual(["ID_MY_DRIVE_FOLDER_1"]); + + const moveCalls = getCalls("move"); + expect(moveCalls).toHaveLength(1); + expect(moveCalls[0]).toStrictEqual([ + "ID_DRIVE_1_FOLDER_2", + "ID_MY_DRIVE_FOLDER_1_FOLDER_2", + true, + true, + false, + ]); +}); diff --git a/__tests__/frontend/source-destination-selection.cy.ts b/__tests__/frontend/source-destination-selection.cy.ts deleted file mode 100644 index 6bf7cc49..00000000 --- a/__tests__/frontend/source-destination-selection.cy.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { stubEndpoints } from "../test-utils/stubEndpoints"; - -const stubs = stubEndpoints({ - listFolders: (successHandler, _, parameters) => { - switch (parameters[0]) { - case "root": - successHandler({ - status: "success", - response: [ - { - id: "ID_MY_DRIVE_FOLDER_1", - name: "FOLDER 1 IN MY DRIVE", - }, - { - id: "ID_MY_DRIVE_FOLDER_2", - name: "FOLDER 2 IN MY DRIVE", - }, - ], - }); - break; - case "ID_DRIVE_1": - successHandler({ - status: "success", - response: [ - { - id: "ID_DRIVE_1_FOLDER_1", - name: "FOLDER 1 IN DRIVE 1", - }, - { - id: "ID_DRIVE_1_FOLDER_2", - name: "FOLDER 2 IN DRIVE 1", - }, - ], - }); - break; - case "ID_MY_DRIVE_FOLDER_1": - successHandler({ - status: "success", - response: [ - { - id: "ID_MY_DRIVE_FOLDER_1_FOLDER_1", - name: "FOLDER 1 IN FOLDER 1 IN MY DRIVE", - }, - { - id: "ID_MY_DRIVE_FOLDER_1_FOLDER_2", - name: "FOLDER 2 IN FOLDER 1 IN MY DRIVE", - }, - ], - }); - break; - case "ID_MY_DRIVE_FOLDER_2": - successHandler({ - status: "success", - response: [ - { - id: "ID_MY_DRIVE_FOLDER_2_FOLDER_1", - name: "FOLDER 1 IN FOLDER 2 IN MY DRIVE", - }, - { - id: "ID_MY_DRIVE_FOLDER_2_FOLDER_2", - name: "FOLDER 2 IN FOLDER 2 IN MY DRIVE", - }, - ], - }); - break; - } - }, - listSharedDrives: (successHandler) => { - successHandler({ - status: "success", - response: [ - { id: "ID_DRIVE_1", name: "DRIVE 1" }, - { id: "ID_DRIVE_2", name: "DRIVE 2" }, - ], - }); - }, - move: (successHandler) => { - setTimeout(() => { - successHandler({ status: "success", response: { errors: [] } }); - }, 100); - }, -}); - -it("works with folder selection", () => { - cy.visit("http://localhost:8080"); - cy.contains("Shared drive mover"); - cy.contains("Continue").click(); - cy.contains("DRIVE 2").dblclick(); - cy.contains("Drive Selection").dblclick(); - cy.contains("DRIVE 1").dblclick(); - cy.contains("FOLDER 2 IN DRIVE 1").click(); - cy.contains("Continue").click(); - cy.contains("My Drive").dblclick(); - cy.contains("FOLDER 2 IN MY DRIVE").dblclick(); - cy.contains("My Drive").click(); - cy.contains("FOLDER 1 IN MY DRIVE").dblclick(); - cy.contains("FOLDER 2 IN FOLDER 1 IN MY DRIVE").click(); - cy.contains("Continue").click(); - cy.contains( - 'contents of the folder "DRIVE 1/FOLDER 2 IN DRIVE 1" into the folder "My Drive/FOLDER 1 IN MY DRIVE/FOLDER 2 IN FOLDER 1 IN MY DRIVE"', - ); - cy.contains("Move").click(); - cy.contains("Done!"); - cy.contains("Successfully moved").then(() => { - expect(stubs.move).to.have.been.calledOnceWith( - "ID_DRIVE_1_FOLDER_2", - "ID_MY_DRIVE_FOLDER_1_FOLDER_2", - true, - true, - false, - ); - }); -});