Add test for adding actor variables to clipboard
@@ -12,6 +12,7 @@ jest.mock("electron");
const mockedClipboard = mocked(clipboard, true);
test("Should be able to copy actor to clipboard", async () => {
+ mockedClipboard.writeText.mockClear();
const store = ({
getState: () => ({
@@ -20,25 +21,97 @@ test("Should be able to copy actor to clipboard", async () => {
entities: {
customEvents: {
entities: {},
- ids: []
- }
- }
- }
- }
+ ids: [],
+ },
+ variables: {
+ entities: {},
+ ids: [],
+ },
+ },
+ },
+ },
}),
dispatch: jest.fn(),
} as unknown) as MiddlewareAPI<Dispatch<AnyAction>, RootState>;
const next = jest.fn();
const action = actions.copyActor({
- ...dummyActor
- })
+ ...dummyActor,
+ });
middleware(store)(next)(action);
expect(next).toHaveBeenCalledWith(action);
- expect(mockedClipboard.writeText).toHaveBeenCalledWith(JSON.stringify({
+ expect(mockedClipboard.writeText).toHaveBeenCalledWith(
+ JSON.stringify(
+ {
actor: dummyActor,
- __type: "actor"
- }, null, 4));
+ __type: "actor",
+ },
+ null,
+ 4
+ )
+ );
+});
+
+test("Should be include referenced variables when copying actor", async () => {
+ mockedClipboard.writeText.mockClear();
+
+ const store = ({
+ getState: () => ({
+ project: {
+ present: {
+ entities: {
+ customEvents: {
+ entities: {},
+ ids: [],
+ },
+ variables: {
+ entities: {
+ actor1_L0: {
+ id: "actor1_L0",
+ name: "Actor Local",
+ },
+ actor2_L0: {
+ id: "actor2_L0",
+ name: "Actor Local",
+ },
+ },
+ ids: ["actor1_L0", "actor2_L0"],
+ },
+ },
+ },
+ },
+ }),
+ dispatch: jest.fn(),
+ } as unknown) as MiddlewareAPI<Dispatch<AnyAction>, RootState>;
+
+ const next = jest.fn();
+ const action = actions.copyActor({
+ ...dummyActor,
+ id: "actor1",
+ });
+
+ middleware(store)(next)(action);
+
+ expect(next).toHaveBeenCalledWith(action);
+ expect(mockedClipboard.writeText).toHaveBeenCalledWith(
+ JSON.stringify(
+ {
+ actor: {
+ ...dummyActor,
+ id: "actor1",
+ },
+ __type: "actor",
+ __variables: [
+ {
+ id: "actor1_L0",
+ name: "Actor Local",
+ },
+ ],
+ },
+ null,
+ 4
+ )
+ );
});
