element-web/apps/web/test/unit-tests/components/views/dialogs/RemoveSectionDialog-test.tsx
Florian Duros c363d2eb82
Room list: edit or remove custom sections (#33283)
* feat(sc): add section menu to section header

* feat(rls): add edit and remove sections

* feat(dialog): add editing mode to CreateSectionDialog

* feat(dialog): add remove section dialog

* feat(vm): wire up vm and stores

* test: update existing snapshots

* test(e2e): add playwright tests to edit and remove a section

* chore: fix remove section i18n key

* fix: able to send empty sections

* chore: update create section editing docs

* chore: remove useless fallback

* chore: add logs when section is unknown

* feat: use different wording when removing an empty section

* fix: only animate the chevron icon in the section header

* fix: change dialog subtitle weight to medium
2026-04-28 10:16:34 +00:00

49 lines
1.9 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 { render, screen } from "jest-matrix-react";
import userEvent from "@testing-library/user-event";
import React from "react";
import { RemoveSectionDialog } from "../../../../../src/components/views/dialogs/RemoveSectionDialog";
describe("RemoveSectionDialog", () => {
const onFinished: jest.Mock = jest.fn();
beforeEach(() => {
jest.resetAllMocks();
});
it("renders the dialog when section is not empty", () => {
const { container } = render(<RemoveSectionDialog onFinished={onFinished} isEmpty={false} />);
expect(container).toMatchSnapshot();
expect(
screen.getByText("The chats in this section will still be available in your chats list."),
).toBeInTheDocument();
});
it("renders the dialog when section is empty", () => {
const { container } = render(<RemoveSectionDialog onFinished={onFinished} isEmpty={true} />);
expect(container).toMatchSnapshot();
expect(
screen.queryByText("The chats in this section will still be available in your chats list."),
).not.toBeInTheDocument();
});
it("calls onFinished with true when remove section is clicked", async () => {
render(<RemoveSectionDialog onFinished={onFinished} isEmpty={false} />);
await userEvent.click(screen.getByRole("button", { name: "Remove section" }));
expect(onFinished).toHaveBeenCalledWith(true);
});
it("calls onFinished with false when the dialog is cancelled", async () => {
render(<RemoveSectionDialog onFinished={onFinished} isEmpty={false} />);
await userEvent.click(screen.getByRole("button", { name: "Cancel" }));
expect(onFinished).toHaveBeenCalledWith(false);
});
});