forked from line/centraldogma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.tsx
More file actions
92 lines (79 loc) · 2.65 KB
/
index.test.tsx
File metadata and controls
92 lines (79 loc) · 2.65 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
84
85
86
87
88
89
90
91
92
import '@testing-library/jest-dom';
import { renderWithProviders } from 'dogma/util/test-utils';
import AppIdentityPage from 'pages/app/settings/app-identities';
import { AppIdentityDto } from 'dogma/features/app-identity/AppIdentity';
import { useGetAppIdentitiesQuery } from 'dogma/features/api/apiSlice';
jest.mock('dogma/features/api/apiSlice', () => ({
...jest.requireActual('dogma/features/api/apiSlice'),
useGetAppIdentitiesQuery: jest.fn(),
}));
jest.mock('next/router', () => ({
useRouter: () => ({ asPath: '/app/settings/app-identities' }),
}));
const mockIdentities: AppIdentityDto[] = [
{
appId: 'app-token-1',
type: 'TOKEN',
systemAdmin: false,
allowGuestAccess: false,
creation: { user: 'user@example.com', timestamp: '2024-01-01T00:00:00Z' },
},
{
appId: 'app-admin-1',
type: 'TOKEN',
systemAdmin: true,
allowGuestAccess: false,
creation: { user: 'admin@example.com', timestamp: '2024-01-02T00:00:00Z' },
},
];
const baseAuthState = {
isInAnonymousMode: false,
csrfToken: null,
isLoading: false,
user: {
login: 'user',
name: 'Test User',
email: 'user@example.com',
roles: [],
systemAdmin: false,
},
};
describe('AppIdentityPage', () => {
beforeEach(() => {
(useGetAppIdentitiesQuery as jest.Mock).mockReturnValue({
data: mockIdentities,
error: undefined,
isLoading: false,
});
});
it('hides the Level column for non-system-admin users', () => {
const { queryByText } = renderWithProviders(<AppIdentityPage />, {
preloadedState: { auth: baseAuthState },
});
expect(queryByText('Level')).not.toBeInTheDocument();
});
it('shows the Level column for system-admin users', () => {
const { getByText } = renderWithProviders(<AppIdentityPage />, {
preloadedState: {
auth: { ...baseAuthState, user: { ...baseAuthState.user, systemAdmin: true } },
},
});
expect(getByText('Level')).toBeInTheDocument();
});
it('renders System Admin and User badges in the Level column for system-admin users', () => {
const { getByText } = renderWithProviders(<AppIdentityPage />, {
preloadedState: {
auth: { ...baseAuthState, user: { ...baseAuthState.user, systemAdmin: true } },
},
});
expect(getByText('System Admin')).toBeInTheDocument();
expect(getByText('User')).toBeInTheDocument();
});
it('displays app identities in the table', () => {
const { getByText } = renderWithProviders(<AppIdentityPage />, {
preloadedState: { auth: baseAuthState },
});
expect(getByText('app-token-1')).toBeInTheDocument();
expect(getByText('app-admin-1')).toBeInTheDocument();
});
});