mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-17 18:36:18 +02:00
* Initial reword of upload to MVVM. * Update tests * More incremental improvements * Refactor tests to use helper method for composer uploads. * Add drag and drop tests * lint * Add commentary * fixup test * More precise selector * Retarget uploads * lint * fixup * one more type * update snap * Fixup composerUploadFiles * fix import * lint * Copy and paste fixes too * Add tests for pasting * Add tests for pasting files. * Remove redundant fn * rm comment * tidy up * Test cleanup * More clean up * another fix * Use condensed version * Cleanup tests * more cleaning * last bity * s/throw Error/throw new Error/
91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import React from "react";
|
|
import { render, fireEvent } from "jest-matrix-react";
|
|
import { useMockedViewModel } from "@element-hq/web-shared-components";
|
|
|
|
import FileDropTarget from "../../../../src/components/structures/FileDropTarget.tsx";
|
|
import {
|
|
RoomUploadContext,
|
|
type RoomUploadViewActions,
|
|
type RoomUploadViewModel,
|
|
type RoomUploadViewSnapshot,
|
|
} from "../../../../src/viewmodels/room/RoomUploadViewModel.tsx";
|
|
|
|
function FileDropTargetWrapped({
|
|
element,
|
|
snapshot,
|
|
actions,
|
|
}: {
|
|
element: HTMLDivElement;
|
|
snapshot: RoomUploadViewSnapshot;
|
|
actions: Partial<RoomUploadViewActions>;
|
|
}) {
|
|
const mockVm = useMockedViewModel<RoomUploadViewSnapshot, RoomUploadViewActions>(
|
|
snapshot,
|
|
actions as RoomUploadViewActions,
|
|
);
|
|
return (
|
|
<RoomUploadContext.Provider value={mockVm as RoomUploadViewModel}>
|
|
<FileDropTarget parent={element} />
|
|
</RoomUploadContext.Provider>
|
|
);
|
|
}
|
|
|
|
describe("FileDropTarget", () => {
|
|
it("should render nothing when idle", () => {
|
|
const element = document.createElement("div");
|
|
const onFileDrop = jest.fn();
|
|
|
|
const { asFragment } = render(
|
|
<FileDropTargetWrapped
|
|
element={element}
|
|
snapshot={{ mayUpload: true }}
|
|
actions={{ initiateViaDataTransfer: onFileDrop }}
|
|
/>,
|
|
);
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
|
|
it("should render drop file prompt on mouse over with file if permissions allow", () => {
|
|
const element = document.createElement("div");
|
|
const onFileDrop = jest.fn();
|
|
const { asFragment } = render(
|
|
<FileDropTargetWrapped
|
|
element={element}
|
|
snapshot={{ mayUpload: true }}
|
|
actions={{ initiateViaDataTransfer: onFileDrop }}
|
|
/>,
|
|
);
|
|
fireEvent.dragEnter(element, {
|
|
dataTransfer: {
|
|
types: ["Files"],
|
|
},
|
|
});
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
|
|
it("should not render drop file prompt on mouse over with file if permissions do not allow", () => {
|
|
const element = document.createElement("div");
|
|
const onFileDrop = jest.fn();
|
|
const { asFragment } = render(
|
|
<FileDropTargetWrapped
|
|
element={element}
|
|
snapshot={{ mayUpload: false }}
|
|
actions={{ initiateViaDataTransfer: onFileDrop }}
|
|
/>,
|
|
);
|
|
fireEvent.dragEnter(element, {
|
|
dataTransfer: {
|
|
types: ["Files"],
|
|
},
|
|
});
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
});
|