Avoid snapshot in metaspaces order test (#34183)
* 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
This commit is contained in:
@@ -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("<SpacePanel />", () => {
|
||||
const spySettingsStore = jest.spyOn(SettingsStore, "getValue").mockImplementation((setting) => {
|
||||
return setting === "feature_video_rooms" ? true : originalGetValue(setting);
|
||||
});
|
||||
const renderResult = render(<SpacePanel />);
|
||||
expect(renderResult.asFragment()).toMatchSnapshot();
|
||||
render(<SpacePanel />);
|
||||
|
||||
// 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();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user