From 66bbe7f01cfb5f43c5f5dc40fb812da773e42574 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Jul 2026 11:32:34 +0100 Subject: [PATCH] Avoid snapshot in metaspaces order test (#34183) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Avoid snapshot in metaspaces order test Just assert the thing we're actually testing rather than a snapshot because I keep having to update this snapshot every time anything in the left panel changes and it's tedious. * 🐂 * Get all the button roles instead * Favourites & people are gone * Query treeitems and then get the buttons from them --- .../views/spaces/SpacePanel-test.tsx | 19 +- .../__snapshots__/SpacePanel-test.tsx.snap | 311 ------------------ 2 files changed, 16 insertions(+), 314 deletions(-) delete mode 100644 apps/web/test/unit-tests/components/views/spaces/__snapshots__/SpacePanel-test.tsx.snap diff --git a/apps/web/test/unit-tests/components/views/spaces/SpacePanel-test.tsx b/apps/web/test/unit-tests/components/views/spaces/SpacePanel-test.tsx index 598d029f1f..a2e3698ced 100644 --- a/apps/web/test/unit-tests/components/views/spaces/SpacePanel-test.tsx +++ b/apps/web/test/unit-tests/components/views/spaces/SpacePanel-test.tsx @@ -8,7 +8,7 @@ Please see LICENSE files in the repository root for full details. */ import React from "react"; -import { render, screen, fireEvent, act, cleanup, waitFor } from "jest-matrix-react"; +import { render, screen, fireEvent, act, cleanup, waitFor, within } from "jest-matrix-react"; import { mocked } from "jest-mock"; import { type MatrixClient, type Room } from "matrix-js-sdk/src/matrix"; @@ -147,8 +147,21 @@ describe("", () => { const spySettingsStore = jest.spyOn(SettingsStore, "getValue").mockImplementation((setting) => { return setting === "feature_video_rooms" ? true : originalGetValue(setting); }); - const renderResult = render(); - expect(renderResult.asFragment()).toMatchSnapshot(); + render(); + + // Inspect the order of the rendered MetaSpaces, excluding the "Create a space" button. + const tree = screen.getByRole("tree", { name: "Spaces" }); + const spaceButtons = within(tree) + .getAllByRole("treeitem") + .filter((el) => within(el).queryByRole("button", { name: "Create a space" }) === null); + + const metaSpaceLabels = Array.from(spaceButtons).map((li) => + within(li) + .getByRole("button", { name: /^(?!Options$).*/ }) // filter out the 'options' buttons within the buttons + .getAttribute("aria-label"), + ); + expect(metaSpaceLabels).toEqual(["Home", "Other rooms", "Conferences"]); + spySettingsStore.mockRestore(); }); diff --git a/apps/web/test/unit-tests/components/views/spaces/__snapshots__/SpacePanel-test.tsx.snap b/apps/web/test/unit-tests/components/views/spaces/__snapshots__/SpacePanel-test.tsx.snap deleted file mode 100644 index efebdcdbc8..0000000000 --- a/apps/web/test/unit-tests/components/views/spaces/__snapshots__/SpacePanel-test.tsx.snap +++ /dev/null @@ -1,311 +0,0 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing - -exports[` should show all activated MetaSpaces in the correct order 1`] = ` - - - -`;