From 79cde60f86304e0a9e3972c7a0cbf47961f6461e Mon Sep 17 00:00:00 2001 From: origami-z <5257855+origami-z@users.noreply.github.com> Date: Tue, 21 May 2024 16:21:04 +0100 Subject: [PATCH] Add test for simple view with new dropdown --- .../ui-src/__tests__/SimpleView.spec.tsx | 52 ++++++++++++++++--- .../copy-manager/ui-src/view/AdvancedView.tsx | 2 +- .../copy-manager/ui-src/view/SimpleView.tsx | 10 ++-- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/packages/copy-manager/ui-src/__tests__/SimpleView.spec.tsx b/packages/copy-manager/ui-src/__tests__/SimpleView.spec.tsx index 78db0a0..b89979d 100644 --- a/packages/copy-manager/ui-src/__tests__/SimpleView.spec.tsx +++ b/packages/copy-manager/ui-src/__tests__/SimpleView.spec.tsx @@ -1,4 +1,4 @@ -import { fireEvent, render, screen } from "@testing-library/react"; +import { fireEvent, render, screen, waitFor } from "@testing-library/react"; import userEvents from "@testing-library/user-event"; import React from "react"; import { beforeEach, describe, expect, test, vi } from "vitest"; @@ -22,20 +22,58 @@ describe("SimpleView", () => { "*" ); }); - test.skip("reacts to failure message sent from Figma", async () => { + test("Adds drop file and change revision via dropdown", async () => { + const csvData = `id,page,name,characters,v2,listOption,headingLevel +$2:1,Page 1,Page Title,Features,Features v2,NONE,1 +$2:1,Page 1,Heading,Body,,NONE,0 + `; + const file = new File([csvData as BlobPart], "chucknorris.csv", { + type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + }); + fireEvent.drop(screen.getByLabelText("File drop zone"), { + dataTransfer: { files: [file], types: ["Files"] }, + }); + + await waitFor(() => { + expect(window.parent.postMessage).toHaveBeenCalledWith( + expect.objectContaining({ + pluginMessage: { + type: "detect-available-lang-from-csv", + csvString: csvData, + }, + }), + "*" + ); + }); + fireEvent( window, new MessageEvent("message", { data: { pluginMessage: { - type: "created-nodes-result", - success: false, + type: "available-lang-from-csv", + langs: ["v2"], }, }, }) ); - expect( - await screen.findByRole("button", { name: /❌/i }) - ).toBeInTheDocument(); + + await userEvents.click( + await screen.findByRole("combobox", { name: "Version" }) + ); + await userEvents.click(screen.getByRole("option", { name: "v2" })); + + await userEvents.click(screen.getByRole("button", { name: "Update" })); + + expect(window.parent.postMessage).toHaveBeenCalledWith( + expect.objectContaining({ + pluginMessage: { + type: "update-content-with-lang", + lang: "v2", // selected 2 lines above + persistInFigma: true, + }, + }), + "*" + ); }); }); diff --git a/packages/copy-manager/ui-src/view/AdvancedView.tsx b/packages/copy-manager/ui-src/view/AdvancedView.tsx index 9e5212a..4a18c57 100644 --- a/packages/copy-manager/ui-src/view/AdvancedView.tsx +++ b/packages/copy-manager/ui-src/view/AdvancedView.tsx @@ -253,7 +253,7 @@ export const AdvancedView = () => { }} /> - + Format { {csvFile === null ? ( - + Drop files here or @@ -151,9 +155,7 @@ export const SimpleView = () => { )} - + ); };