mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-16 18:06:17 +02:00
* Add shared event presentation context * Add app-web event presentation mapper * Wire event presentation provider into app timelines * Add Storybook controls for event layout and density * Wire compact density through app/web event presentation provider * Use event presentation density for URL previews * Move TileErrorView layout to event presentation context * Minor fix and updated snapshot * Updated snapshots for url preview group * Prettier fix * Restore removed story to fix missing playwright test * Updates after review comments * Fix prettier issue
58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
/*
|
|
Copyright 2026 Element Creations 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 { act, render, screen, waitFor } from "jest-matrix-react";
|
|
import { useEventPresentation } from "@element-hq/web-shared-components";
|
|
|
|
import { Layout } from "../../../src/settings/enums/Layout";
|
|
import {
|
|
EventPresentationContextProvider,
|
|
getEventPresentation,
|
|
} from "../../../src/utils/EventPresentationContextProvider";
|
|
import SettingsStore from "../../../src/settings/SettingsStore";
|
|
import { SettingLevel } from "../../../src/settings/SettingLevel";
|
|
|
|
const PresentationProbe: React.FC = () => {
|
|
const { layout, density } = useEventPresentation();
|
|
|
|
return <div data-testid="presentation">{`${layout}:${density}`}</div>;
|
|
};
|
|
|
|
describe("EventPresentationContextProvider", () => {
|
|
beforeEach(async () => {
|
|
await SettingsStore.setValue("useCompactLayout", null, SettingLevel.DEVICE, false);
|
|
});
|
|
|
|
it.each([
|
|
[Layout.Group, false, { layout: "group", density: "default" }],
|
|
[Layout.Group, true, { layout: "group", density: "compact" }],
|
|
[Layout.Bubble, false, { layout: "bubble", density: "default" }],
|
|
[Layout.Bubble, true, { layout: "bubble", density: "default" }],
|
|
[Layout.IRC, false, { layout: "irc", density: "default" }],
|
|
[Layout.IRC, true, { layout: "irc", density: "default" }],
|
|
])("maps %s with compact=%s", (layout, useCompactLayout, expected) => {
|
|
expect(getEventPresentation(layout, useCompactLayout)).toEqual(expected);
|
|
});
|
|
|
|
it("updates provider density when compact layout changes", async () => {
|
|
render(
|
|
<EventPresentationContextProvider layout={Layout.Group}>
|
|
<PresentationProbe />
|
|
</EventPresentationContextProvider>,
|
|
);
|
|
|
|
expect(screen.getByTestId("presentation")).toHaveTextContent("group:default");
|
|
|
|
await act(async () => {
|
|
await SettingsStore.setValue("useCompactLayout", null, SettingLevel.DEVICE, true);
|
|
});
|
|
|
|
await waitFor(() => expect(screen.getByTestId("presentation")).toHaveTextContent("group:compact"));
|
|
});
|
|
});
|