Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 37d2b7b

Browse files
authored
Support dynamic room predecessors in AddExistingToSpaceDialog (#10342)
1 parent 421c1b9 commit 37d2b7b

File tree

3 files changed

+199
-1
lines changed

3 files changed

+199
-1
lines changed

Diff for: src/components/views/dialogs/AddExistingToSpaceDialog.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import ProgressBar from "../elements/ProgressBar";
3939
import DecoratedRoomAvatar from "../avatars/DecoratedRoomAvatar";
4040
import QueryMatcher from "../../../autocomplete/QueryMatcher";
4141
import LazyRenderList from "../elements/LazyRenderList";
42+
import { useSettingValue } from "../../../hooks/useSettings";
4243

4344
// These values match CSS
4445
const ROW_HEIGHT = 32 + 12;
@@ -135,7 +136,11 @@ export const AddExistingToSpace: React.FC<IAddExistingToSpaceProps> = ({
135136
onFinished,
136137
}) => {
137138
const cli = useContext(MatrixClientContext);
138-
const visibleRooms = useMemo(() => cli.getVisibleRooms().filter((r) => r.getMyMembership() === "join"), [cli]);
139+
const msc3946ProcessDynamicPredecessor = useSettingValue<boolean>("feature_dynamic_room_predecessors");
140+
const visibleRooms = useMemo(
141+
() => cli.getVisibleRooms(msc3946ProcessDynamicPredecessor).filter((r) => r.getMyMembership() === "join"),
142+
[cli, msc3946ProcessDynamicPredecessor],
143+
);
139144

140145
const scrollRef = useRef<AutoHideScrollbar<"div">>();
141146
const [scrollState, setScrollState] = useState<IScrollState>({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright 2023 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { render } from "@testing-library/react";
18+
import { mocked } from "jest-mock";
19+
import { MatrixClient } from "matrix-js-sdk/src/matrix";
20+
import React from "react";
21+
22+
import AddExistingToSpaceDialog from "../../../../src/components/views/dialogs/AddExistingToSpaceDialog";
23+
import SettingsStore from "../../../../src/settings/SettingsStore";
24+
import DMRoomMap from "../../../../src/utils/DMRoomMap";
25+
import { mkSpace, stubClient } from "../../../test-utils";
26+
27+
describe("<AddExistingToSpaceDialog />", () => {
28+
it("looks as expected", () => {
29+
const client = stubClient();
30+
const dialog = renderAddExistingToSpaceDialog(client);
31+
expect(dialog.asFragment()).toMatchSnapshot();
32+
});
33+
34+
describe("If the feature_dynamic_room_predecessors is not enabled", () => {
35+
beforeEach(() => {
36+
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
37+
});
38+
39+
it("Passes through the dynamic predecessor setting", async () => {
40+
const client = stubClient();
41+
mocked(client.getVisibleRooms).mockClear();
42+
renderAddExistingToSpaceDialog(client);
43+
expect(client.getVisibleRooms).toHaveBeenCalledWith(false);
44+
});
45+
});
46+
47+
describe("If the feature_dynamic_room_predecessors is enabled", () => {
48+
beforeEach(() => {
49+
// Turn on feature_dynamic_room_predecessors setting
50+
jest.spyOn(SettingsStore, "getValue").mockImplementation(
51+
(settingName) => settingName === "feature_dynamic_room_predecessors",
52+
);
53+
});
54+
55+
it("Passes through the dynamic predecessor setting", async () => {
56+
const client = stubClient();
57+
mocked(client.getVisibleRooms).mockClear();
58+
renderAddExistingToSpaceDialog(client);
59+
expect(client.getVisibleRooms).toHaveBeenCalledWith(true);
60+
});
61+
});
62+
});
63+
64+
function renderAddExistingToSpaceDialog(client: MatrixClient) {
65+
const dmRoomMap = new DMRoomMap(client);
66+
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
67+
const space = mkSpace(client, "!spaceid:example.com");
68+
const dialog = render(
69+
<AddExistingToSpaceDialog
70+
space={space}
71+
onCreateRoomClick={jest.fn()}
72+
onAddSubspaceClick={jest.fn()}
73+
onFinished={jest.fn()}
74+
/>,
75+
);
76+
return dialog;
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<AddExistingToSpaceDialog /> looks as expected 1`] = `
4+
<DocumentFragment>
5+
<div
6+
data-focus-guard="true"
7+
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
8+
tabindex="0"
9+
/>
10+
<div
11+
aria-describedby="mx_AddExistingToSpace"
12+
aria-labelledby="mx_BaseDialog_title"
13+
class="mx_AddExistingToSpaceDialog"
14+
data-focus-lock-disabled="false"
15+
role="dialog"
16+
>
17+
<div
18+
class="mx_Dialog_header mx_Dialog_headerWithCancel"
19+
>
20+
<h2
21+
class="mx_Heading_h2 mx_Dialog_title"
22+
id="mx_BaseDialog_title"
23+
>
24+
<div
25+
class="mx_SubspaceSelector"
26+
>
27+
<img
28+
alt=""
29+
class="mx_BaseAvatar mx_BaseAvatar_image mx_RoomAvatar_isSpaceRoom"
30+
data-testid="avatar-img"
31+
src="http://this.is.a.url/avatar.url/room.png"
32+
style="width: 40px; height: 40px;"
33+
/>
34+
<div>
35+
<h1>
36+
Add existing rooms
37+
</h1>
38+
<div
39+
class="mx_SubspaceSelector_onlySpace"
40+
>
41+
!spaceid:example.com
42+
</div>
43+
</div>
44+
</div>
45+
</h2>
46+
<div
47+
aria-label="Close dialog"
48+
class="mx_AccessibleButton mx_Dialog_cancelButton"
49+
role="button"
50+
tabindex="0"
51+
/>
52+
</div>
53+
<div
54+
class="mx_AddExistingToSpace"
55+
>
56+
<div
57+
class="mx_SearchBox mx_textinput"
58+
>
59+
<input
60+
autocomplete="off"
61+
class="mx_textinput_icon mx_textinput_search mx_textinput_icon mx_textinput_search"
62+
data-testid="searchbox-input"
63+
placeholder="Search for rooms"
64+
type="text"
65+
value=""
66+
/>
67+
<div
68+
class="mx_AccessibleButton mx_SearchBox_closeButton"
69+
role="button"
70+
tabindex="-1"
71+
/>
72+
</div>
73+
<div
74+
class="mx_AutoHideScrollbar mx_AddExistingToSpace_content"
75+
tabindex="-1"
76+
>
77+
<span
78+
class="mx_AddExistingToSpace_noResults"
79+
>
80+
No results
81+
</span>
82+
</div>
83+
<div
84+
class="mx_AddExistingToSpace_footer"
85+
>
86+
<span>
87+
<div>
88+
Want to add a new room instead?
89+
</div>
90+
<div
91+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link"
92+
role="button"
93+
tabindex="0"
94+
>
95+
Create a new room
96+
</div>
97+
</span>
98+
<div
99+
aria-disabled="true"
100+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary mx_AccessibleButton_disabled"
101+
disabled=""
102+
role="button"
103+
tabindex="0"
104+
>
105+
Add
106+
</div>
107+
</div>
108+
</div>
109+
</div>
110+
<div
111+
data-focus-guard="true"
112+
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
113+
tabindex="0"
114+
/>
115+
</DocumentFragment>
116+
`;

0 commit comments

Comments
 (0)