2022-08-10 19:14:59 +03:00
|
|
|
/*
|
|
|
|
Copyright 2022 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 React from "react";
|
2023-02-22 13:52:55 +03:00
|
|
|
import { act, fireEvent, render, RenderResult } from "@testing-library/react";
|
2022-08-10 19:14:59 +03:00
|
|
|
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2022-09-14 13:40:26 +03:00
|
|
|
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
2023-02-16 12:38:44 +03:00
|
|
|
import { defer, sleep } from "matrix-js-sdk/src/utils";
|
2022-09-28 20:18:10 +03:00
|
|
|
import {
|
2022-09-29 22:05:06 +03:00
|
|
|
ClientEvent,
|
2022-09-28 20:18:10 +03:00
|
|
|
IMyDevice,
|
|
|
|
LOCAL_NOTIFICATION_SETTINGS_PREFIX,
|
|
|
|
MatrixEvent,
|
|
|
|
PUSHER_DEVICE_ID,
|
|
|
|
PUSHER_ENABLED,
|
2022-10-25 11:39:48 +03:00
|
|
|
IAuthData,
|
2023-04-06 11:06:12 +03:00
|
|
|
UNSTABLE_MSC3882_CAPABILITY,
|
2023-04-24 16:19:46 +03:00
|
|
|
CryptoApi,
|
|
|
|
DeviceVerificationStatus,
|
2022-09-28 20:18:10 +03:00
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2023-04-24 16:19:46 +03:00
|
|
|
import { mocked } from "jest-mock";
|
2022-08-10 19:14:59 +03:00
|
|
|
|
2023-03-24 22:39:24 +03:00
|
|
|
import { clearAllModals } from "../../../../../test-utils";
|
2022-08-10 19:14:59 +03:00
|
|
|
import SessionManagerTab from "../../../../../../src/components/views/settings/tabs/user/SessionManagerTab";
|
|
|
|
import MatrixClientContext from "../../../../../../src/contexts/MatrixClientContext";
|
|
|
|
import {
|
2022-10-19 18:11:42 +03:00
|
|
|
flushPromises,
|
2022-08-10 19:14:59 +03:00
|
|
|
getMockClientWithEventEmitter,
|
2022-09-27 15:35:54 +03:00
|
|
|
mkPusher,
|
2022-08-10 19:14:59 +03:00
|
|
|
mockClientMethodsUser,
|
2022-10-04 11:12:07 +03:00
|
|
|
mockPlatformPeg,
|
2022-08-10 19:14:59 +03:00
|
|
|
} from "../../../../../test-utils";
|
2022-09-08 18:35:53 +03:00
|
|
|
import Modal from "../../../../../../src/Modal";
|
2022-09-14 15:37:36 +03:00
|
|
|
import LogoutDialog from "../../../../../../src/components/views/dialogs/LogoutDialog";
|
2022-10-04 11:12:07 +03:00
|
|
|
import { DeviceSecurityVariation, ExtendedDevice } from "../../../../../../src/components/views/settings/devices/types";
|
|
|
|
import { INACTIVE_DEVICE_AGE_MS } from "../../../../../../src/components/views/settings/devices/filter";
|
2022-10-19 18:11:42 +03:00
|
|
|
import SettingsStore from "../../../../../../src/settings/SettingsStore";
|
2023-01-10 09:01:50 +03:00
|
|
|
import { getClientInformationEventType } from "../../../../../../src/utils/device/clientInformation";
|
2022-10-04 11:12:07 +03:00
|
|
|
|
|
|
|
mockPlatformPeg();
|
2022-08-10 19:14:59 +03:00
|
|
|
|
|
|
|
describe("<SessionManagerTab />", () => {
|
|
|
|
const aliceId = "@alice:server.org";
|
|
|
|
const deviceId = "alices_device";
|
|
|
|
|
|
|
|
const alicesDevice = {
|
|
|
|
device_id: deviceId,
|
2022-09-15 17:34:50 +03:00
|
|
|
display_name: "Alices device",
|
2022-08-10 19:14:59 +03:00
|
|
|
};
|
|
|
|
const alicesMobileDevice = {
|
|
|
|
device_id: "alices_mobile_device",
|
2022-08-11 12:45:35 +03:00
|
|
|
last_seen_ts: Date.now(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const alicesOlderMobileDevice = {
|
|
|
|
device_id: "alices_older_mobile_device",
|
|
|
|
last_seen_ts: Date.now() - 600000,
|
2022-08-10 19:14:59 +03:00
|
|
|
};
|
|
|
|
|
2022-10-04 11:12:07 +03:00
|
|
|
const alicesInactiveDevice = {
|
2022-10-17 18:14:49 +03:00
|
|
|
device_id: "alices_older_inactive_mobile_device",
|
2022-10-04 11:12:07 +03:00
|
|
|
last_seen_ts: Date.now() - (INACTIVE_DEVICE_AGE_MS + 1000),
|
|
|
|
};
|
|
|
|
|
2023-03-28 13:23:16 +03:00
|
|
|
const mockVerificationRequest = {
|
|
|
|
cancel: jest.fn(),
|
|
|
|
on: jest.fn(),
|
|
|
|
} as unknown as VerificationRequest;
|
2023-04-24 16:19:46 +03:00
|
|
|
|
|
|
|
const mockCrypto = mocked({
|
|
|
|
getDeviceVerificationStatus: jest.fn(),
|
|
|
|
} as unknown as CryptoApi);
|
|
|
|
|
2022-08-10 19:14:59 +03:00
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
|
|
|
...mockClientMethodsUser(aliceId),
|
2023-04-24 16:19:46 +03:00
|
|
|
getCrypto: jest.fn().mockReturnValue(mockCrypto),
|
2022-08-10 19:14:59 +03:00
|
|
|
getDevices: jest.fn(),
|
|
|
|
getStoredDevice: jest.fn(),
|
|
|
|
getDeviceId: jest.fn().mockReturnValue(deviceId),
|
2022-09-14 13:40:26 +03:00
|
|
|
requestVerification: jest.fn().mockResolvedValue(mockVerificationRequest),
|
2022-09-14 19:18:32 +03:00
|
|
|
deleteMultipleDevices: jest.fn(),
|
|
|
|
generateClientSecret: jest.fn(),
|
2022-09-15 17:34:50 +03:00
|
|
|
setDeviceDetails: jest.fn(),
|
2022-10-04 16:12:23 +03:00
|
|
|
getAccountData: jest.fn(),
|
2023-01-10 09:01:50 +03:00
|
|
|
deleteAccountData: jest.fn(),
|
2022-09-27 15:35:54 +03:00
|
|
|
doesServerSupportUnstableFeature: jest.fn().mockResolvedValue(true),
|
|
|
|
getPushers: jest.fn(),
|
|
|
|
setPusher: jest.fn(),
|
2022-09-28 20:18:10 +03:00
|
|
|
setLocalNotificationSettings: jest.fn(),
|
2022-10-19 15:31:20 +03:00
|
|
|
getVersions: jest.fn().mockResolvedValue({}),
|
2023-04-06 11:06:12 +03:00
|
|
|
getCapabilities: jest.fn().mockResolvedValue({}),
|
2022-08-10 19:14:59 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const defaultProps = {};
|
|
|
|
const getComponent = (props = {}): React.ReactElement => (
|
|
|
|
<MatrixClientContext.Provider value={mockClient}>
|
|
|
|
<SessionManagerTab {...defaultProps} {...props} />
|
|
|
|
</MatrixClientContext.Provider>
|
|
|
|
);
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
const toggleDeviceDetails = (
|
|
|
|
getByTestId: ReturnType<typeof render>["getByTestId"],
|
2022-10-05 14:41:01 +03:00
|
|
|
deviceId: ExtendedDevice["device_id"],
|
2022-11-20 22:24:56 +03:00
|
|
|
isOpen?: boolean,
|
2022-10-17 18:14:49 +03:00
|
|
|
): void => {
|
2022-09-14 19:18:32 +03:00
|
|
|
// open device detail
|
|
|
|
const tile = getByTestId(`device-tile-${deviceId}`);
|
2022-11-20 22:24:56 +03:00
|
|
|
const label = isOpen ? "Hide details" : "Show details";
|
|
|
|
const toggle = tile.querySelector(`[aria-label="${label}"]`) as Element;
|
2022-09-14 19:18:32 +03:00
|
|
|
fireEvent.click(toggle);
|
|
|
|
};
|
|
|
|
|
2022-09-30 10:07:50 +03:00
|
|
|
const toggleDeviceSelection = (
|
|
|
|
getByTestId: ReturnType<typeof render>["getByTestId"],
|
2022-10-05 14:41:01 +03:00
|
|
|
deviceId: ExtendedDevice["device_id"],
|
2022-10-17 18:14:49 +03:00
|
|
|
): void => {
|
2022-09-30 10:07:50 +03:00
|
|
|
const checkbox = getByTestId(`device-tile-checkbox-${deviceId}`);
|
|
|
|
fireEvent.click(checkbox);
|
|
|
|
};
|
|
|
|
|
2022-10-17 18:14:49 +03:00
|
|
|
const getDeviceTile = (
|
|
|
|
getByTestId: ReturnType<typeof render>["getByTestId"],
|
|
|
|
deviceId: ExtendedDevice["device_id"],
|
|
|
|
): HTMLElement => {
|
|
|
|
return getByTestId(`device-tile-${deviceId}`);
|
|
|
|
};
|
|
|
|
|
2022-10-04 11:12:07 +03:00
|
|
|
const setFilter = async (container: HTMLElement, option: DeviceSecurityVariation | string) =>
|
|
|
|
await act(async () => {
|
|
|
|
const dropdown = container.querySelector('[aria-label="Filter devices"]');
|
|
|
|
|
|
|
|
fireEvent.click(dropdown as Element);
|
|
|
|
// tick to let dropdown render
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-04 11:12:07 +03:00
|
|
|
|
|
|
|
fireEvent.click(container.querySelector(`#device-list-filter__${option}`) as Element);
|
|
|
|
});
|
|
|
|
|
2022-09-30 10:07:50 +03:00
|
|
|
const isDeviceSelected = (
|
|
|
|
getByTestId: ReturnType<typeof render>["getByTestId"],
|
2022-10-05 14:41:01 +03:00
|
|
|
deviceId: ExtendedDevice["device_id"],
|
2022-09-30 10:07:50 +03:00
|
|
|
): boolean => !!(getByTestId(`device-tile-checkbox-${deviceId}`) as HTMLInputElement).checked;
|
|
|
|
|
2022-10-04 11:12:07 +03:00
|
|
|
const isSelectAllChecked = (getByTestId: ReturnType<typeof render>["getByTestId"]): boolean =>
|
|
|
|
!!(getByTestId("device-select-all-checkbox") as HTMLInputElement).checked;
|
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
const confirmSignout = async (
|
|
|
|
getByTestId: ReturnType<typeof render>["getByTestId"],
|
|
|
|
confirm = true,
|
|
|
|
): Promise<void> => {
|
|
|
|
// modal has sleeps in rendering process :(
|
|
|
|
await sleep(100);
|
|
|
|
const buttonId = confirm ? "dialog-primary-button" : "dialog-cancel-button";
|
|
|
|
fireEvent.click(getByTestId(buttonId));
|
|
|
|
|
|
|
|
// flush the confirmation promise
|
|
|
|
await flushPromises();
|
|
|
|
};
|
|
|
|
|
2023-03-24 22:39:24 +03:00
|
|
|
beforeEach(async () => {
|
2022-08-10 19:14:59 +03:00
|
|
|
jest.clearAllMocks();
|
|
|
|
jest.spyOn(logger, "error").mockRestore();
|
|
|
|
mockClient.getStoredDevice.mockImplementation((_userId, id) => {
|
|
|
|
const device = [alicesDevice, alicesMobileDevice].find((device) => device.device_id === id);
|
|
|
|
return device ? new DeviceInfo(device.device_id) : null;
|
|
|
|
});
|
2023-04-24 16:19:46 +03:00
|
|
|
mockCrypto.getDeviceVerificationStatus.mockReset().mockResolvedValue(new DeviceVerificationStatus({}));
|
2022-09-14 19:18:32 +03:00
|
|
|
|
2022-09-15 17:34:50 +03:00
|
|
|
mockClient.getDevices.mockReset().mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
|
2022-09-27 15:35:54 +03:00
|
|
|
|
|
|
|
mockClient.getPushers.mockReset().mockResolvedValue({
|
|
|
|
pushers: [
|
|
|
|
mkPusher({
|
|
|
|
[PUSHER_DEVICE_ID.name]: alicesMobileDevice.device_id,
|
|
|
|
[PUSHER_ENABLED.name]: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
2022-09-28 20:18:10 +03:00
|
|
|
|
2023-01-10 09:01:50 +03:00
|
|
|
// @ts-ignore mock
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.store = { accountData: new Map() };
|
2023-01-10 09:01:50 +03:00
|
|
|
|
2022-09-28 20:18:10 +03:00
|
|
|
mockClient.getAccountData.mockReset().mockImplementation((eventType) => {
|
|
|
|
if (eventType.startsWith(LOCAL_NOTIFICATION_SETTINGS_PREFIX.name)) {
|
|
|
|
return new MatrixEvent({
|
|
|
|
type: eventType,
|
|
|
|
content: {
|
|
|
|
is_silenced: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-10-25 11:39:48 +03:00
|
|
|
|
|
|
|
// sometimes a verification modal is in modal state when these tests run
|
|
|
|
// make sure the coast is clear
|
2023-03-24 22:39:24 +03:00
|
|
|
await clearAllModals();
|
2022-08-10 19:14:59 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("renders spinner while devices load", () => {
|
|
|
|
const { container } = render(getComponent());
|
|
|
|
expect(container.getElementsByClassName("mx_Spinner").length).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("removes spinner when device fetch fails", async () => {
|
|
|
|
// eat the expected error log
|
|
|
|
jest.spyOn(logger, "error").mockImplementation(() => {});
|
|
|
|
mockClient.getDevices.mockRejectedValue({ httpStatus: 404 });
|
|
|
|
const { container } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-08-10 19:14:59 +03:00
|
|
|
});
|
|
|
|
expect(container.getElementsByClassName("mx_Spinner").length).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not fail when checking device verification fails", async () => {
|
2023-04-24 16:19:46 +03:00
|
|
|
const logSpy = jest.spyOn(console, "error").mockImplementation((e) => {});
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2023-04-24 16:19:46 +03:00
|
|
|
const failError = new Error("non-specific failure");
|
|
|
|
mockCrypto.getDeviceVerificationStatus.mockImplementation(() => {
|
|
|
|
throw failError;
|
2022-08-10 19:14:59 +03:00
|
|
|
});
|
|
|
|
render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-08-10 19:14:59 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// called for each device despite error
|
2023-04-24 16:19:46 +03:00
|
|
|
expect(mockCrypto.getDeviceVerificationStatus).toHaveBeenCalledWith(aliceId, alicesDevice.device_id);
|
|
|
|
expect(mockCrypto.getDeviceVerificationStatus).toHaveBeenCalledWith(aliceId, alicesMobileDevice.device_id);
|
|
|
|
expect(logSpy).toHaveBeenCalledWith("Error getting device cross-signing info", failError);
|
2022-08-10 19:14:59 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("sets device verification status correctly", async () => {
|
2022-12-09 00:52:00 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
|
|
|
|
});
|
|
|
|
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
|
2023-04-24 16:19:46 +03:00
|
|
|
mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => {
|
2022-12-09 00:52:00 +03:00
|
|
|
// alices device is trusted
|
|
|
|
if (deviceId === alicesDevice.device_id) {
|
2023-04-24 16:19:46 +03:00
|
|
|
return new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true });
|
2022-12-09 00:52:00 +03:00
|
|
|
}
|
|
|
|
// alices mobile device is not
|
|
|
|
if (deviceId === alicesMobileDevice.device_id) {
|
2023-04-24 16:19:46 +03:00
|
|
|
return new DeviceVerificationStatus({});
|
2022-12-09 00:52:00 +03:00
|
|
|
}
|
|
|
|
// alicesOlderMobileDevice does not support encryption
|
|
|
|
throw new Error("encryption not supported");
|
|
|
|
});
|
2022-08-10 19:14:59 +03:00
|
|
|
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-08-10 19:14:59 +03:00
|
|
|
});
|
|
|
|
|
2023-04-24 16:19:46 +03:00
|
|
|
expect(mockCrypto.getDeviceVerificationStatus).toHaveBeenCalledTimes(3);
|
2022-12-09 00:52:00 +03:00
|
|
|
expect(
|
|
|
|
getByTestId(`device-tile-${alicesDevice.device_id}`).querySelector('[aria-label="Verified"]'),
|
|
|
|
).toBeTruthy();
|
|
|
|
expect(
|
|
|
|
getByTestId(`device-tile-${alicesMobileDevice.device_id}`).querySelector('[aria-label="Unverified"]'),
|
|
|
|
).toBeTruthy();
|
|
|
|
// sessions that dont support encryption use unverified badge
|
|
|
|
expect(
|
|
|
|
getByTestId(`device-tile-${alicesOlderMobileDevice.device_id}`).querySelector('[aria-label="Unverified"]'),
|
|
|
|
).toBeTruthy();
|
2022-08-10 19:14:59 +03:00
|
|
|
});
|
|
|
|
|
2022-10-04 16:12:23 +03:00
|
|
|
it("extends device with client information when available", async () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-10-04 16:12:23 +03:00
|
|
|
mockClient.getAccountData.mockImplementation((eventType: string) => {
|
|
|
|
const content = {
|
|
|
|
name: "Element Web",
|
|
|
|
version: "1.2.3",
|
|
|
|
url: "test.com",
|
|
|
|
};
|
|
|
|
return new MatrixEvent({
|
|
|
|
type: eventType,
|
|
|
|
content,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-04 16:12:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// twice for each device
|
|
|
|
expect(mockClient.getAccountData).toHaveBeenCalledTimes(4);
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesDevice.device_id);
|
|
|
|
// application metadata section rendered
|
|
|
|
expect(getByTestId("device-detail-metadata-application")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders devices without available client information without error", async () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-10-04 16:12:23 +03:00
|
|
|
|
|
|
|
const { getByTestId, queryByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-04 16:12:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesDevice.device_id);
|
|
|
|
// application metadata section not rendered
|
|
|
|
expect(queryByTestId("device-detail-metadata-application")).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2022-08-11 12:45:35 +03:00
|
|
|
it("does not render other sessions section when user has only one device", async () => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice] });
|
|
|
|
const { queryByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-08-11 12:45:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(queryByTestId("other-sessions-section")).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2022-08-11 13:39:14 +03:00
|
|
|
it("renders other sessions section when user has more than one device", async () => {
|
2022-08-11 12:45:35 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesOlderMobileDevice, alicesMobileDevice],
|
|
|
|
});
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-08-11 12:45:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(getByTestId("other-sessions-section")).toBeTruthy();
|
|
|
|
});
|
2022-08-17 12:58:34 +03:00
|
|
|
|
2022-08-31 15:34:22 +03:00
|
|
|
it("goes to filtered list from security recommendations", async () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-08-31 15:34:22 +03:00
|
|
|
const { getByTestId, container } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-08-31 15:34:22 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("unverified-devices-cta"));
|
|
|
|
|
|
|
|
// our session manager waits a tick for rerender
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-08-31 15:34:22 +03:00
|
|
|
|
|
|
|
// unverified filter is set
|
2022-09-29 10:22:00 +03:00
|
|
|
expect(container.querySelector(".mx_FilteredDeviceListHeader")).toMatchSnapshot();
|
2022-08-31 15:34:22 +03:00
|
|
|
});
|
|
|
|
|
2022-10-13 10:07:34 +03:00
|
|
|
describe("current session section", () => {
|
|
|
|
it("disables current session context menu while devices are loading", () => {
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
expect(getByTestId("current-session-menu").getAttribute("aria-disabled")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("disables current session context menu when there is no current device", async () => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({ devices: [] });
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-13 10:07:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(getByTestId("current-session-menu").getAttribute("aria-disabled")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders current session section with an unverified session", async () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-10-13 10:07:34 +03:00
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-13 10:07:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(getByTestId("current-session-section")).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("opens encryption setup dialog when verifiying current session", async () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-10-13 10:07:34 +03:00
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
const modalSpy = jest.spyOn(Modal, "createDialog");
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-13 10:07:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// click verify button from current session section
|
|
|
|
fireEvent.click(getByTestId(`verification-status-button-${alicesDevice.device_id}`));
|
|
|
|
|
|
|
|
expect(modalSpy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders current session section with a verified session", async () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-10-13 10:07:34 +03:00
|
|
|
mockClient.getStoredDevice.mockImplementation(() => new DeviceInfo(alicesDevice.device_id));
|
2023-04-24 16:19:46 +03:00
|
|
|
mockCrypto.getDeviceVerificationStatus.mockResolvedValue(
|
|
|
|
new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true }),
|
|
|
|
);
|
2022-10-13 10:07:34 +03:00
|
|
|
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-13 10:07:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(getByTestId("current-session-section")).toMatchSnapshot();
|
|
|
|
});
|
2022-12-20 04:17:05 +03:00
|
|
|
|
|
|
|
it("expands current session details", async () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-12-20 04:17:05 +03:00
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("current-session-toggle-details"));
|
|
|
|
|
|
|
|
expect(getByTestId(`device-detail-${alicesDevice.device_id}`)).toBeTruthy();
|
|
|
|
// only one security card rendered
|
|
|
|
expect(getByTestId("current-session-section").querySelectorAll(".mx_DeviceSecurityCard").length).toEqual(1);
|
|
|
|
});
|
2022-10-13 10:07:34 +03:00
|
|
|
});
|
|
|
|
|
2022-08-17 12:58:34 +03:00
|
|
|
describe("device detail expansion", () => {
|
|
|
|
it("renders no devices expanded by default", async () => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesOlderMobileDevice, alicesMobileDevice],
|
|
|
|
});
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-08-17 12:58:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const otherSessionsSection = getByTestId("other-sessions-section");
|
|
|
|
|
|
|
|
// no expanded device details
|
|
|
|
expect(otherSessionsSection.getElementsByClassName("mx_DeviceDetails").length).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("toggles device expansion on click", async () => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesOlderMobileDevice, alicesMobileDevice],
|
|
|
|
});
|
|
|
|
const { getByTestId, queryByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-08-17 12:58:34 +03:00
|
|
|
});
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
toggleDeviceDetails(getByTestId, alicesOlderMobileDevice.device_id);
|
2022-08-17 12:58:34 +03:00
|
|
|
|
|
|
|
// device details are expanded
|
|
|
|
expect(getByTestId(`device-detail-${alicesOlderMobileDevice.device_id}`)).toBeTruthy();
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id);
|
2022-08-17 12:58:34 +03:00
|
|
|
|
|
|
|
// both device details are expanded
|
|
|
|
expect(getByTestId(`device-detail-${alicesOlderMobileDevice.device_id}`)).toBeTruthy();
|
|
|
|
expect(getByTestId(`device-detail-${alicesMobileDevice.device_id}`)).toBeTruthy();
|
|
|
|
|
2022-11-20 22:24:56 +03:00
|
|
|
// toggle closed
|
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id, true);
|
2022-08-17 12:58:34 +03:00
|
|
|
|
|
|
|
// alicesMobileDevice was toggled off
|
|
|
|
expect(queryByTestId(`device-detail-${alicesMobileDevice.device_id}`)).toBeFalsy();
|
|
|
|
// alicesOlderMobileDevice stayed open
|
|
|
|
expect(getByTestId(`device-detail-${alicesOlderMobileDevice.device_id}`)).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2022-09-14 13:40:26 +03:00
|
|
|
|
|
|
|
describe("Device verification", () => {
|
|
|
|
it("does not render device verification cta when current session is not verified", async () => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesOlderMobileDevice, alicesMobileDevice],
|
|
|
|
});
|
|
|
|
const { getByTestId, queryByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 13:40:26 +03:00
|
|
|
});
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
toggleDeviceDetails(getByTestId, alicesOlderMobileDevice.device_id);
|
2022-09-14 13:40:26 +03:00
|
|
|
|
|
|
|
// verify device button is not rendered
|
|
|
|
expect(queryByTestId(`verification-status-button-${alicesOlderMobileDevice.device_id}`)).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders device verification cta on other sessions when current session is verified", async () => {
|
|
|
|
const modalSpy = jest.spyOn(Modal, "createDialog");
|
|
|
|
|
|
|
|
// make the current device verified
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-09-14 13:40:26 +03:00
|
|
|
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
|
2023-04-24 16:19:46 +03:00
|
|
|
mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => {
|
2022-09-14 13:40:26 +03:00
|
|
|
if (deviceId === alicesDevice.device_id) {
|
2023-04-24 16:19:46 +03:00
|
|
|
return new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true });
|
2022-09-14 13:40:26 +03:00
|
|
|
}
|
2023-04-24 16:19:46 +03:00
|
|
|
return new DeviceVerificationStatus({});
|
2022-09-14 13:40:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 13:40:26 +03:00
|
|
|
});
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id);
|
2022-09-14 13:40:26 +03:00
|
|
|
|
|
|
|
// click verify button from current session section
|
|
|
|
fireEvent.click(getByTestId(`verification-status-button-${alicesMobileDevice.device_id}`));
|
|
|
|
|
|
|
|
expect(mockClient.requestVerification).toHaveBeenCalledWith(aliceId, [alicesMobileDevice.device_id]);
|
|
|
|
expect(modalSpy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-12-09 00:52:00 +03:00
|
|
|
it("does not allow device verification on session that do not support encryption", async () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-12-09 00:52:00 +03:00
|
|
|
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
|
2023-04-24 16:19:46 +03:00
|
|
|
mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => {
|
2022-12-09 00:52:00 +03:00
|
|
|
// current session verified = able to verify other sessions
|
|
|
|
if (deviceId === alicesDevice.device_id) {
|
2023-04-24 16:19:46 +03:00
|
|
|
return new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true });
|
2022-12-09 00:52:00 +03:00
|
|
|
}
|
|
|
|
// but alicesMobileDevice doesn't support encryption
|
2023-04-24 16:19:46 +03:00
|
|
|
// XXX this is not what happens if a device doesn't support encryption.
|
2022-12-09 00:52:00 +03:00
|
|
|
throw new Error("encryption not supported");
|
|
|
|
});
|
|
|
|
|
|
|
|
const { getByTestId, queryByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
|
|
|
|
// no verify button
|
|
|
|
expect(queryByTestId(`verification-status-button-${alicesMobileDevice.device_id}`)).toBeFalsy();
|
|
|
|
expect(
|
|
|
|
getByTestId(`device-detail-${alicesMobileDevice.device_id}`).getElementsByClassName(
|
|
|
|
"mx_DeviceSecurityCard",
|
|
|
|
),
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2022-09-14 13:40:26 +03:00
|
|
|
it("refreshes devices after verifying other device", async () => {
|
|
|
|
const modalSpy = jest.spyOn(Modal, "createDialog");
|
|
|
|
|
|
|
|
// make the current device verified
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice],
|
|
|
|
});
|
2022-09-14 13:40:26 +03:00
|
|
|
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
|
2023-04-24 16:19:46 +03:00
|
|
|
mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => {
|
2022-09-14 13:40:26 +03:00
|
|
|
if (deviceId === alicesDevice.device_id) {
|
2023-04-24 16:19:46 +03:00
|
|
|
return new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true });
|
2022-09-14 13:40:26 +03:00
|
|
|
}
|
2023-04-24 16:19:46 +03:00
|
|
|
return new DeviceVerificationStatus({});
|
2022-09-14 13:40:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 13:40:26 +03:00
|
|
|
});
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id);
|
2022-09-14 13:40:26 +03:00
|
|
|
|
|
|
|
// reset mock counter before triggering verification
|
|
|
|
mockClient.getDevices.mockClear();
|
|
|
|
|
|
|
|
// click verify button from current session section
|
|
|
|
fireEvent.click(getByTestId(`verification-status-button-${alicesMobileDevice.device_id}`));
|
|
|
|
|
|
|
|
const { onFinished: modalOnFinished } = modalSpy.mock.calls[0][1] as any;
|
|
|
|
// simulate modal completing process
|
|
|
|
await modalOnFinished();
|
|
|
|
|
|
|
|
// cancelled in case it was a failure exit from modal
|
|
|
|
expect(mockVerificationRequest.cancel).toHaveBeenCalled();
|
|
|
|
// devices refreshed
|
|
|
|
expect(mockClient.getDevices).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2022-09-14 15:37:36 +03:00
|
|
|
|
|
|
|
describe("Sign out", () => {
|
|
|
|
it("Signs out of current device", async () => {
|
|
|
|
const modalSpy = jest.spyOn(Modal, "createDialog");
|
|
|
|
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice],
|
|
|
|
});
|
2022-09-14 15:37:36 +03:00
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 15:37:36 +03:00
|
|
|
});
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
toggleDeviceDetails(getByTestId, alicesDevice.device_id);
|
2022-09-14 15:37:36 +03:00
|
|
|
|
|
|
|
const signOutButton = getByTestId("device-detail-sign-out-cta");
|
|
|
|
expect(signOutButton).toMatchSnapshot();
|
|
|
|
fireEvent.click(signOutButton);
|
|
|
|
|
|
|
|
// logout dialog opened
|
|
|
|
expect(modalSpy).toHaveBeenCalledWith(LogoutDialog, {}, undefined, false, true);
|
|
|
|
});
|
2022-09-14 19:18:32 +03:00
|
|
|
|
2022-10-13 10:07:34 +03:00
|
|
|
it("Signs out of current device from kebab menu", async () => {
|
|
|
|
const modalSpy = jest.spyOn(Modal, "createDialog");
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice],
|
|
|
|
});
|
2022-10-13 10:07:34 +03:00
|
|
|
const { getByTestId, getByLabelText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-13 10:07:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("current-session-menu"));
|
|
|
|
fireEvent.click(getByLabelText("Sign out"));
|
|
|
|
|
|
|
|
// logout dialog opened
|
|
|
|
expect(modalSpy).toHaveBeenCalledWith(LogoutDialog, {}, undefined, false, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render sign out other devices option when only one device", async () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice],
|
|
|
|
});
|
2022-10-13 10:07:34 +03:00
|
|
|
const { getByTestId, queryByLabelText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-13 10:07:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("current-session-menu"));
|
2022-12-29 05:08:57 +03:00
|
|
|
expect(queryByLabelText("Sign out of all other sessions")).toBeFalsy();
|
2022-10-13 10:07:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("signs out of all other devices from current session context menu", async () => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
|
|
|
|
});
|
|
|
|
const { getByTestId, getByLabelText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-13 10:07:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("current-session-menu"));
|
2022-12-29 05:08:57 +03:00
|
|
|
fireEvent.click(getByLabelText("Sign out of all other sessions (2)"));
|
2022-10-25 11:39:48 +03:00
|
|
|
await confirmSignout(getByTestId);
|
2022-10-13 10:07:34 +03:00
|
|
|
|
|
|
|
// other devices deleted, excluding current device
|
|
|
|
expect(mockClient.deleteMultipleDevices).toHaveBeenCalledWith(
|
|
|
|
[alicesMobileDevice.device_id, alicesOlderMobileDevice.device_id],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-01-10 09:01:50 +03:00
|
|
|
it("removes account data events for devices after sign out", async () => {
|
|
|
|
const mobileDeviceClientInfo = new MatrixEvent({
|
|
|
|
type: getClientInformationEventType(alicesMobileDevice.device_id),
|
|
|
|
content: {
|
|
|
|
name: "test",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
// @ts-ignore setup mock
|
|
|
|
mockClient.store = {
|
|
|
|
// @ts-ignore setup mock
|
2023-03-28 13:23:16 +03:00
|
|
|
accountData: new Map([[mobileDeviceClientInfo.getType(), mobileDeviceClientInfo]]),
|
2023-01-10 09:01:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
mockClient.getDevices
|
|
|
|
.mockResolvedValueOnce({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
|
|
|
|
})
|
|
|
|
.mockResolvedValueOnce({
|
|
|
|
// refreshed devices after sign out
|
|
|
|
devices: [alicesDevice],
|
|
|
|
});
|
|
|
|
|
|
|
|
const { getByTestId, getByLabelText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(mockClient.deleteAccountData).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("current-session-menu"));
|
|
|
|
fireEvent.click(getByLabelText("Sign out of all other sessions (2)"));
|
|
|
|
await confirmSignout(getByTestId);
|
|
|
|
|
|
|
|
// only called once for signed out device with account data event
|
|
|
|
expect(mockClient.deleteAccountData).toHaveBeenCalledTimes(1);
|
|
|
|
expect(mockClient.deleteAccountData).toHaveBeenCalledWith(mobileDeviceClientInfo.getType());
|
|
|
|
});
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
describe("other devices", () => {
|
2023-03-28 13:23:16 +03:00
|
|
|
const interactiveAuthError = {
|
|
|
|
httpStatus: 401,
|
|
|
|
data: { flows: [{ stages: ["m.login.password"] }] },
|
|
|
|
};
|
2022-09-14 19:18:32 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockClient.deleteMultipleDevices.mockReset();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("deletes a device when interactive auth is not required", async () => {
|
|
|
|
mockClient.deleteMultipleDevices.mockResolvedValue({});
|
|
|
|
mockClient.getDevices
|
2023-03-28 13:23:16 +03:00
|
|
|
.mockResolvedValueOnce({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
|
|
|
|
})
|
2022-09-14 19:18:32 +03:00
|
|
|
// pretend it was really deleted on refresh
|
2023-03-28 13:23:16 +03:00
|
|
|
.mockResolvedValueOnce({
|
|
|
|
devices: [alicesDevice, alicesOlderMobileDevice],
|
|
|
|
});
|
2022-09-14 19:18:32 +03:00
|
|
|
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 19:18:32 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
|
|
|
|
const deviceDetails = getByTestId(`device-detail-${alicesMobileDevice.device_id}`);
|
|
|
|
const signOutButton = deviceDetails.querySelector(
|
|
|
|
'[data-testid="device-detail-sign-out-cta"]',
|
|
|
|
) as Element;
|
|
|
|
fireEvent.click(signOutButton);
|
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
await confirmSignout(getByTestId);
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
// sign out button is disabled with spinner
|
|
|
|
expect(
|
|
|
|
(deviceDetails.querySelector('[data-testid="device-detail-sign-out-cta"]') as Element).getAttribute(
|
|
|
|
"aria-disabled",
|
2022-12-12 14:24:14 +03:00
|
|
|
),
|
2022-09-14 19:18:32 +03:00
|
|
|
).toEqual("true");
|
|
|
|
// delete called
|
|
|
|
expect(mockClient.deleteMultipleDevices).toHaveBeenCalledWith(
|
|
|
|
[alicesMobileDevice.device_id],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 19:18:32 +03:00
|
|
|
|
|
|
|
// devices refreshed
|
|
|
|
expect(mockClient.getDevices).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2023-03-01 18:23:35 +03:00
|
|
|
it("does not delete a device when interactive auth is not required", async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
|
|
|
|
const deviceDetails = getByTestId(`device-detail-${alicesMobileDevice.device_id}`);
|
|
|
|
const signOutButton = deviceDetails.querySelector(
|
|
|
|
'[data-testid="device-detail-sign-out-cta"]',
|
|
|
|
) as Element;
|
|
|
|
fireEvent.click(signOutButton);
|
|
|
|
|
|
|
|
await confirmSignout(getByTestId, false);
|
|
|
|
|
|
|
|
// doesnt enter loading state
|
|
|
|
expect(
|
|
|
|
(deviceDetails.querySelector('[data-testid="device-detail-sign-out-cta"]') as Element).getAttribute(
|
|
|
|
"aria-disabled",
|
2022-12-12 14:24:14 +03:00
|
|
|
),
|
2022-10-25 11:39:48 +03:00
|
|
|
).toEqual(null);
|
|
|
|
// delete not called
|
|
|
|
expect(mockClient.deleteMultipleDevices).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-09-14 19:18:32 +03:00
|
|
|
it("deletes a device when interactive auth is required", async () => {
|
|
|
|
mockClient.deleteMultipleDevices
|
|
|
|
// require auth
|
|
|
|
.mockRejectedValueOnce(interactiveAuthError)
|
|
|
|
// then succeed
|
|
|
|
.mockResolvedValueOnce({});
|
|
|
|
|
|
|
|
mockClient.getDevices
|
2023-03-28 13:23:16 +03:00
|
|
|
.mockResolvedValueOnce({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
|
|
|
|
})
|
2022-09-14 19:18:32 +03:00
|
|
|
// pretend it was really deleted on refresh
|
2023-03-28 13:23:16 +03:00
|
|
|
.mockResolvedValueOnce({
|
|
|
|
devices: [alicesDevice, alicesOlderMobileDevice],
|
|
|
|
});
|
2022-09-14 19:18:32 +03:00
|
|
|
|
|
|
|
const { getByTestId, getByLabelText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 19:18:32 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// reset mock count after initial load
|
|
|
|
mockClient.getDevices.mockClear();
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
|
|
|
|
const deviceDetails = getByTestId(`device-detail-${alicesMobileDevice.device_id}`);
|
|
|
|
const signOutButton = deviceDetails.querySelector(
|
|
|
|
'[data-testid="device-detail-sign-out-cta"]',
|
|
|
|
) as Element;
|
|
|
|
fireEvent.click(signOutButton);
|
2022-10-25 11:39:48 +03:00
|
|
|
await confirmSignout(getByTestId);
|
2022-09-14 19:18:32 +03:00
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 19:18:32 +03:00
|
|
|
// modal rendering has some weird sleeps
|
|
|
|
await sleep(100);
|
|
|
|
|
|
|
|
expect(mockClient.deleteMultipleDevices).toHaveBeenCalledWith(
|
|
|
|
[alicesMobileDevice.device_id],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
|
|
|
|
const modal = document.getElementsByClassName("mx_Dialog");
|
|
|
|
expect(modal.length).toBeTruthy();
|
|
|
|
|
|
|
|
// fill password and submit for interactive auth
|
|
|
|
act(() => {
|
2023-03-28 13:23:16 +03:00
|
|
|
fireEvent.change(getByLabelText("Password"), {
|
|
|
|
target: { value: "topsecret" },
|
|
|
|
});
|
2022-09-14 19:18:32 +03:00
|
|
|
fireEvent.submit(getByLabelText("Password"));
|
|
|
|
});
|
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 19:18:32 +03:00
|
|
|
|
|
|
|
// called again with auth
|
|
|
|
expect(mockClient.deleteMultipleDevices).toHaveBeenCalledWith([alicesMobileDevice.device_id], {
|
|
|
|
identifier: {
|
|
|
|
type: "m.id.user",
|
|
|
|
user: aliceId,
|
|
|
|
},
|
|
|
|
password: "",
|
|
|
|
type: "m.login.password",
|
|
|
|
user: aliceId,
|
|
|
|
});
|
|
|
|
// devices refreshed
|
|
|
|
expect(mockClient.getDevices).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("clears loading state when device deletion is cancelled during interactive auth", async () => {
|
|
|
|
mockClient.deleteMultipleDevices
|
|
|
|
// require auth
|
|
|
|
.mockRejectedValueOnce(interactiveAuthError)
|
|
|
|
// then succeed
|
|
|
|
.mockResolvedValueOnce({});
|
|
|
|
|
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
|
|
|
|
});
|
|
|
|
|
|
|
|
const { getByTestId, getByLabelText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 19:18:32 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
|
|
|
|
const deviceDetails = getByTestId(`device-detail-${alicesMobileDevice.device_id}`);
|
|
|
|
const signOutButton = deviceDetails.querySelector(
|
|
|
|
'[data-testid="device-detail-sign-out-cta"]',
|
|
|
|
) as Element;
|
|
|
|
fireEvent.click(signOutButton);
|
2022-10-25 11:39:48 +03:00
|
|
|
await confirmSignout(getByTestId);
|
2022-09-14 19:18:32 +03:00
|
|
|
|
|
|
|
// button is loading
|
|
|
|
expect(
|
|
|
|
(deviceDetails.querySelector('[data-testid="device-detail-sign-out-cta"]') as Element).getAttribute(
|
|
|
|
"aria-disabled",
|
2022-12-12 14:24:14 +03:00
|
|
|
),
|
2022-09-14 19:18:32 +03:00
|
|
|
).toEqual("true");
|
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-16 15:00:01 +03:00
|
|
|
|
|
|
|
// Modal rendering has some weird sleeps.
|
|
|
|
// Resetting ourselves twice in the main loop gives modal the chance to settle.
|
|
|
|
await sleep(0);
|
|
|
|
await sleep(0);
|
2022-09-14 19:18:32 +03:00
|
|
|
|
|
|
|
expect(mockClient.deleteMultipleDevices).toHaveBeenCalledWith(
|
|
|
|
[alicesMobileDevice.device_id],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
|
|
|
|
const modal = document.getElementsByClassName("mx_Dialog");
|
|
|
|
expect(modal.length).toBeTruthy();
|
|
|
|
|
|
|
|
// cancel iau by closing modal
|
|
|
|
act(() => {
|
|
|
|
fireEvent.click(getByLabelText("Close dialog"));
|
|
|
|
});
|
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-14 19:18:32 +03:00
|
|
|
|
|
|
|
// not called again
|
|
|
|
expect(mockClient.deleteMultipleDevices).toHaveBeenCalledTimes(1);
|
|
|
|
// devices not refreshed (not called since initial fetch)
|
|
|
|
expect(mockClient.getDevices).toHaveBeenCalledTimes(1);
|
|
|
|
|
|
|
|
// loading state cleared
|
|
|
|
expect(
|
|
|
|
(deviceDetails.querySelector('[data-testid="device-detail-sign-out-cta"]') as Element).getAttribute(
|
|
|
|
"aria-disabled",
|
2022-12-12 14:24:14 +03:00
|
|
|
),
|
2022-09-14 19:18:32 +03:00
|
|
|
).toEqual(null);
|
|
|
|
});
|
2022-09-30 10:07:50 +03:00
|
|
|
|
|
|
|
it("deletes multiple devices", async () => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice, alicesInactiveDevice],
|
|
|
|
});
|
2022-10-25 11:39:48 +03:00
|
|
|
// get a handle for resolving the delete call
|
|
|
|
// because promise flushing after the confirm modal is resolving this too
|
|
|
|
// and we want to test the loading state here
|
2023-02-16 12:38:44 +03:00
|
|
|
const resolveDeleteRequest = defer<IAuthData>();
|
2022-10-25 11:39:48 +03:00
|
|
|
mockClient.deleteMultipleDevices.mockImplementation(() => {
|
2023-02-16 12:38:44 +03:00
|
|
|
return resolveDeleteRequest.promise;
|
2022-10-25 11:39:48 +03:00
|
|
|
});
|
2022-09-30 10:07:50 +03:00
|
|
|
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-30 10:07:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceSelection(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
toggleDeviceSelection(getByTestId, alicesOlderMobileDevice.device_id);
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("sign-out-selection-cta"));
|
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
await confirmSignout(getByTestId);
|
|
|
|
|
2022-10-17 18:14:49 +03:00
|
|
|
// buttons disabled in list header
|
|
|
|
expect(getByTestId("sign-out-selection-cta").getAttribute("aria-disabled")).toBeTruthy();
|
|
|
|
expect(getByTestId("cancel-selection-cta").getAttribute("aria-disabled")).toBeTruthy();
|
|
|
|
// spinner rendered in list header
|
|
|
|
expect(getByTestId("sign-out-selection-cta").querySelector(".mx_Spinner")).toBeTruthy();
|
|
|
|
|
|
|
|
// spinners on signing out devices
|
|
|
|
expect(
|
|
|
|
getDeviceTile(getByTestId, alicesMobileDevice.device_id).querySelector(".mx_Spinner"),
|
|
|
|
).toBeTruthy();
|
|
|
|
expect(
|
|
|
|
getDeviceTile(getByTestId, alicesOlderMobileDevice.device_id).querySelector(".mx_Spinner"),
|
|
|
|
).toBeTruthy();
|
|
|
|
// no spinner for device that is not signing out
|
|
|
|
expect(
|
|
|
|
getDeviceTile(getByTestId, alicesInactiveDevice.device_id).querySelector(".mx_Spinner"),
|
|
|
|
).toBeFalsy();
|
|
|
|
|
2022-09-30 10:07:50 +03:00
|
|
|
// delete called with both ids
|
|
|
|
expect(mockClient.deleteMultipleDevices).toHaveBeenCalledWith(
|
|
|
|
[alicesMobileDevice.device_id, alicesOlderMobileDevice.device_id],
|
|
|
|
undefined,
|
|
|
|
);
|
2022-10-25 11:39:48 +03:00
|
|
|
|
2023-02-16 12:38:44 +03:00
|
|
|
resolveDeleteRequest.resolve({});
|
2022-09-30 10:07:50 +03:00
|
|
|
});
|
2022-12-29 05:08:57 +03:00
|
|
|
|
|
|
|
it("signs out of all other devices from other sessions context menu", async () => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
|
|
|
|
});
|
|
|
|
const { getByTestId, getByLabelText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("other-sessions-menu"));
|
|
|
|
fireEvent.click(getByLabelText("Sign out of 2 sessions"));
|
|
|
|
await confirmSignout(getByTestId);
|
|
|
|
|
|
|
|
// other devices deleted, excluding current device
|
|
|
|
expect(mockClient.deleteMultipleDevices).toHaveBeenCalledWith(
|
|
|
|
[alicesMobileDevice.device_id, alicesOlderMobileDevice.device_id],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
});
|
2022-09-14 19:18:32 +03:00
|
|
|
});
|
2022-09-14 15:37:36 +03:00
|
|
|
});
|
2022-09-15 17:34:50 +03:00
|
|
|
|
|
|
|
describe("Rename sessions", () => {
|
|
|
|
const updateDeviceName = async (
|
|
|
|
getByTestId: RenderResult["getByTestId"],
|
|
|
|
device: IMyDevice,
|
|
|
|
newDeviceName: string,
|
|
|
|
) => {
|
|
|
|
toggleDeviceDetails(getByTestId, device.device_id);
|
|
|
|
|
|
|
|
// start editing
|
|
|
|
fireEvent.click(getByTestId("device-heading-rename-cta"));
|
|
|
|
|
|
|
|
const input = getByTestId("device-rename-input");
|
|
|
|
fireEvent.change(input, { target: { value: newDeviceName } });
|
|
|
|
fireEvent.click(getByTestId("device-rename-submit-cta"));
|
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
|
|
|
await flushPromises();
|
2022-09-15 17:34:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
it("renames current session", async () => {
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-15 17:34:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const newDeviceName = "new device name";
|
|
|
|
await updateDeviceName(getByTestId, alicesDevice, newDeviceName);
|
|
|
|
|
|
|
|
expect(mockClient.setDeviceDetails).toHaveBeenCalledWith(alicesDevice.device_id, {
|
|
|
|
display_name: newDeviceName,
|
|
|
|
});
|
|
|
|
|
|
|
|
// devices refreshed
|
|
|
|
expect(mockClient.getDevices).toHaveBeenCalledTimes(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renames other session", async () => {
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-15 17:34:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const newDeviceName = "new device name";
|
|
|
|
await updateDeviceName(getByTestId, alicesMobileDevice, newDeviceName);
|
|
|
|
|
|
|
|
expect(mockClient.setDeviceDetails).toHaveBeenCalledWith(alicesMobileDevice.device_id, {
|
|
|
|
display_name: newDeviceName,
|
|
|
|
});
|
|
|
|
|
|
|
|
// devices refreshed
|
|
|
|
expect(mockClient.getDevices).toHaveBeenCalledTimes(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not rename session or refresh devices is session name is unchanged", async () => {
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-15 17:34:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await updateDeviceName(getByTestId, alicesDevice, alicesDevice.display_name);
|
|
|
|
|
|
|
|
expect(mockClient.setDeviceDetails).not.toHaveBeenCalled();
|
|
|
|
// only called once on initial load
|
|
|
|
expect(mockClient.getDevices).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("saves an empty session display name successfully", async () => {
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-15 17:34:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await updateDeviceName(getByTestId, alicesDevice, "");
|
|
|
|
|
2023-03-28 13:23:16 +03:00
|
|
|
expect(mockClient.setDeviceDetails).toHaveBeenCalledWith(alicesDevice.device_id, {
|
|
|
|
display_name: "",
|
|
|
|
});
|
2022-09-15 17:34:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("displays an error when session display name fails to save", async () => {
|
|
|
|
const logSpy = jest.spyOn(logger, "error");
|
|
|
|
const error = new Error("oups");
|
|
|
|
mockClient.setDeviceDetails.mockRejectedValue(error);
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-15 17:34:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const newDeviceName = "new device name";
|
|
|
|
await updateDeviceName(getByTestId, alicesDevice, newDeviceName);
|
|
|
|
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-15 17:34:50 +03:00
|
|
|
|
|
|
|
expect(logSpy).toHaveBeenCalledWith("Error setting session display name", error);
|
|
|
|
|
|
|
|
// error displayed
|
|
|
|
expect(getByTestId("device-rename-error")).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2022-09-27 15:35:54 +03:00
|
|
|
|
2022-09-30 10:07:50 +03:00
|
|
|
describe("Multiple selection", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("toggles session selection", async () => {
|
|
|
|
const { getByTestId, getByText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-30 10:07:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceSelection(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
toggleDeviceSelection(getByTestId, alicesOlderMobileDevice.device_id);
|
|
|
|
|
|
|
|
// header displayed correctly
|
|
|
|
expect(getByText("2 sessions selected")).toBeTruthy();
|
|
|
|
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesMobileDevice.device_id)).toBeTruthy();
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesOlderMobileDevice.device_id)).toBeTruthy();
|
|
|
|
|
|
|
|
toggleDeviceSelection(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
|
|
|
|
// unselected
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesMobileDevice.device_id)).toBeFalsy();
|
|
|
|
// still selected
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesOlderMobileDevice.device_id)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("cancel button clears selection", async () => {
|
|
|
|
const { getByTestId, getByText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-30 10:07:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceSelection(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
toggleDeviceSelection(getByTestId, alicesOlderMobileDevice.device_id);
|
|
|
|
|
|
|
|
// header displayed correctly
|
|
|
|
expect(getByText("2 sessions selected")).toBeTruthy();
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("cancel-selection-cta"));
|
|
|
|
|
|
|
|
// unselected
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesMobileDevice.device_id)).toBeFalsy();
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesOlderMobileDevice.device_id)).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("changing the filter clears selection", async () => {
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-30 10:07:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceSelection(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesMobileDevice.device_id)).toBeTruthy();
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("unverified-devices-cta"));
|
|
|
|
|
|
|
|
// our session manager waits a tick for rerender
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-30 10:07:50 +03:00
|
|
|
|
|
|
|
// unselected
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesOlderMobileDevice.device_id)).toBeFalsy();
|
|
|
|
});
|
2022-10-04 11:12:07 +03:00
|
|
|
|
|
|
|
describe("toggling select all", () => {
|
|
|
|
it("selects all sessions when there is not existing selection", async () => {
|
|
|
|
const { getByTestId, getByText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-04 11:12:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("device-select-all-checkbox"));
|
|
|
|
|
|
|
|
// header displayed correctly
|
|
|
|
expect(getByText("2 sessions selected")).toBeTruthy();
|
|
|
|
expect(isSelectAllChecked(getByTestId)).toBeTruthy();
|
|
|
|
|
|
|
|
// devices selected
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesMobileDevice.device_id)).toBeTruthy();
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesOlderMobileDevice.device_id)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selects all sessions when some sessions are already selected", async () => {
|
|
|
|
const { getByTestId, getByText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-04 11:12:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceSelection(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("device-select-all-checkbox"));
|
|
|
|
|
|
|
|
// header displayed correctly
|
|
|
|
expect(getByText("2 sessions selected")).toBeTruthy();
|
|
|
|
expect(isSelectAllChecked(getByTestId)).toBeTruthy();
|
|
|
|
|
|
|
|
// devices selected
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesMobileDevice.device_id)).toBeTruthy();
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesOlderMobileDevice.device_id)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("deselects all sessions when all sessions are selected", async () => {
|
|
|
|
const { getByTestId, getByText } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-04 11:12:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId("device-select-all-checkbox"));
|
|
|
|
|
|
|
|
// header displayed correctly
|
|
|
|
expect(getByText("2 sessions selected")).toBeTruthy();
|
|
|
|
expect(isSelectAllChecked(getByTestId)).toBeTruthy();
|
|
|
|
|
|
|
|
// devices selected
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesMobileDevice.device_id)).toBeTruthy();
|
|
|
|
expect(isDeviceSelected(getByTestId, alicesOlderMobileDevice.device_id)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selects only sessions that are part of the active filter", async () => {
|
|
|
|
mockClient.getDevices.mockResolvedValue({
|
|
|
|
devices: [alicesDevice, alicesMobileDevice, alicesInactiveDevice],
|
|
|
|
});
|
|
|
|
const { getByTestId, container } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-10-04 11:12:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// filter for inactive sessions
|
|
|
|
await setFilter(container, DeviceSecurityVariation.Inactive);
|
|
|
|
|
|
|
|
// select all inactive sessions
|
|
|
|
fireEvent.click(getByTestId("device-select-all-checkbox"));
|
|
|
|
|
|
|
|
expect(isSelectAllChecked(getByTestId)).toBeTruthy();
|
|
|
|
|
|
|
|
// sign out of all selected sessions
|
|
|
|
fireEvent.click(getByTestId("sign-out-selection-cta"));
|
2022-10-25 11:39:48 +03:00
|
|
|
await confirmSignout(getByTestId);
|
2022-10-04 11:12:07 +03:00
|
|
|
|
|
|
|
// only called with session from active filter
|
|
|
|
expect(mockClient.deleteMultipleDevices).toHaveBeenCalledWith(
|
|
|
|
[alicesInactiveDevice.device_id],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2022-09-30 10:07:50 +03:00
|
|
|
});
|
|
|
|
|
2022-09-27 15:35:54 +03:00
|
|
|
it("lets you change the pusher state", async () => {
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-27 15:35:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesMobileDevice.device_id);
|
|
|
|
|
|
|
|
// device details are expanded
|
|
|
|
expect(getByTestId(`device-detail-${alicesMobileDevice.device_id}`)).toBeTruthy();
|
|
|
|
expect(getByTestId("device-detail-push-notification")).toBeTruthy();
|
|
|
|
|
|
|
|
const checkbox = getByTestId("device-detail-push-notification-checkbox");
|
|
|
|
|
|
|
|
expect(checkbox).toBeTruthy();
|
|
|
|
fireEvent.click(checkbox);
|
|
|
|
|
|
|
|
expect(mockClient.setPusher).toHaveBeenCalled();
|
|
|
|
});
|
2022-09-28 20:18:10 +03:00
|
|
|
|
|
|
|
it("lets you change the local notification settings state", async () => {
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-28 20:18:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesDevice.device_id);
|
|
|
|
|
|
|
|
// device details are expanded
|
|
|
|
expect(getByTestId(`device-detail-${alicesDevice.device_id}`)).toBeTruthy();
|
|
|
|
expect(getByTestId("device-detail-push-notification")).toBeTruthy();
|
|
|
|
|
|
|
|
const checkbox = getByTestId("device-detail-push-notification-checkbox");
|
|
|
|
|
|
|
|
expect(checkbox).toBeTruthy();
|
|
|
|
fireEvent.click(checkbox);
|
|
|
|
|
|
|
|
expect(mockClient.setLocalNotificationSettings).toHaveBeenCalledWith(alicesDevice.device_id, {
|
|
|
|
is_silenced: true,
|
|
|
|
});
|
|
|
|
});
|
2022-09-29 22:05:06 +03:00
|
|
|
|
|
|
|
it("updates the UI when another session changes the local notifications", async () => {
|
|
|
|
const { getByTestId } = render(getComponent());
|
|
|
|
|
|
|
|
await act(async () => {
|
2022-10-25 11:39:48 +03:00
|
|
|
await flushPromises();
|
2022-09-29 22:05:06 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
toggleDeviceDetails(getByTestId, alicesDevice.device_id);
|
|
|
|
|
|
|
|
// device details are expanded
|
|
|
|
expect(getByTestId(`device-detail-${alicesDevice.device_id}`)).toBeTruthy();
|
|
|
|
expect(getByTestId("device-detail-push-notification")).toBeTruthy();
|
|
|
|
|
|
|
|
const checkbox = getByTestId("device-detail-push-notification-checkbox");
|
|
|
|
|
|
|
|
expect(checkbox).toBeTruthy();
|
|
|
|
|
|
|
|
expect(checkbox.getAttribute("aria-checked")).toEqual("true");
|
|
|
|
|
|
|
|
const evt = new MatrixEvent({
|
|
|
|
type: LOCAL_NOTIFICATION_SETTINGS_PREFIX.name + "." + alicesDevice.device_id,
|
|
|
|
content: {
|
|
|
|
is_silenced: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
mockClient.emit(ClientEvent.AccountData, evt);
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(checkbox.getAttribute("aria-checked")).toEqual("false");
|
|
|
|
});
|
2022-10-19 18:11:42 +03:00
|
|
|
|
|
|
|
describe("QR code login", () => {
|
|
|
|
const settingsValueSpy = jest.spyOn(SettingsStore, "getValue");
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
settingsValueSpy.mockClear().mockReturnValue(false);
|
|
|
|
// enable server support for qr login
|
|
|
|
mockClient.getVersions.mockResolvedValue({
|
|
|
|
versions: [],
|
|
|
|
unstable_features: {
|
|
|
|
"org.matrix.msc3886": true,
|
|
|
|
},
|
|
|
|
});
|
2023-04-06 11:06:12 +03:00
|
|
|
mockClient.getCapabilities.mockResolvedValue({
|
|
|
|
[UNSTABLE_MSC3882_CAPABILITY.name]: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
});
|
2022-10-19 18:11:42 +03:00
|
|
|
});
|
|
|
|
|
2023-02-17 12:27:57 +03:00
|
|
|
it("renders qr code login section", async () => {
|
2022-10-19 18:11:42 +03:00
|
|
|
const { getByText } = render(getComponent());
|
|
|
|
|
|
|
|
// wait for versions call to settle
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
expect(getByText("Sign in with QR code")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("enters qr code login section when show QR code button clicked", async () => {
|
|
|
|
const { getByText, getByTestId } = render(getComponent());
|
|
|
|
// wait for versions call to settle
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
fireEvent.click(getByText("Show QR code"));
|
|
|
|
|
|
|
|
expect(getByTestId("login-with-qr")).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2022-08-10 19:14:59 +03:00
|
|
|
});
|