Skip to content

Commit

Permalink
Fix file drop zone not responding to file browser (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
origami-z authored Jun 13, 2024
1 parent 6a386d0 commit f72918c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
55 changes: 55 additions & 0 deletions packages/copy-manager/ui-src/__tests__/SimpleView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,61 @@ $2:1,Page 1,Heading,Body,,NONE,0

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,
},
}),
"*"
);
});
test("Pick a file from button 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",
});
const fileInput = document.querySelector(`input[type='file']`);
fireEvent.change(fileInput!, {
target: { files: [file] },
});

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: "available-lang-from-csv",
langs: ["v2"],
},
},
})
);

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: {
Expand Down
7 changes: 2 additions & 5 deletions packages/copy-manager/ui-src/view/SimpleView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ export const SimpleView = () => {
);
};

const onFileDrop = (
_: React.DragEvent<HTMLDivElement>,
files: readonly File[]
) => {
const onFileDrop = (_: any, files: readonly File[]) => {
if (files.length && files[0] !== null) {
const csv = files[0];
setCsvFile(csv);
Expand Down Expand Up @@ -126,7 +123,7 @@ export const SimpleView = () => {
>
<FileDropZoneIcon />
<strong>Drop files here or</strong>
<FileDropZoneTrigger accept=".csv" />
<FileDropZoneTrigger accept=".csv" onChange={onFileDrop} />
</FileDropZone>
) : (
<StackLayout gap={1}>
Expand Down

0 comments on commit f72918c

Please sign in to comment.