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

Commit e960e5d

Browse files
author
Kerry Archibald
committed
test other sessions section
1 parent 6d4d405 commit e960e5d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/components/views/settings/tabs/user/SessionManagerTab.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const SessionManagerTab: React.FC = () => {
4848
`For best security, verify your sessions and sign out ` +
4949
`from any session that you don't recognize or use anymore.`,
5050
)}
51+
data-testid='other-sessions-section'
5152
>
5253
<FilteredDeviceList devices={otherDevices} />
5354
</SettingsSubsection>

test/components/views/settings/tabs/user/SessionManagerTab-test.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ describe('<SessionManagerTab />', () => {
4040
};
4141
const alicesMobileDevice = {
4242
device_id: 'alices_mobile_device',
43+
last_seen_ts: Date.now(),
44+
};
45+
46+
const alicesOlderMobileDevice = {
47+
device_id: 'alices_older_mobile_device',
48+
last_seen_ts: Date.now() - 600000,
4349
};
4450

4551
const mockCrossSigningInfo = {
@@ -139,8 +145,6 @@ describe('<SessionManagerTab />', () => {
139145

140146
it('renders current session section', async () => {
141147
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
142-
const noCryptoError = new Error("End-to-end encryption disabled");
143-
mockClient.getStoredDevice.mockImplementation(() => { throw noCryptoError; });
144148
const { getByTestId } = render(getComponent());
145149

146150
await act(async () => {
@@ -149,4 +153,28 @@ describe('<SessionManagerTab />', () => {
149153

150154
expect(getByTestId('current-session-section')).toMatchSnapshot();
151155
});
156+
157+
it('does not render other sessions section when user has only one device', async () => {
158+
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice] });
159+
const { queryByTestId } = render(getComponent());
160+
161+
await act(async () => {
162+
await flushPromisesWithFakeTimers();
163+
});
164+
165+
expect(queryByTestId('other-sessions-section')).toBeFalsy();
166+
});
167+
168+
it('renders other sessions section', async () => {
169+
mockClient.getDevices.mockResolvedValue({
170+
devices: [alicesDevice, alicesOlderMobileDevice, alicesMobileDevice],
171+
});
172+
const { getByTestId } = render(getComponent());
173+
174+
await act(async () => {
175+
await flushPromisesWithFakeTimers();
176+
});
177+
178+
expect(getByTestId('other-sessions-section')).toBeTruthy();
179+
});
152180
});

0 commit comments

Comments
 (0)