From dd6097c5687eb86510721203edd5238632949095 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 21 Aug 2023 10:39:20 +0100 Subject: [PATCH] Polish & delabs `Exploring public spaces` feature (#11423) * Iterate search public spaces UX * Tweak iconography in spotlight * Delabs `Exploring public spaces` * Tweak msc3827 v1.4 support discovery * i18n * Delete stale test * Fix tests * Iterate * Iterate PR based on review * Improve types * Add shortcut to search for public spaces to create space menu * Update import * Add org.matrix.msc3827.stable filtering * Fix tests * silence some errors --- cypress/e2e/spotlight/spotlight.spec.ts | 12 +-- res/css/views/dialogs/_SpotlightDialog.pcss | 13 ++- res/img/element-icons/spaces.svg | 3 + src/components/structures/MatrixChat.tsx | 15 +++- src/components/structures/RoomSearch.tsx | 5 +- .../views/dialogs/spotlight/Filter.ts | 21 +++++ .../dialogs/spotlight/SpotlightDialog.tsx | 90 +++++++++---------- .../views/spaces/SpaceCreateMenu.tsx | 28 +++++- .../spaces/SpaceSettingsVisibilityTab.tsx | 4 +- src/dispatcher/actions.ts | 5 ++ .../payloads/OpenSpotlightPayload.ts | 26 ++++++ src/hooks/spotlight/useDebouncedCallback.ts | 2 +- src/i18n/strings/en_EN.json | 9 +- src/settings/Settings.tsx | 14 --- .../views/dialogs/SpotlightDialog-test.tsx | 25 +----- .../tabs/user/LabsUserSettingsTab-test.tsx | 8 +- .../views/spaces/SpacePanel-test.tsx | 7 +- 17 files changed, 180 insertions(+), 107 deletions(-) create mode 100644 res/img/element-icons/spaces.svg create mode 100644 src/components/views/dialogs/spotlight/Filter.ts create mode 100644 src/dispatcher/payloads/OpenSpotlightPayload.ts diff --git a/cypress/e2e/spotlight/spotlight.spec.ts b/cypress/e2e/spotlight/spotlight.spec.ts index b85e110398..d7ce14eff9 100644 --- a/cypress/e2e/spotlight/spotlight.spec.ts +++ b/cypress/e2e/spotlight/spotlight.spec.ts @@ -218,20 +218,20 @@ describe("Spotlight", () => { cy.openSpotlightDialog().within(() => { cy.wait(1000); // wait for the dialog to settle, otherwise our keypresses might race with an update - // initially, publicrooms should be highlighted (because there are no other suggestions) - cy.get("#mx_SpotlightDialog_button_explorePublicRooms").should("have.attr", "aria-selected", "true"); + // initially, public spaces should be highlighted (because there are no other suggestions) + cy.get("#mx_SpotlightDialog_button_explorePublicSpaces").should("have.attr", "aria-selected", "true"); - // hitting enter should enable the publicrooms filter + // hitting enter should enable the public rooms filter cy.spotlightSearch().type("{enter}"); - cy.get(".mx_SpotlightDialog_filter").should("contain", "Public rooms"); + cy.get(".mx_SpotlightDialog_filter").should("contain", "Public spaces"); cy.spotlightSearch().type("{backspace}"); cy.get(".mx_SpotlightDialog_filter").should("not.exist"); cy.spotlightSearch().type("{downArrow}"); cy.spotlightSearch().type("{downArrow}"); - cy.get("#mx_SpotlightDialog_button_startChat").should("have.attr", "aria-selected", "true"); + cy.get("#mx_SpotlightDialog_button_explorePublicRooms").should("have.attr", "aria-selected", "true"); cy.spotlightSearch().type("{enter}"); - cy.get(".mx_SpotlightDialog_filter").should("contain", "People"); + cy.get(".mx_SpotlightDialog_filter").should("contain", "Public rooms"); cy.spotlightSearch().type("{backspace}"); cy.get(".mx_SpotlightDialog_filter").should("not.exist"); }); diff --git a/res/css/views/dialogs/_SpotlightDialog.pcss b/res/css/views/dialogs/_SpotlightDialog.pcss index 4e811ecef1..5c2f5b6717 100644 --- a/res/css/views/dialogs/_SpotlightDialog.pcss +++ b/res/css/views/dialogs/_SpotlightDialog.pcss @@ -97,7 +97,11 @@ limitations under the License. } &.mx_SpotlightDialog_filterPublicRooms::before { - mask-image: url("$(res)/img/element-icons/roomlist/explore.svg"); + mask-image: url("$(res)/img/element-icons/roomlist/hash-circle.svg"); + } + + &.mx_SpotlightDialog_filterPublicSpaces::before { + mask-image: url("$(res)/img/element-icons/spaces.svg"); } .mx_SpotlightDialog_filter--close { @@ -408,6 +412,7 @@ limitations under the License. .mx_SpotlightDialog_startChat, .mx_SpotlightDialog_joinRoomAlias, .mx_SpotlightDialog_explorePublicRooms, + .mx_SpotlightDialog_explorePublicSpaces, .mx_SpotlightDialog_startGroupChat { padding-left: $spacing-32; position: relative; @@ -436,7 +441,11 @@ limitations under the License. } .mx_SpotlightDialog_explorePublicRooms::before { - mask-image: url("$(res)/img/element-icons/roomlist/explore.svg"); + mask-image: url("$(res)/img/element-icons/roomlist/hash-circle.svg"); + } + + .mx_SpotlightDialog_explorePublicSpaces::before { + mask-image: url("$(res)/img/element-icons/spaces.svg"); } .mx_SpotlightDialog_startGroupChat::before { diff --git a/res/img/element-icons/spaces.svg b/res/img/element-icons/spaces.svg new file mode 100644 index 0000000000..7183b4eca9 --- /dev/null +++ b/res/img/element-icons/spaces.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 563e228088..9002beaa11 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -140,12 +140,13 @@ import { SdkContextClass, SDKContext } from "../../contexts/SDKContext"; import { viewUserDeviceSettings } from "../../actions/handlers/viewUserDeviceSettings"; import { cleanUpBroadcasts, VoiceBroadcastResumer } from "../../voice-broadcast"; import GenericToast from "../views/toasts/GenericToast"; -import RovingSpotlightDialog, { Filter } from "../views/dialogs/spotlight/SpotlightDialog"; +import RovingSpotlightDialog from "../views/dialogs/spotlight/SpotlightDialog"; import { findDMForUser } from "../../utils/dm/findDMForUser"; import { Linkify } from "../../HtmlUtils"; import { NotificationColor } from "../../stores/notifications/NotificationColor"; import { UserTab } from "../views/dialogs/UserTab"; import { shouldSkipSetupEncryption } from "../../utils/crypto/shouldSkipSetupEncryption"; +import { Filter } from "../views/dialogs/spotlight/Filter"; // legacy export export { default as Views } from "../../Views"; @@ -898,6 +899,18 @@ export default class MatrixChat extends React.PureComponent { break; } + case Action.OpenSpotlight: + Modal.createDialog( + RovingSpotlightDialog, + { + initialText: payload.initialText, + initialFilter: payload.initialFilter, + }, + "mx_SpotlightDialog_wrapper", + false, + true, + ); + break; } }; diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index a387a2e0d5..f20943c5a8 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -22,9 +22,8 @@ import defaultDispatcher from "../../dispatcher/dispatcher"; import { ActionPayload } from "../../dispatcher/payloads"; import { IS_MAC, Key } from "../../Keyboard"; import { _t } from "../../languageHandler"; -import Modal from "../../Modal"; -import SpotlightDialog from "../views/dialogs/spotlight/SpotlightDialog"; import AccessibleButton from "../views/elements/AccessibleButton"; +import { Action } from "../../dispatcher/actions"; interface IProps { isMinimized: boolean; @@ -44,7 +43,7 @@ export default class RoomSearch extends React.PureComponent { } private openSpotlight(): void { - Modal.createDialog(SpotlightDialog, {}, "mx_SpotlightDialog_wrapper", false, true); + defaultDispatcher.fire(Action.OpenSpotlight); } private onAction = (payload: ActionPayload): void => { diff --git a/src/components/views/dialogs/spotlight/Filter.ts b/src/components/views/dialogs/spotlight/Filter.ts new file mode 100644 index 0000000000..11cdb6dc6b --- /dev/null +++ b/src/components/views/dialogs/spotlight/Filter.ts @@ -0,0 +1,21 @@ +/* +Copyright 2021 - 2023 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +export enum Filter { + People, + PublicRooms, + PublicSpaces, +} diff --git a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx index 886f78d4da..6f787e80e9 100644 --- a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx +++ b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx @@ -71,7 +71,6 @@ import DecoratedRoomAvatar from "../../avatars/DecoratedRoomAvatar"; import { SearchResultAvatar } from "../../avatars/SearchResultAvatar"; import { NetworkDropdown } from "../../directory/NetworkDropdown"; import AccessibleButton, { ButtonEvent } from "../../elements/AccessibleButton"; -import LabelledCheckbox from "../../elements/LabelledCheckbox"; import Spinner from "../../elements/Spinner"; import NotificationBadge from "../../rooms/NotificationBadge"; import BaseDialog from "../BaseDialog"; @@ -85,6 +84,7 @@ import RoomAvatar from "../../avatars/RoomAvatar"; import { useFeatureEnabled } from "../../../../hooks/useSettings"; import { filterBoolean } from "../../../../utils/arrays"; import { transformSearchTerm } from "../../../../utils/SearchInput"; +import { Filter } from "./Filter"; const MAX_RECENT_SEARCHES = 10; const SECTION_LIMIT = 50; // only show 50 results per section for performance reasons @@ -100,11 +100,11 @@ function refIsForRecentlyViewed(ref?: RefObject): boolean { return ref?.current?.id?.startsWith("mx_SpotlightDialog_button_recentlyViewed_") === true; } -function getRoomTypes(showRooms: boolean, showSpaces: boolean): Set { +function getRoomTypes(filter: Filter | null): Set { const roomTypes = new Set(); - if (showRooms) roomTypes.add(null); - if (showSpaces) roomTypes.add(RoomType.Space); + if (filter === Filter.PublicRooms) roomTypes.add(null); + if (filter === Filter.PublicSpaces) roomTypes.add(RoomType.Space); return roomTypes; } @@ -114,12 +114,7 @@ enum Section { Rooms, Spaces, Suggestions, - PublicRooms, -} - -export enum Filter { - People, - PublicRooms, + PublicRoomsAndSpaces, } function filterToLabel(filter: Filter): string { @@ -128,6 +123,8 @@ function filterToLabel(filter: Filter): string { return _t("People"); case Filter.PublicRooms: return _t("Public rooms"); + case Filter.PublicSpaces: + return _t("Public spaces"); } } @@ -168,8 +165,8 @@ const isMemberResult = (result: any): result is IMemberResult => !!result?.membe const toPublicRoomResult = (publicRoom: IPublicRoomsChunkRoom): IPublicRoomResult => ({ publicRoom, - section: Section.PublicRooms, - filter: [Filter.PublicRooms], + section: Section.PublicRoomsAndSpaces, + filter: [Filter.PublicRooms, Filter.PublicSpaces], query: filterBoolean([ publicRoom.room_id.toLowerCase(), publicRoom.canonical_alias?.toLowerCase(), @@ -308,7 +305,16 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n const [inviteLinkCopied, setInviteLinkCopied] = useState(false); const trimmedQuery = useMemo(() => query.trim(), [query]); - const exploringPublicSpacesEnabled = useFeatureEnabled("feature_exploring_public_spaces"); + const [supportsSpaceFiltering, setSupportsSpaceFiltering] = useState(true); // assume it does until we find out it doesn't + useEffect(() => { + cli.isVersionSupported("v1.4") + .then((supported) => { + return supported || cli.doesServerSupportUnstableFeature("org.matrix.msc3827.stable"); + }) + .then((supported) => { + setSupportsSpaceFiltering(supported); + }); + }, [cli]); const { loading: publicRoomsLoading, @@ -319,21 +325,23 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n search: searchPublicRooms, error: publicRoomsError, } = usePublicRoomDirectory(); - const [showRooms, setShowRooms] = useState(true); - const [showSpaces, setShowSpaces] = useState(false); const { loading: peopleLoading, users: userDirectorySearchResults, search: searchPeople } = useUserDirectory(); const { loading: profileLoading, profile, search: searchProfileInfo } = useProfileInfo(); const searchParams: [IDirectoryOpts] = useMemo( () => [ { query: trimmedQuery, - roomTypes: getRoomTypes(showRooms, showSpaces), + roomTypes: getRoomTypes(filter), limit: SECTION_LIMIT, }, ], - [trimmedQuery, showRooms, showSpaces], + [trimmedQuery, filter], + ); + useDebouncedCallback( + filter === Filter.PublicRooms || filter === Filter.PublicSpaces, + searchPublicRooms, + searchParams, ); - useDebouncedCallback(filter === Filter.PublicRooms, searchPublicRooms, searchParams); useDebouncedCallback(filter === Filter.People, searchPeople, searchParams); useDebouncedCallback(filter === Filter.People, searchProfileInfo, searchParams); @@ -403,7 +411,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n [Section.Rooms]: [], [Section.Spaces]: [], [Section.Suggestions]: [], - [Section.PublicRooms]: [], + [Section.PublicRoomsAndSpaces]: [], }; // Group results in their respective sections @@ -436,7 +444,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n results[entry.section].push(entry); }); - } else if (filter === Filter.PublicRooms) { + } else if (filter === Filter.PublicRooms || filter === Filter.PublicSpaces) { // return all results for public rooms if no query is given possibleResults.forEach((entry) => { if (isPublicRoomResult(entry)) { @@ -549,6 +557,15 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n {trimmedQuery ? _t('Use "%(query)s" to search', { query }) : _t("Search for")}
+ {filter !== Filter.PublicSpaces && supportsSpaceFiltering && ( + + )} {filter !== Filter.PublicRooms && (
); - } else if (trimmedQuery && filter === Filter.PublicRooms) { + } else if (trimmedQuery && (filter === Filter.PublicRooms || filter === Filter.PublicSpaces)) { hiddenResultsSection = (

{_t("Some results may be hidden")}

@@ -1218,6 +1217,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n className={classNames("mx_SpotlightDialog_filter", { mx_SpotlightDialog_filterPeople: filter === Filter.People, mx_SpotlightDialog_filterPublicRooms: filter === Filter.PublicRooms, + mx_SpotlightDialog_filterPublicSpaces: filter === Filter.PublicSpaces, })} > {filterToLabel(filter)} diff --git a/src/components/views/spaces/SpaceCreateMenu.tsx b/src/components/views/spaces/SpaceCreateMenu.tsx index d24ad9fb1f..83e50858b5 100644 --- a/src/components/views/spaces/SpaceCreateMenu.tsx +++ b/src/components/views/spaces/SpaceCreateMenu.tsx @@ -24,6 +24,7 @@ import React, { useState, ChangeEvent, ReactNode, + useEffect, } from "react"; import classNames from "classnames"; import { @@ -48,6 +49,9 @@ import withValidation from "../elements/Validation"; import RoomAliasField from "../elements/RoomAliasField"; import { getKeyBindingsManager } from "../../../KeyBindingsManager"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; +import defaultDispatcher from "../../../dispatcher/dispatcher"; +import { Action } from "../../../dispatcher/actions"; +import { Filter } from "../dialogs/spotlight/Filter"; export const createSpace = async ( client: MatrixClient, @@ -225,6 +229,17 @@ const SpaceCreateMenu: React.FC<{ const [avatar, setAvatar] = useState(undefined); const [topic, setTopic] = useState(""); + const [supportsSpaceFiltering, setSupportsSpaceFiltering] = useState(true); // assume it does until we find out it doesn't + useEffect(() => { + cli.isVersionSupported("v1.4") + .then((supported) => { + return supported || cli.doesServerSupportUnstableFeature("org.matrix.msc3827.stable"); + }) + .then((supported) => { + setSupportsSpaceFiltering(supported); + }); + }, [cli]); + const onSpaceCreateClick = async (e: ButtonEvent): Promise => { e.preventDefault(); if (busy) return; @@ -258,6 +273,13 @@ const SpaceCreateMenu: React.FC<{ } }; + const onSearchClick = (): void => { + defaultDispatcher.dispatch({ + action: Action.OpenSpotlight, + initialFilter: Filter.PublicSpaces, + }); + }; + let body; if (visibility === null) { body = ( @@ -283,7 +305,11 @@ const SpaceCreateMenu: React.FC<{ onClick={() => setVisibility(Visibility.Private)} /> -

{_t("To join a space you'll need an invite.")}

+ {supportsSpaceFiltering && ( + + {_t("Search for public spaces")} + + )} ); } else { diff --git a/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx b/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx index 75df665b90..a2047ca950 100644 --- a/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx +++ b/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx @@ -40,7 +40,9 @@ const SpaceSettingsVisibilityTab: React.FC = ({ matrixClient: cli, space const [error, setError] = useState(""); const serverSupportsExploringSpaces = useAsyncMemo( async (): Promise => { - return cli.doesServerSupportUnstableFeature("org.matrix.msc3827.stable"); + return cli.isVersionSupported("v1.4").then((supported) => { + return supported || cli.doesServerSupportUnstableFeature("org.matrix.msc3827.stable"); + }); }, [cli], false, diff --git a/src/dispatcher/actions.ts b/src/dispatcher/actions.ts index b08e09141d..8b699cbec2 100644 --- a/src/dispatcher/actions.ts +++ b/src/dispatcher/actions.ts @@ -366,4 +366,9 @@ export enum Action { * Fired when requesting to cancel an ask to join a room. Use with a CancelAskToJoinPayload. */ CancelAskToJoin = "cancel_ask_to_join", + + /** + * Fired when we want to open spotlight search. Use with a OpenSpotlightPayload. + */ + OpenSpotlight = "open_spotlight", } diff --git a/src/dispatcher/payloads/OpenSpotlightPayload.ts b/src/dispatcher/payloads/OpenSpotlightPayload.ts new file mode 100644 index 0000000000..d3c8b82d68 --- /dev/null +++ b/src/dispatcher/payloads/OpenSpotlightPayload.ts @@ -0,0 +1,26 @@ +/* +Copyright 2023 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { Action } from "../actions"; +import { ActionPayload } from "../payloads"; +import { Filter } from "../../components/views/dialogs/spotlight/Filter"; + +export interface OpenSpotlightPayload extends ActionPayload { + action: Action.OpenSpotlight; + + initialFilter?: Filter; + initialText?: string; +} diff --git a/src/hooks/spotlight/useDebouncedCallback.ts b/src/hooks/spotlight/useDebouncedCallback.ts index e7524bf932..eb681e7a06 100644 --- a/src/hooks/spotlight/useDebouncedCallback.ts +++ b/src/hooks/spotlight/useDebouncedCallback.ts @@ -20,7 +20,7 @@ const DEBOUNCE_TIMEOUT = 100; export function useDebouncedCallback( enabled: boolean, - callback: (...params: T) => void, + callback: (...params: T) => unknown, params: T, ): void { useEffect(() => { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 64a3bb662e..9fb7f99f7f 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -992,8 +992,6 @@ "New Notification Settings": "New Notification Settings", "Notification Settings": "Notification Settings", "Introducing a simpler way to change your notification settings. Customize your %(brand)s, just the way you like.": "Introducing a simpler way to change your notification settings. Customize your %(brand)s, just the way you like.", - "Explore public spaces in the new search dialog": "Explore public spaces in the new search dialog", - "Requires your server to support the stable version of MSC3827": "Requires your server to support the stable version of MSC3827", "Let moderators hide messages pending moderation.": "Let moderators hide messages pending moderation.", "Report to moderators": "Report to moderators", "In rooms that support moderation, the “Report” button will let you report abuse to room moderators.": "In rooms that support moderation, the “Report” button will let you report abuse to room moderators.", @@ -1269,7 +1267,7 @@ "Open space for anyone, best for communities": "Open space for anyone, best for communities", "Private": "Private", "Invite only, best for yourself or teams": "Invite only, best for yourself or teams", - "To join a space you'll need an invite.": "To join a space you'll need an invite.", + "Search for public spaces": "Search for public spaces", "Go back": "Go back", "Your public space": "Your public space", "Your private space": "Your private space", @@ -3254,14 +3252,13 @@ "one": "%(count)s Member" }, "Public rooms": "Public rooms", + "Public spaces": "Public spaces", "Use \"%(query)s\" to search": "Use \"%(query)s\" to search", "Search for": "Search for", "View": "View", "Spaces you're in": "Spaces you're in", - "You cannot search for rooms that are neither a room nor a space": "You cannot search for rooms that are neither a room nor a space", "Failed to query public rooms": "Failed to query public rooms", - "Show rooms": "Show rooms", - "Show spaces": "Show spaces", + "Failed to query public spaces": "Failed to query public spaces", "Other rooms in %(spaceName)s": "Other rooms in %(spaceName)s", "Join %(roomAddress)s": "Join %(roomAddress)s", "Some results may be hidden for privacy": "Some results may be hidden for privacy", diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index ceed24d183..7592c21209 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -252,20 +252,6 @@ export const SETTINGS: { [setting: string]: ISetting } = { ), }, }, - "feature_exploring_public_spaces": { - isFeature: true, - labsGroup: LabGroup.Spaces, - displayName: _td("Explore public spaces in the new search dialog"), - supportedLevels: LEVELS_FEATURE, - default: false, - controller: new ServerSupportUnstableFeatureController( - "feature_exploring_public_spaces", - defaultWatchManager, - [["org.matrix.msc3827.stable"]], - "v1.4", - _td("Requires your server to support the stable version of MSC3827"), - ), - }, "feature_msc3531_hide_messages_pending_moderation": { isFeature: true, labsGroup: LabGroup.Moderation, diff --git a/test/components/views/dialogs/SpotlightDialog-test.tsx b/test/components/views/dialogs/SpotlightDialog-test.tsx index 0a0c1eb6c6..44fd98c9f6 100644 --- a/test/components/views/dialogs/SpotlightDialog-test.tsx +++ b/test/components/views/dialogs/SpotlightDialog-test.tsx @@ -27,7 +27,8 @@ import { import sanitizeHtml from "sanitize-html"; import { fireEvent, render, screen } from "@testing-library/react"; -import SpotlightDialog, { Filter } from "../../../../src/components/views/dialogs/spotlight/SpotlightDialog"; +import SpotlightDialog from "../../../../src/components/views/dialogs/spotlight/SpotlightDialog"; +import { Filter } from "../../../../src/components/views/dialogs/spotlight/Filter"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import { LocalRoom, LOCAL_ROOM_ID_PREFIX } from "../../../../src/models/LocalRoom"; import { DirectoryMember, startDmOnFirstMessage } from "../../../../src/utils/direct-messages"; @@ -352,12 +353,12 @@ describe("Spotlight Dialog", () => { }); it("should find Rooms", () => { - expect(options.length).toBe(3); + expect(options).toHaveLength(4); expect(options[0]!.innerHTML).toContain(testRoom.name); }); it("should not find LocalRooms", () => { - expect(options.length).toBe(3); + expect(options).toHaveLength(4); expect(options[0]!.innerHTML).not.toContain(testLocalRoom.name); }); }); @@ -573,22 +574,4 @@ describe("Spotlight Dialog", () => { expect(screen.getByText("Failed to query public rooms")).toBeInTheDocument(); }); - - it("should show error both 'Show rooms' and 'Show spaces' are unchecked", async () => { - jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName, roomId, excludeDefault) => { - if (settingName === "feature_exploring_public_spaces") { - return true; - } else { - return []; // SpotlightSearch.recentSearches - } - }); - render( null} />); - - jest.advanceTimersByTime(200); - await flushPromisesWithFakeTimers(); - - fireEvent.click(screen.getByText("Show rooms")); - - expect(screen.getByText("You cannot search for rooms that are neither a room nor a space")).toBeInTheDocument(); - }); }); diff --git a/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx b/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx index ead079cdf0..63c11290be 100644 --- a/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx +++ b/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx @@ -71,7 +71,7 @@ describe("", () => { // non-beta labs section expect(screen.getByText("Early previews")).toBeInTheDocument(); const labsSections = container.getElementsByClassName("mx_SettingsSubsection"); - expect(labsSections).toHaveLength(10); + expect(labsSections).toHaveLength(9); }); it("allow setting a labs flag which requires unstable support once support is confirmed", async () => { @@ -80,21 +80,21 @@ describe("", () => { const deferred = defer(); cli.doesServerSupportUnstableFeature.mockImplementation(async (featureName) => { - return featureName === "org.matrix.msc3827.stable" ? deferred.promise : false; + return featureName === "org.matrix.msc3952_intentional_mentions" ? deferred.promise : false; }); MatrixClientBackedController.matrixClient = cli; const { queryByText } = render(getComponent()); expect( - queryByText("Explore public spaces in the new search dialog")! + queryByText("Enable intentional mentions")! .closest(".mx_SettingsFlag")! .querySelector(".mx_AccessibleButton"), ).toHaveAttribute("aria-disabled", "true"); deferred.resolve(true); await waitFor(() => { expect( - queryByText("Explore public spaces in the new search dialog")! + queryByText("Enable intentional mentions")! .closest(".mx_SettingsFlag")! .querySelector(".mx_AccessibleButton"), ).toHaveAttribute("aria-disabled", "false"); diff --git a/test/components/views/spaces/SpacePanel-test.tsx b/test/components/views/spaces/SpacePanel-test.tsx index db6b64ecf4..c05db7ae8a 100644 --- a/test/components/views/spaces/SpacePanel-test.tsx +++ b/test/components/views/spaces/SpacePanel-test.tsx @@ -24,7 +24,7 @@ import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import { MetaSpace, SpaceKey } from "../../../../src/stores/spaces"; import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents"; import { UIComponent } from "../../../../src/settings/UIFeature"; -import { mkStubRoom, wrapInSdkContext } from "../../../test-utils"; +import { mkStubRoom, wrapInMatrixClientContext, wrapInSdkContext } from "../../../test-utils"; import { SdkContextClass } from "../../../../src/contexts/SDKContext"; import SpaceStore from "../../../../src/stores/spaces/SpaceStore"; import DMRoomMap from "../../../../src/utils/DMRoomMap"; @@ -122,9 +122,12 @@ describe("", () => { isGuest: jest.fn(), getAccountData: jest.fn(), on: jest.fn(), + off: jest.fn(), removeListener: jest.fn(), + isVersionSupported: jest.fn().mockResolvedValue(true), + doesServerSupportUnstableFeature: jest.fn().mockResolvedValue(false), } as unknown as MatrixClient; - const SpacePanel = wrapInSdkContext(UnwrappedSpacePanel, SdkContextClass.instance); + const SpacePanel = wrapInSdkContext(wrapInMatrixClientContext(UnwrappedSpacePanel), SdkContextClass.instance); beforeAll(() => { jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);