From e960e5d6bd116f1f3854b9e79451612310c3e951 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Tue, 9 Aug 2022 13:33:07 +0200 Subject: [PATCH] test other sessions section --- .../settings/tabs/user/SessionManagerTab.tsx | 1 + .../tabs/user/SessionManagerTab-test.tsx | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/components/views/settings/tabs/user/SessionManagerTab.tsx b/src/components/views/settings/tabs/user/SessionManagerTab.tsx index fcd519eee52a..cba3234caec2 100644 --- a/src/components/views/settings/tabs/user/SessionManagerTab.tsx +++ b/src/components/views/settings/tabs/user/SessionManagerTab.tsx @@ -48,6 +48,7 @@ const SessionManagerTab: React.FC = () => { `For best security, verify your sessions and sign out ` + `from any session that you don't recognize or use anymore.`, )} + data-testid='other-sessions-section' > diff --git a/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx b/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx index 4118cf765a02..f01c69a485a5 100644 --- a/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx +++ b/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx @@ -40,6 +40,12 @@ describe('', () => { }; const alicesMobileDevice = { device_id: 'alices_mobile_device', + last_seen_ts: Date.now(), + }; + + const alicesOlderMobileDevice = { + device_id: 'alices_older_mobile_device', + last_seen_ts: Date.now() - 600000, }; const mockCrossSigningInfo = { @@ -139,8 +145,6 @@ describe('', () => { it('renders current session section', async () => { mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] }); - const noCryptoError = new Error("End-to-end encryption disabled"); - mockClient.getStoredDevice.mockImplementation(() => { throw noCryptoError; }); const { getByTestId } = render(getComponent()); await act(async () => { @@ -149,4 +153,28 @@ describe('', () => { expect(getByTestId('current-session-section')).toMatchSnapshot(); }); + + 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 () => { + await flushPromisesWithFakeTimers(); + }); + + expect(queryByTestId('other-sessions-section')).toBeFalsy(); + }); + + it('renders other sessions section', async () => { + mockClient.getDevices.mockResolvedValue({ + devices: [alicesDevice, alicesOlderMobileDevice, alicesMobileDevice], + }); + const { getByTestId } = render(getComponent()); + + await act(async () => { + await flushPromisesWithFakeTimers(); + }); + + expect(getByTestId('other-sessions-section')).toBeTruthy(); + }); });