From edce2aada7e5c3ced115b3fba46f9804257761ee Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 11:07:58 +0200 Subject: [PATCH 01/13] promote new session manager to beta --- src/i18n/strings/en_EN.json | 2 ++ src/settings/Settings.tsx | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 7a6b984563d..ae307b0da10 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -922,6 +922,8 @@ "Favourite Messages (under active development)": "Favourite Messages (under active development)", "Voice broadcast (under active development)": "Voice broadcast (under active development)", "Use new session manager (under active development)": "Use new session manager (under active development)", + "New session manager": "New session manager", + "TODO": "TODO", "Font size": "Font size", "Use custom size": "Use custom size", "Enable Emoji suggestions while typing": "Enable Emoji suggestions while typing", diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 52538f7291b..2ff73d4f6de 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -470,6 +470,10 @@ export const SETTINGS: {[setting: string]: ISetting} = { supportedLevels: LEVELS_FEATURE, displayName: _td("Use new session manager (under active development)"), default: false, + betaInfo: { + title: _td('New session manager'), + caption: () => _td('TODO'), + }, }, "baseFontSize": { displayName: _td("Font size"), From bb226487754c6482ab0fa480cec577703e13e07f Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 11:14:22 +0200 Subject: [PATCH 02/13] hide old sessions section when new dm enabled --- .../tabs/user/SecurityUserSettingsTab.tsx | 25 +++++++++++-------- src/settings/Settings.tsx | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx index 91b448eb3b0..3b61a64b9fb 100644 --- a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx @@ -346,19 +346,24 @@ export default class SecurityUserSettingsTab extends React.Component +
{ _t("Where you're signed in") }
+
+ + { _t( + "Manage your signed-in devices below. " + + "A device's name is visible to people you communicate with.", + ) } + + +
+ : null; + return (
{ warning } -
{ _t("Where you're signed in") }
-
- - { _t( - "Manage your signed-in devices below. " + - "A device's name is visible to people you communicate with.", - ) } - - -
+ { devicesSection }
{ _t("Encryption") }
{ secureBackup } diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 2ff73d4f6de..cd5a3b575c8 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -468,7 +468,7 @@ export const SETTINGS: {[setting: string]: ISetting} = { isFeature: true, labsGroup: LabGroup.Experimental, supportedLevels: LEVELS_FEATURE, - displayName: _td("Use new session manager (under active development)"), + displayName: _td("Use new session manager"), default: false, betaInfo: { title: _td('New session manager'), From a9bbf26efded5e90e8a469d870cc411afa5e8e00 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 11:17:26 +0200 Subject: [PATCH 03/13] use correct logic --- .../tabs/user/SecurityUserSettingsTab.tsx | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx index 3b61a64b9fb..b4aad064e44 100644 --- a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx @@ -347,18 +347,20 @@ export default class SecurityUserSettingsTab extends React.Component -
{ _t("Where you're signed in") }
-
- - { _t( - "Manage your signed-in devices below. " + - "A device's name is visible to people you communicate with.", - ) } - - -
- : null; + const devicesSection = useNewSessionManager + ? null + : <> +
{ _t("Where you're signed in") }
+
+ + { _t( + "Manage your signed-in devices below. " + + "A device's name is visible to people you communicate with.", + ) } + + +
+ ; return (
From 052ec0f557e757fbf11eca0c8dba5b20c895c650 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 11:38:36 +0200 Subject: [PATCH 04/13] add new ViewUserDeviceSettings action --- .../handlers/viewUserDeviceSettings.ts | 30 ++++++++++++ src/components/structures/MatrixChat.tsx | 5 ++ src/dispatcher/actions.ts | 5 ++ .../handlers/viewUserDeviceSettings-test.ts | 48 +++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 src/actions/handlers/viewUserDeviceSettings.ts create mode 100644 test/actions/handlers/viewUserDeviceSettings-test.ts diff --git a/src/actions/handlers/viewUserDeviceSettings.ts b/src/actions/handlers/viewUserDeviceSettings.ts new file mode 100644 index 00000000000..e1dc7b3f268 --- /dev/null +++ b/src/actions/handlers/viewUserDeviceSettings.ts @@ -0,0 +1,30 @@ +/* +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 { UserTab } from "../../components/views/dialogs/UserTab"; +import { Action } from "../../dispatcher/actions"; +import defaultDispatcher from "../../dispatcher/dispatcher"; + +/** + * Redirect to the correct device manager section + * Based on the labs setting + */ +export const viewUserDeviceSettings = (isNewDeviceManagerEnabled: boolean) => { + defaultDispatcher.dispatch({ + action: Action.ViewUserSettings, + initialTabId: isNewDeviceManagerEnabled ? UserTab.SessionManager : UserTab.Security, + }); +}; diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 6dd2820aa17..923f4610925 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -137,6 +137,7 @@ import { TimelineRenderingType } from "../../contexts/RoomContext"; import { UseCaseSelection } from '../views/elements/UseCaseSelection'; import { ValidatedServerConfig } from '../../utils/ValidatedServerConfig'; import { isLocalRoom } from '../../utils/localRoom/isLocalRoom'; +import { viewUserDeviceSettings } from '../../actions/handlers/viewUserDeviceSettings'; // legacy export export { default as Views } from "../../Views"; @@ -677,6 +678,10 @@ export default class MatrixChat extends React.PureComponent { } break; } + case Action.ViewUserDeviceSettings: { + viewUserDeviceSettings(SettingsStore.getValue("feature_new_device_manager")); + break; + } case Action.ViewUserSettings: { const tabPayload = payload as OpenToTabPayload; Modal.createDialog(UserSettingsDialog, diff --git a/src/dispatcher/actions.ts b/src/dispatcher/actions.ts index 4e161a70051..2b2e443e81d 100644 --- a/src/dispatcher/actions.ts +++ b/src/dispatcher/actions.ts @@ -40,6 +40,11 @@ export enum Action { */ ViewUserSettings = "view_user_settings", + /** + * Open the user device settings. No additional payload information required. + */ + ViewUserDeviceSettings = "view_user_device_settings", + /** * Opens the room directory. No additional payload information required. */ diff --git a/test/actions/handlers/viewUserDeviceSettings-test.ts b/test/actions/handlers/viewUserDeviceSettings-test.ts new file mode 100644 index 00000000000..72d1db430db --- /dev/null +++ b/test/actions/handlers/viewUserDeviceSettings-test.ts @@ -0,0 +1,48 @@ +/* +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 { viewUserDeviceSettings } from "../../../src/actions/handlers/viewUserDeviceSettings"; +import { UserTab } from "../../../src/components/views/dialogs/UserTab"; +import { Action } from "../../../src/dispatcher/actions"; +import defaultDispatcher from "../../../src/dispatcher/dispatcher"; + +describe('viewUserDeviceSettings()', () => { + const dispatchSpy = jest.spyOn(defaultDispatcher, 'dispatch'); + + beforeEach(() => { + dispatchSpy.mockClear(); + }); + + it('dispatches action to view new session manager when enabled', () => { + const isNewDeviceManagerEnabled = true; + viewUserDeviceSettings(isNewDeviceManagerEnabled); + + expect(dispatchSpy).toHaveBeenCalledWith({ + action: Action.ViewUserSettings, + initialTabId: UserTab.SessionManager, + }); + }); + + it('dispatches action to view old session manager when disabled', () => { + const isNewDeviceManagerEnabled = false; + viewUserDeviceSettings(isNewDeviceManagerEnabled); + + expect(dispatchSpy).toHaveBeenCalledWith({ + action: Action.ViewUserSettings, + initialTabId: UserTab.Security, + }); + }); +}); From cd7892940ea5937c62196b8b6f1afb436bb851ab Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 11:43:26 +0200 Subject: [PATCH 05/13] replace device management ctas with viewUserDeviceSettings --- src/components/views/right_panel/UserInfo.tsx | 4 +--- src/toasts/BulkUnverifiedSessionsToast.ts | 4 +--- src/toasts/UnverifiedSessionToast.ts | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index 45489603ba8..810ae48dd71 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -48,7 +48,6 @@ import EncryptionPanel from "./EncryptionPanel"; import { useAsyncMemo } from '../../../hooks/useAsyncMemo'; import { legacyVerifyUser, verifyDevice, verifyUser } from '../../../verification'; import { Action } from "../../../dispatcher/actions"; -import { UserTab } from "../dialogs/UserTab"; import { useIsEncrypted } from "../../../hooks/useIsEncrypted"; import BaseCard from "./BaseCard"; import { E2EStatus } from "../../../utils/ShieldUtils"; @@ -1331,8 +1330,7 @@ const BasicUserInfo: React.FC<{ className="mx_UserInfo_field" onClick={() => { dis.dispatch({ - action: Action.ViewUserSettings, - initialTabId: UserTab.Security, + action: Action.ViewUserDeviceSettings, }); }} > diff --git a/src/toasts/BulkUnverifiedSessionsToast.ts b/src/toasts/BulkUnverifiedSessionsToast.ts index 6ddb0d7db57..0113f2f030a 100644 --- a/src/toasts/BulkUnverifiedSessionsToast.ts +++ b/src/toasts/BulkUnverifiedSessionsToast.ts @@ -20,7 +20,6 @@ import DeviceListener from '../DeviceListener'; import GenericToast from "../components/views/toasts/GenericToast"; import ToastStore from "../stores/ToastStore"; import { Action } from "../dispatcher/actions"; -import { UserTab } from "../components/views/dialogs/UserTab"; const TOAST_KEY = "reviewsessions"; @@ -29,8 +28,7 @@ export const showToast = (deviceIds: Set) => { DeviceListener.sharedInstance().dismissUnverifiedSessions(deviceIds); dis.dispatch({ - action: Action.ViewUserSettings, - initialTabId: UserTab.Security, + action: Action.ViewUserDeviceSettings, }); }; diff --git a/src/toasts/UnverifiedSessionToast.ts b/src/toasts/UnverifiedSessionToast.ts index d0db97cd08f..f2d637ef0d9 100644 --- a/src/toasts/UnverifiedSessionToast.ts +++ b/src/toasts/UnverifiedSessionToast.ts @@ -21,7 +21,6 @@ import DeviceListener from '../DeviceListener'; import ToastStore from "../stores/ToastStore"; import GenericToast from "../components/views/toasts/GenericToast"; import { Action } from "../dispatcher/actions"; -import { UserTab } from "../components/views/dialogs/UserTab"; function toastKey(deviceId: string) { return "unverified_session_" + deviceId; @@ -33,8 +32,7 @@ export const showToast = async (deviceId: string) => { const onAccept = () => { DeviceListener.sharedInstance().dismissUnverifiedSessions([deviceId]); dis.dispatch({ - action: Action.ViewUserSettings, - initialTabId: UserTab.Security, + action: Action.ViewUserDeviceSettings, }); }; From 98e58e24b939971d8b7aa7376c50a2cca044f80a Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 12:14:53 +0200 Subject: [PATCH 06/13] test SecurityUserSettingsTab --- .../tabs/user/SecurityUserSettingsTab.tsx | 5 +- src/i18n/strings/en_EN.json | 2 +- .../user/SecurityUserSettingsTab-test.tsx | 68 +++++++++++++++++++ test/test-utils/client.ts | 16 +++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 test/components/views/settings/tabs/user/SecurityUserSettingsTab-test.tsx diff --git a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx index b4aad064e44..f4e4e55513d 100644 --- a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx @@ -351,7 +351,10 @@ export default class SecurityUserSettingsTab extends React.Component
{ _t("Where you're signed in") }
-
+
{ _t( "Manage your signed-in devices below. " + diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index ae307b0da10..47b2d00c0ce 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -921,7 +921,7 @@ "Live Location Sharing (temporary implementation: locations persist in room history)": "Live Location Sharing (temporary implementation: locations persist in room history)", "Favourite Messages (under active development)": "Favourite Messages (under active development)", "Voice broadcast (under active development)": "Voice broadcast (under active development)", - "Use new session manager (under active development)": "Use new session manager (under active development)", + "Use new session manager": "Use new session manager", "New session manager": "New session manager", "TODO": "TODO", "Font size": "Font size", diff --git a/test/components/views/settings/tabs/user/SecurityUserSettingsTab-test.tsx b/test/components/views/settings/tabs/user/SecurityUserSettingsTab-test.tsx new file mode 100644 index 00000000000..bddb493463f --- /dev/null +++ b/test/components/views/settings/tabs/user/SecurityUserSettingsTab-test.tsx @@ -0,0 +1,68 @@ +/* +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 { render } from '@testing-library/react'; +import React from 'react'; + +import SecurityUserSettingsTab from "../../../../../../src/components/views/settings/tabs/user/SecurityUserSettingsTab"; +import SettingsStore from '../../../../../../src/settings/SettingsStore'; +import { + getMockClientWithEventEmitter, + mockClientMethodsServer, + mockClientMethodsUser, + mockClientMethodsCrypto, + mockClientMethodsDevice, + mockPlatformPeg, +} from '../../../../../test-utils'; + +describe('', () => { + const defaultProps = { + closeSettingsFn: jest.fn(), + }; + const getComponent = () => ; + + const userId = '@alice:server.org'; + const deviceId = 'alices-device'; + getMockClientWithEventEmitter({ + ...mockClientMethodsUser(userId), + ...mockClientMethodsServer(), + ...mockClientMethodsDevice(deviceId), + ...mockClientMethodsCrypto(), + getRooms: jest.fn().mockReturnValue([]), + getIgnoredUsers: jest.fn(), + }); + + const settingsValueSpy = jest.spyOn(SettingsStore, 'getValue'); + + beforeEach(() => { + mockPlatformPeg(); + jest.clearAllMocks(); + settingsValueSpy.mockReturnValue(false); + }); + + it('renders sessions section when new session manager is disabled', () => { + settingsValueSpy.mockReturnValue(false); + const { getByTestId } = render(getComponent()); + + expect(getByTestId('devices-section')).toBeTruthy(); + }); + + it('does not render sessions section when new session manager is enabled', () => { + settingsValueSpy.mockReturnValue(true); + const { queryByTestId } = render(getComponent()); + + expect(queryByTestId('devices-section')).toBeFalsy(); + }); +}); diff --git a/test/test-utils/client.ts b/test/test-utils/client.ts index 4a5b3184913..1f91a3cf161 100644 --- a/test/test-utils/client.ts +++ b/test/test-utils/client.ts @@ -71,6 +71,7 @@ export const mockClientMethodsUser = (userId = '@alice:domain') => ({ credentials: { userId }, getThreePids: jest.fn().mockResolvedValue({ threepids: [] }), getAccessToken: jest.fn(), + getDeviceId: jest.fn(), }); /** @@ -94,6 +95,21 @@ export const mockClientMethodsServer = (): Partial, unknown>> => ({ + getDeviceId: jest.fn().mockReturnValue(deviceId), + getDeviceEd25519Key: jest.fn(), + getDevices: jest.fn().mockResolvedValue({ devices: [] }), +}); + +export const mockClientMethodsCrypto = (): Partial, unknown>> => ({ + isCryptoEnabled: jest.fn(), + getCrossSigningCacheCallbacks: jest.fn(), + checkKeyBackup: jest.fn(), +}); + From ded73ead44964ce1b070d905859a93b8214cbc29 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 13:01:51 +0200 Subject: [PATCH 07/13] more complete mocks --- test/test-utils/client.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/test-utils/client.ts b/test/test-utils/client.ts index 1f91a3cf161..1ff05d1ff46 100644 --- a/test/test-utils/client.ts +++ b/test/test-utils/client.ts @@ -15,7 +15,7 @@ limitations under the License. */ import EventEmitter from "events"; -import { MethodKeysOf, mocked, MockedObject } from "jest-mock"; +import { MethodKeysOf, mocked, MockedObject, PropertyKeysOf } from "jest-mock"; import { MatrixClient, User } from "matrix-js-sdk/src/matrix"; import { MatrixClientPeg } from "../../src/MatrixClientPeg"; @@ -107,9 +107,18 @@ export const mockClientMethodsDevice = ( getDevices: jest.fn().mockResolvedValue({ devices: [] }), }); -export const mockClientMethodsCrypto = (): Partial, unknown>> => ({ +export const mockClientMethodsCrypto = (): Partial & PropertyKeysOf, unknown> +> => ({ isCryptoEnabled: jest.fn(), + isSecretStorageReady: jest.fn(), + isKeyBackupKeyStored: jest.fn(), getCrossSigningCacheCallbacks: jest.fn(), - checkKeyBackup: jest.fn(), + getStoredCrossSigningForUser: jest.fn(), + checkKeyBackup: jest.fn().mockReturnValue({}), + crypto: { + getSessionBackupPrivateKey: jest.fn(), + secretStorage: { hasKey: jest.fn() }, + }, }); From 5fade3c3d900cb5cddb91df1e7fa66a3c0c5381a Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 13:17:30 +0200 Subject: [PATCH 08/13] more thorough mocks --- test/test-utils/client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test-utils/client.ts b/test/test-utils/client.ts index 1ff05d1ff46..48ac1738b83 100644 --- a/test/test-utils/client.ts +++ b/test/test-utils/client.ts @@ -113,12 +113,16 @@ export const mockClientMethodsCrypto = (): Partial Date: Mon, 10 Oct 2022 14:30:51 +0200 Subject: [PATCH 09/13] more mocks --- test/test-utils/client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test-utils/client.ts b/test/test-utils/client.ts index 48ac1738b83..d6ec3f2fd33 100644 --- a/test/test-utils/client.ts +++ b/test/test-utils/client.ts @@ -112,6 +112,7 @@ export const mockClientMethodsCrypto = (): Partial => ({ isCryptoEnabled: jest.fn(), isSecretStorageReady: jest.fn(), + isCrossSigningReady: jest.fn(), isKeyBackupKeyStored: jest.fn(), getCrossSigningCacheCallbacks: jest.fn().mockReturnValue({ getCrossSigningKeyCache: jest.fn() }), getStoredCrossSigningForUser: jest.fn(), From d7ecd115bf2c1a115249136f82c0663ca7d32645 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 16:06:59 +0200 Subject: [PATCH 10/13] test LabsUserSettingsTab --- .../tabs/user/LabsUserSettingsTab.tsx | 11 +- .../tabs/user/LabsUserSettingsTab-test.tsx | 74 +++++++ .../LabsUserSettingsTab-test.tsx.snap | 191 ++++++++++++++++++ 3 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx create mode 100644 test/components/views/settings/tabs/user/__snapshots__/LabsUserSettingsTab-test.tsx.snap diff --git a/src/components/views/settings/tabs/user/LabsUserSettingsTab.tsx b/src/components/views/settings/tabs/user/LabsUserSettingsTab.tsx index 80e2ebb6cf1..60575876267 100644 --- a/src/components/views/settings/tabs/user/LabsUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/LabsUserSettingsTab.tsx @@ -80,7 +80,10 @@ export default class LabsUserSettingsTab extends React.Component<{}, IState> { let betaSection; if (betas.length) { - betaSection =
+ betaSection =
{ betas.map(f => ) }
; } @@ -137,7 +140,11 @@ export default class LabsUserSettingsTab extends React.Component<{}, IState> { labsSections = <> { sortBy(Array.from(groups.entries()), "0").map(([group, flags]) => ( -
+
{ _t(labGroupNames[group]) } { flags }
diff --git a/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx b/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx new file mode 100644 index 00000000000..d13615206b4 --- /dev/null +++ b/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx @@ -0,0 +1,74 @@ +/* +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'; +import { render } from '@testing-library/react'; + +import LabsUserSettingsTab from '../../../../../../src/components/views/settings/tabs/user/LabsUserSettingsTab'; +import SettingsStore from '../../../../../../src/settings/SettingsStore'; +import { + getMockClientWithEventEmitter, + mockClientMethodsServer, + mockClientMethodsUser, +} from '../../../../../test-utils'; +import SdkConfig from '../../../../../../src/SdkConfig'; + +describe('', () => { + + const sdkConfigSpy = jest.spyOn(SdkConfig, 'get'); + + const defaultProps = { + closeSettingsFn: jest.fn(), + }; + const getComponent = () => ; + + const userId = '@alice:server.org'; + getMockClientWithEventEmitter({ + ...mockClientMethodsUser(userId), + ...mockClientMethodsServer(), + }); + + const settingsValueSpy = jest.spyOn(SettingsStore, 'getValue'); + + beforeEach(() => { + jest.clearAllMocks(); + settingsValueSpy.mockReturnValue(false); + sdkConfigSpy.mockReturnValue(false); + }); + + it('renders settings marked as beta as beta cards', () => { + const { getByTestId } = render(getComponent()); + expect(getByTestId("labs-beta-section")).toMatchSnapshot(); + }); + + it('does not render non-beta labs settings when disabled in config', () => { + const { container } = render(getComponent()); + expect(sdkConfigSpy).toHaveBeenCalledWith('show_labs_settings'); + + const labsSections = container.getElementsByClassName('mx_SettingsTab_section'); + // only section is beta section + expect(labsSections.length).toEqual(1); + }); + + it('renders non-beta labs settings when enabled in config', () => { + // enable labs + sdkConfigSpy.mockImplementation(configName => configName === 'show_labs_settings'); + const { container } = render(getComponent()); + + const labsSections = container.getElementsByClassName('mx_SettingsTab_section'); + expect(labsSections.length).toEqual(11); + }); +}); diff --git a/test/components/views/settings/tabs/user/__snapshots__/LabsUserSettingsTab-test.tsx.snap b/test/components/views/settings/tabs/user/__snapshots__/LabsUserSettingsTab-test.tsx.snap new file mode 100644 index 00000000000..f560cbcfa0d --- /dev/null +++ b/test/components/views/settings/tabs/user/__snapshots__/LabsUserSettingsTab-test.tsx.snap @@ -0,0 +1,191 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` renders settings marked as beta as beta cards 1`] = ` +
+
+
+
+

+ + Video rooms + + + Beta + +

+
+

+ A new way to chat over voice and video in . +

+

+ Video rooms are always-on VoIP channels embedded within a room in . +

+
+
+
+ Join the beta +
+
+
+ Joining the beta will reload . +
+
+
+
+ +
+
+
+
+
+
+

+ + Threads + + + Beta + +

+
+

+ Keep discussions organised with threads. +

+

+ + Threads help keep conversations on-topic and easy to track. + + Learn more + + . + +

+
+
+
+ Join the beta +
+
+
+ Joining the beta will reload . +
+
+
+
+ +
+
+
+
+
+
+

+ + New session manager + + + Beta + +

+
+ TODO +
+
+
+ Join the beta +
+
+
+
+ +
+
+
+
+`; From bfd8125ce77d16f8d1194fd5db7de154d5d161ab Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 16:09:49 +0200 Subject: [PATCH 11/13] lint --- .../views/settings/tabs/user/LabsUserSettingsTab-test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx b/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx index d13615206b4..614bb4062f0 100644 --- a/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx +++ b/test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx @@ -27,7 +27,6 @@ import { import SdkConfig from '../../../../../../src/SdkConfig'; describe('', () => { - const sdkConfigSpy = jest.spyOn(SdkConfig, 'get'); const defaultProps = { From fdef6b33702cd12693ffaefc814b6ec969a2df4b Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 16:14:23 +0200 Subject: [PATCH 12/13] updated copy --- src/i18n/strings/en_EN.json | 3 ++- src/settings/Settings.tsx | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 47b2d00c0ce..5716ab03de7 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -923,7 +923,8 @@ "Voice broadcast (under active development)": "Voice broadcast (under active development)", "Use new session manager": "Use new session manager", "New session manager": "New session manager", - "TODO": "TODO", + "Have greater visibility and control over all your sessions.": "Have greater visibility and control over all your sessions.", + "Our new sessions manager provides better visibility of all your sessions, and greater control over them including the ability to remotely toggle push notifications.": "Our new sessions manager provides better visibility of all your sessions, and greater control over them including the ability to remotely toggle push notifications.", "Font size": "Font size", "Use custom size": "Use custom size", "Enable Emoji suggestions while typing": "Enable Emoji suggestions while typing", diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index cd5a3b575c8..658ce6ee5e1 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -472,7 +472,19 @@ export const SETTINGS: {[setting: string]: ISetting} = { default: false, betaInfo: { title: _td('New session manager'), - caption: () => _td('TODO'), + caption: () => <> +

+ { _td('Have greater visibility and control over all your sessions.') } +

+

+ { _td( + 'Our new sessions manager provides better visibility of all your sessions, ' + + 'and greater control over them including the ability to remotely toggle push notifications.', + ) + } +

+ + , }, }, "baseFontSize": { From 56af9d098e22dbb1dde3055224f8961e36db6dbd Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 16:17:15 +0200 Subject: [PATCH 13/13] update snaps for new copy --- .../user/__snapshots__/LabsUserSettingsTab-test.tsx.snap | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/components/views/settings/tabs/user/__snapshots__/LabsUserSettingsTab-test.tsx.snap b/test/components/views/settings/tabs/user/__snapshots__/LabsUserSettingsTab-test.tsx.snap index f560cbcfa0d..b2ff84a8233 100644 --- a/test/components/views/settings/tabs/user/__snapshots__/LabsUserSettingsTab-test.tsx.snap +++ b/test/components/views/settings/tabs/user/__snapshots__/LabsUserSettingsTab-test.tsx.snap @@ -163,7 +163,12 @@ exports[` renders settings marked as beta as beta car
- TODO +

+ Have greater visibility and control over all your sessions. +

+

+ Our new sessions manager provides better visibility of all your sessions, and greater control over them including the ability to remotely toggle push notifications. +