Skip to content

Commit

Permalink
Add test for simple view with new dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
origami-z committed May 21, 2024
1 parent 76a76e6 commit 79cde60
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
52 changes: 45 additions & 7 deletions packages/copy-manager/ui-src/__tests__/SimpleView.spec.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
},
}),
"*"
);
});
});
2 changes: 1 addition & 1 deletion packages/copy-manager/ui-src/view/AdvancedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export const AdvancedView = () => {
}}
/>
</FormField>
<FormField style={{ width: 64 }}>
<FormField style={{ width: 68 }}>
<FormFieldLabel>Format</FormFieldLabel>
<Dropdown
selected={[selectedExportFormat]}
Expand Down
10 changes: 6 additions & 4 deletions packages/copy-manager/ui-src/view/SimpleView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ export const SimpleView = () => {
<StackLayout className="simple-view" align="center">
<Button onClick={onExportCsv}>Export CSV</Button>
{csvFile === null ? (
<FileDropZone style={{ width: 300 }} onDrop={onFileDrop}>
<FileDropZone
style={{ width: 300 }}
onDrop={onFileDrop}
aria-label="File drop zone"
>
<FileDropZoneIcon />
<strong>Drop files here or</strong>
<FileDropZoneTrigger accept=".csv" />
Expand Down Expand Up @@ -151,9 +155,7 @@ export const SimpleView = () => {
</Dropdown>
</FormField>
)}
<Button onClick={onUpdateCsv} disabled={!revisionsAvailable}>
Update
</Button>
<Button onClick={onUpdateCsv}>Update</Button>
</StackLayout>
);
};

0 comments on commit 79cde60

Please sign in to comment.