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

Commit

Permalink
test other sessions section
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry Archibald committed Aug 9, 2022
1 parent 6d4d405 commit e960e5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
>
<FilteredDeviceList devices={otherDevices} />
</SettingsSubsection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ describe('<SessionManagerTab />', () => {
};
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 = {
Expand Down Expand Up @@ -139,8 +145,6 @@ describe('<SessionManagerTab />', () => {

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 () => {
Expand All @@ -149,4 +153,28 @@ describe('<SessionManagerTab />', () => {

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();
});
});

0 comments on commit e960e5d

Please sign in to comment.