-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathroute-dashboard.test.tsx
107 lines (85 loc) · 2.65 KB
/
route-dashboard.test.tsx
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { render } from '@/lib/test-utils'
import { screen, waitFor, within } from '@testing-library/react'
import { expect, it } from 'vitest'
import userEvent from '@testing-library/user-event'
import { RouteDashboard } from '../route-dashboard'
it('should mount alert summaries', async () => {
render(<RouteDashboard />)
expect(
screen.getByRole('heading', { name: /workspace token usage/i })
).toBeVisible()
expect(
screen.getByRole('heading', { name: /secrets redacted/i })
).toBeVisible()
expect(
screen.getByRole('heading', { name: /malicious packages/i })
).toBeVisible()
})
it('should render messages table', async () => {
render(<RouteDashboard />)
expect(
screen.getByRole('grid', {
name: /alerts table/i,
})
).toBeVisible()
})
it('shows only conversations with secrets when you click on the secrets tab', async () => {
render(<RouteDashboard />)
await waitFor(() => {
expect(screen.queryByText(/loading.../i)).not.toBeInTheDocument()
})
await userEvent.click(
screen.getByRole('tab', {
name: /secrets/i,
})
)
const tbody = screen.getAllByRole('rowgroup')[1] as HTMLElement
await waitFor(() => {
const secretsCountButtons = within(tbody).getAllByRole('button', {
name: /secrets count/,
}) as HTMLElement[]
secretsCountButtons.forEach((e) => {
expect(e).toHaveTextContent('10')
})
})
})
it('shows only conversations with pii when you click on the secrets tab', async () => {
render(<RouteDashboard />)
await waitFor(() => {
expect(screen.queryByText(/loading.../i)).not.toBeInTheDocument()
})
await userEvent.click(
screen.getByRole('tab', {
name: /pii/i,
})
)
const tbody = screen.getAllByRole('rowgroup')[1] as HTMLElement
await waitFor(() => {
const secretsCountButtons = within(tbody).getAllByRole('button', {
name: /personally identifiable information \(PII\) count/,
}) as HTMLElement[]
secretsCountButtons.forEach((e) => {
expect(e).toHaveTextContent('10')
})
})
})
it('shows only conversations with malicious when you click on the malicious tab', async () => {
render(<RouteDashboard />)
await waitFor(() => {
expect(screen.queryByText(/loading.../i)).not.toBeInTheDocument()
})
await userEvent.click(
screen.getByRole('tab', {
name: /malicious/i,
})
)
const tbody = screen.getAllByRole('rowgroup')[1] as HTMLElement
await waitFor(() => {
const secretsCountButtons = within(tbody).getAllByRole('button', {
name: /malicious packages count/,
}) as HTMLElement[]
secretsCountButtons.forEach((e) => {
expect(e).toHaveTextContent('10')
})
})
})