forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurityTab.test.tsx
More file actions
83 lines (69 loc) · 2.33 KB
/
Copy pathSecurityTab.test.tsx
File metadata and controls
83 lines (69 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import React from 'react';
const getSessions = vi.fn();
const revokeSession = vi.fn();
const showToast = vi.fn();
vi.mock('../../../lib/store', () => ({
appStore: {
showToast: (...args: unknown[]) => showToast(...args),
},
}));
vi.mock('../../../lib/api', () => ({
apiClient: {
post: vi.fn(),
},
}));
vi.mock('../../../services/api', () => ({
apiService: {
getSessions: (...args: unknown[]) => getSessions(...args),
revokeSession: (...args: unknown[]) => revokeSession(...args),
},
}));
import { SecurityTab } from './SecurityTab';
describe('SecurityTab session review', () => {
beforeEach(() => {
vi.clearAllMocks();
getSessions.mockResolvedValue([
{
id: 'sess-current',
device_label: 'Chrome on macOS',
ip_address: '1.2.3.4',
created_at: new Date().toISOString(),
last_active_at: new Date().toISOString(),
is_current: true,
},
{
id: 'sess-other',
device_label: 'Firefox on Linux',
ip_address: '5.6.7.8',
created_at: new Date(Date.now() - 3_600_000).toISOString(),
last_active_at: new Date(Date.now() - 3_600_000).toISOString(),
is_current: false,
},
]);
revokeSession.mockResolvedValue(undefined);
});
it('loads and lists sessions when Review Sessions is clicked', async () => {
render(<SecurityTab />);
fireEvent.click(screen.getByRole('button', { name: 'Review Sessions' }));
await waitFor(() => {
expect(getSessions).toHaveBeenCalledTimes(1);
});
expect(await screen.findByText('Chrome on macOS')).toBeTruthy();
expect(screen.getByText('Firefox on Linux')).toBeTruthy();
expect(screen.getByText('Current')).toBeTruthy();
});
it('revokes a non-current session', async () => {
render(<SecurityTab />);
fireEvent.click(screen.getByRole('button', { name: 'Review Sessions' }));
await screen.findByText('Firefox on Linux');
fireEvent.click(
screen.getByRole('button', { name: 'Revoke session for Firefox on Linux' })
);
await waitFor(() => {
expect(revokeSession).toHaveBeenCalledWith('sess-other');
});
expect(showToast).toHaveBeenCalledWith('Session revoked', 'success');
});
});