Second batch: Replace MatrixClient.isRoomEncrypted
by MatrixClient.CryptoApi.isEncryptionEnabledInRoom
(#28466)
* Add `asyncFilter` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `MemberListStore.tsx` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `EventIndex.tsx` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `SendMessageComposer.tsx` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `ScalarMessaging.ts` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `RolesRoomSettingsTab.tsx` * Add reject doc to `asyncFilter` * Reverse `MemberListStore.loadMembers` condition * Remove async for `ScalarMessaging.ts` * Display permission section only after `isEncrypted` is computed * Display composer only after `isEncrypted` is computed * Revert "Display composer only after `isEncrypted` is computed" This reverts commit4d4e037391
. * Revert "Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `SendMessageComposer.tsx`" This reverts commit6bf06da02c
.
This commit is contained in:
parent
ca33d9165a
commit
5cdcf44b6f
8 changed files with 93 additions and 49 deletions
|
@ -27,16 +27,19 @@ describe("RolesRoomSettingsTab", () => {
|
|||
let cli: MatrixClient;
|
||||
let room: Room;
|
||||
|
||||
const renderTab = (propRoom: Room = room): RenderResult => {
|
||||
return render(<RolesRoomSettingsTab room={propRoom} />, withClientContextRenderOptions(cli));
|
||||
const renderTab = async (propRoom: Room = room): Promise<RenderResult> => {
|
||||
const renderResult = render(<RolesRoomSettingsTab room={propRoom} />, withClientContextRenderOptions(cli));
|
||||
// Wait for the tab to be ready
|
||||
await waitFor(() => expect(screen.getByText("Permissions")).toBeInTheDocument());
|
||||
return renderResult;
|
||||
};
|
||||
|
||||
const getVoiceBroadcastsSelect = (): HTMLElement => {
|
||||
return renderTab().container.querySelector("select[label='Voice broadcasts']")!;
|
||||
const getVoiceBroadcastsSelect = async (): Promise<Element> => {
|
||||
return (await renderTab()).container.querySelector("select[label='Voice broadcasts']")!;
|
||||
};
|
||||
|
||||
const getVoiceBroadcastsSelectedOption = (): HTMLElement => {
|
||||
return renderTab().container.querySelector("select[label='Voice broadcasts'] option:checked")!;
|
||||
const getVoiceBroadcastsSelectedOption = async (): Promise<Element> => {
|
||||
return (await renderTab()).container.querySelector("select[label='Voice broadcasts'] option:checked")!;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -45,7 +48,7 @@ describe("RolesRoomSettingsTab", () => {
|
|||
room = mkStubRoom(roomId, "test room", cli);
|
||||
});
|
||||
|
||||
it("should allow an Admin to demote themselves but not others", () => {
|
||||
it("should allow an Admin to demote themselves but not others", async () => {
|
||||
mocked(cli.getRoom).mockReturnValue(room);
|
||||
// @ts-ignore - mocked doesn't support overloads properly
|
||||
mocked(room.currentState.getStateEvents).mockImplementation((type, key) => {
|
||||
|
@ -67,19 +70,19 @@ describe("RolesRoomSettingsTab", () => {
|
|||
return null;
|
||||
});
|
||||
mocked(room.currentState.mayClientSendStateEvent).mockReturnValue(true);
|
||||
const { container } = renderTab();
|
||||
const { container } = await renderTab();
|
||||
|
||||
expect(container.querySelector(`[placeholder="${cli.getUserId()}"]`)).not.toBeDisabled();
|
||||
expect(container.querySelector(`[placeholder="@admin:server"]`)).toBeDisabled();
|
||||
});
|
||||
|
||||
it("should initially show »Moderator« permission for »Voice broadcasts«", () => {
|
||||
expect(getVoiceBroadcastsSelectedOption().textContent).toBe("Moderator");
|
||||
it("should initially show »Moderator« permission for »Voice broadcasts«", async () => {
|
||||
expect((await getVoiceBroadcastsSelectedOption()).textContent).toBe("Moderator");
|
||||
});
|
||||
|
||||
describe("when setting »Default« permission for »Voice broadcasts«", () => {
|
||||
beforeEach(() => {
|
||||
fireEvent.change(getVoiceBroadcastsSelect(), {
|
||||
beforeEach(async () => {
|
||||
fireEvent.change(await getVoiceBroadcastsSelect(), {
|
||||
target: { value: 0 },
|
||||
});
|
||||
});
|
||||
|
@ -122,12 +125,12 @@ describe("RolesRoomSettingsTab", () => {
|
|||
});
|
||||
|
||||
describe("Join Element calls", () => {
|
||||
it("defaults to moderator for joining calls", () => {
|
||||
expect(getJoinCallSelectedOption(renderTab())?.textContent).toBe("Moderator");
|
||||
it("defaults to moderator for joining calls", async () => {
|
||||
expect(getJoinCallSelectedOption(await renderTab())?.textContent).toBe("Moderator");
|
||||
});
|
||||
|
||||
it("can change joining calls power level", () => {
|
||||
const tab = renderTab();
|
||||
it("can change joining calls power level", async () => {
|
||||
const tab = await renderTab();
|
||||
|
||||
fireEvent.change(getJoinCallSelect(tab), {
|
||||
target: { value: 0 },
|
||||
|
@ -143,12 +146,12 @@ describe("RolesRoomSettingsTab", () => {
|
|||
});
|
||||
|
||||
describe("Start Element calls", () => {
|
||||
it("defaults to moderator for starting calls", () => {
|
||||
expect(getStartCallSelectedOption(renderTab())?.textContent).toBe("Moderator");
|
||||
it("defaults to moderator for starting calls", async () => {
|
||||
expect(getStartCallSelectedOption(await renderTab())?.textContent).toBe("Moderator");
|
||||
});
|
||||
|
||||
it("can change starting calls power level", () => {
|
||||
const tab = renderTab();
|
||||
it("can change starting calls power level", async () => {
|
||||
const tab = await renderTab();
|
||||
|
||||
fireEvent.change(getStartCallSelect(tab), {
|
||||
target: { value: 0 },
|
||||
|
@ -164,10 +167,10 @@ describe("RolesRoomSettingsTab", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("hides when group calls disabled", () => {
|
||||
it("hides when group calls disabled", async () => {
|
||||
setGroupCallsEnabled(false);
|
||||
|
||||
const tab = renderTab();
|
||||
const tab = await renderTab();
|
||||
|
||||
expect(getStartCallSelect(tab)).toBeFalsy();
|
||||
expect(getStartCallSelectedOption(tab)).toBeFalsy();
|
||||
|
@ -250,7 +253,7 @@ describe("RolesRoomSettingsTab", () => {
|
|||
return null;
|
||||
});
|
||||
mocked(room.currentState.mayClientSendStateEvent).mockReturnValue(true);
|
||||
const { container } = renderTab();
|
||||
const { container } = await renderTab();
|
||||
|
||||
const selector = container.querySelector(`[placeholder="${cli.getUserId()}"]`)!;
|
||||
fireEvent.change(selector, { target: { value: "50" } });
|
||||
|
|
|
@ -189,8 +189,7 @@ describe("MemberListStore", () => {
|
|||
});
|
||||
|
||||
it("does not use lazy loading on encrypted rooms", async () => {
|
||||
client.isRoomEncrypted = jest.fn();
|
||||
mocked(client.isRoomEncrypted).mockReturnValue(true);
|
||||
jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true);
|
||||
|
||||
const { joined } = await store.loadMemberList(roomId);
|
||||
expect(joined).toEqual([room.getMember(alice)]);
|
||||
|
|
|
@ -24,6 +24,7 @@ import {
|
|||
asyncEvery,
|
||||
asyncSome,
|
||||
asyncSomeParallel,
|
||||
asyncFilter,
|
||||
} from "../../../src/utils/arrays";
|
||||
|
||||
type TestParams = { input: number[]; output: number[] };
|
||||
|
@ -480,4 +481,15 @@ describe("arrays", () => {
|
|||
expect(await asyncSomeParallel([1, 2, 3], predicate)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("asyncFilter", () => {
|
||||
it("when called with an empty array, it should return an empty array", async () => {
|
||||
expect(await asyncFilter([], jest.fn().mockResolvedValue(true))).toEqual([]);
|
||||
});
|
||||
|
||||
it("should filter the content", async () => {
|
||||
const predicate = jest.fn().mockImplementation((value) => Promise.resolve(value === 2));
|
||||
expect(await asyncFilter([1, 2, 3], predicate)).toEqual([2]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue