2023-06-15 12:57:58 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-06-15 12:57:58 +01:00
|
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2023-06-15 12:57:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2024-10-14 21:41:58 +05:30
|
|
|
import { render, fireEvent } from "jest-matrix-react";
|
2023-06-15 12:57:58 +01:00
|
|
|
|
2024-10-15 14:57:26 +01:00
|
|
|
import MainSplit from "../../../../src/components/structures/MainSplit";
|
|
|
|
|
import { PosthogAnalytics } from "../../../../src/PosthogAnalytics.ts";
|
2025-10-06 10:23:06 +01:00
|
|
|
import { SDKContext, SdkContextClass } from "../../../../src/contexts/SDKContext.ts";
|
2023-06-15 12:57:58 +01:00
|
|
|
|
|
|
|
|
describe("<MainSplit/>", () => {
|
|
|
|
|
const children = (
|
|
|
|
|
<div>
|
|
|
|
|
Child<span>Foo</span>Bar
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
const panel = <div>Right panel</div>;
|
2025-10-06 10:23:06 +01:00
|
|
|
let sdkContext: SdkContextClass;
|
2023-06-15 12:57:58 +01:00
|
|
|
|
2024-10-04 10:41:00 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
localStorage.clear();
|
2025-10-06 10:23:06 +01:00
|
|
|
sdkContext = new SdkContextClass();
|
2024-10-04 10:41:00 +01:00
|
|
|
});
|
|
|
|
|
|
2023-06-15 12:57:58 +01:00
|
|
|
it("renders", () => {
|
|
|
|
|
const { asFragment, container } = render(
|
2025-10-06 10:23:06 +01:00
|
|
|
<MainSplit children={children} panel={panel} analyticsRoomType="other_room" />,
|
2023-06-15 12:57:58 +01:00
|
|
|
);
|
|
|
|
|
expect(asFragment()).toMatchSnapshot();
|
2024-10-04 10:41:00 +01:00
|
|
|
// Assert it matches the default width of 320
|
|
|
|
|
expect(container.querySelector<HTMLElement>(".mx_RightPanel_ResizeWrapper")!.style.width).toBe("320px");
|
2023-06-15 12:57:58 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("respects defaultSize prop", () => {
|
|
|
|
|
const { asFragment, container } = render(
|
2025-10-06 10:23:06 +01:00
|
|
|
<MainSplit children={children} panel={panel} defaultSize={500} analyticsRoomType="other_room" />,
|
2023-06-15 12:57:58 +01:00
|
|
|
);
|
|
|
|
|
expect(asFragment()).toMatchSnapshot();
|
|
|
|
|
// Assert it matches the default width of 350
|
|
|
|
|
expect(container.querySelector<HTMLElement>(".mx_RightPanel_ResizeWrapper")!.style.width).toBe("500px");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("prefers size stashed in LocalStorage to the defaultSize prop", () => {
|
|
|
|
|
localStorage.setItem("mx_rhs_size_thread", "333");
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<MainSplit
|
|
|
|
|
children={children}
|
|
|
|
|
panel={panel}
|
|
|
|
|
sizeKey="thread"
|
|
|
|
|
defaultSize={400}
|
2024-10-04 10:41:00 +01:00
|
|
|
analyticsRoomType="other_room"
|
2023-06-15 12:57:58 +01:00
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
expect(container.querySelector<HTMLElement>(".mx_RightPanel_ResizeWrapper")!.style.width).toBe("333px");
|
|
|
|
|
});
|
2024-10-04 10:41:00 +01:00
|
|
|
|
|
|
|
|
it("should report to analytics on resize stop", () => {
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<MainSplit
|
|
|
|
|
children={children}
|
|
|
|
|
panel={panel}
|
|
|
|
|
sizeKey="thread"
|
|
|
|
|
defaultSize={400}
|
|
|
|
|
analyticsRoomType="other_room"
|
|
|
|
|
/>,
|
2025-10-06 10:23:06 +01:00
|
|
|
{ wrapper: ({ children }) => <SDKContext.Provider value={sdkContext}>{children}</SDKContext.Provider> },
|
2024-10-04 10:41:00 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const spy = jest.spyOn(PosthogAnalytics.instance, "trackEvent");
|
|
|
|
|
|
|
|
|
|
const handle = container.querySelector(".mx_ResizeHandle--horizontal")!;
|
2025-10-06 10:23:06 +01:00
|
|
|
expect(handle).toBeInTheDocument();
|
2024-10-04 10:41:00 +01:00
|
|
|
fireEvent.mouseDown(handle);
|
2025-03-04 17:03:32 +00:00
|
|
|
fireEvent.resize(handle, { clientX: 0 });
|
2024-10-04 10:41:00 +01:00
|
|
|
fireEvent.mouseUp(handle);
|
|
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalledWith({
|
|
|
|
|
eventName: "WebPanelResize",
|
|
|
|
|
panel: "right",
|
|
|
|
|
roomType: "other_room",
|
|
|
|
|
size: 400,
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-06-15 12:57:58 +01:00
|
|
|
});
|