@bevel-software/platform-core-frontend 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/package.json +2 -2
  2. package/src/core/__tests__/ShellRoutes.test.tsx +95 -95
  3. package/src/lib/utils.ts +138 -138
  4. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +156 -156
  5. package/src/modules/admin/components/UserAccountsPage.tsx +353 -353
  6. package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -104
  7. package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -200
  8. package/src/modules/library/__tests__/loadout.test.tsx +72 -72
  9. package/src/modules/library/__tests__/status.test.ts +117 -117
  10. package/src/modules/library/components/ChangeRequestDock.tsx +47 -47
  11. package/src/modules/library/components/CompareView.tsx +357 -357
  12. package/src/modules/library/components/DetailDialog.tsx +566 -566
  13. package/src/modules/library/components/GearIcon.tsx +12 -12
  14. package/src/modules/library/components/LibraryCard.tsx +132 -132
  15. package/src/modules/library/components/LibraryPage.tsx +254 -254
  16. package/src/modules/library/components/LoadoutSidebar.tsx +156 -156
  17. package/src/modules/library/components/StatusGem.tsx +21 -21
  18. package/src/modules/library/components/SuggestChange.tsx +171 -171
  19. package/src/modules/library/components/particles.ts +50 -50
  20. package/src/modules/library/library.css +320 -320
  21. package/src/modules/library/state/loadout.tsx +129 -129
  22. package/src/modules/library/utils/status.ts +116 -116
  23. package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -276
  24. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -51
  25. package/src/modules/toolbar/components/AppSwitcher.tsx +108 -108
  26. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -548
  27. package/src/modules/workspace/components/FileExplorer.tsx +1068 -1068
  28. package/src/modules/workspace/components/FileViewer.tsx +906 -906
  29. package/src/modules/workspace/utils/fileTree.ts +179 -179
  30. package/src/shared/components/PageShell.tsx +51 -51
@@ -1,156 +1,156 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { render, screen, waitFor, within } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { UserAccountsPage } from '../components/UserAccountsPage';
5
- import { AdminContext } from '../state/admin.context';
6
- import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
7
- import {
8
- createAccount,
9
- deleteAccount,
10
- listAccounts,
11
- } from '../../auth/services/account.api';
12
-
13
- vi.mock('../../auth/services/account.api', () => ({
14
- createAccount: vi.fn(),
15
- deleteAccount: vi.fn(),
16
- listAccounts: vi.fn(),
17
- }));
18
-
19
- const ME = { id: 'admin-1', email: 'admin@example.com', name: 'Admin' };
20
- const ALICE = {
21
- id: 'u-alice',
22
- email: 'alice@example.com',
23
- name: 'Alice',
24
- hasPassword: false,
25
- createdAt: '2026-01-01T00:00:00Z',
26
- };
27
-
28
- function renderPage(opts: { isAdmin?: boolean } = {}) {
29
- const auth: AuthContextValue = {
30
- user: ME,
31
- token: 't',
32
- isLoading: false,
33
- login: vi.fn(async () => {}),
34
- logout: vi.fn(),
35
- };
36
- return render(
37
- <AuthContext.Provider value={auth}>
38
- <AdminContext.Provider
39
- value={{
40
- isAdmin: opts.isAdmin ?? true,
41
- unreadCount: 0,
42
- lastSeen: null,
43
- markSeen: () => {},
44
- refresh: () => {},
45
- rolesConfigCorrupted: false,
46
- rolesConfigErrors: [],
47
- runRolesRecovery: async () => {},
48
- }}
49
- >
50
- <UserAccountsPage />
51
- </AdminContext.Provider>
52
- </AuthContext.Provider>,
53
- );
54
- }
55
-
56
- beforeEach(() => {
57
- vi.mocked(listAccounts)
58
- .mockReset()
59
- .mockResolvedValue([
60
- { ...ME, hasPassword: true, createdAt: '2026-01-01T00:00:00Z' },
61
- ALICE,
62
- ]);
63
- vi.mocked(deleteAccount).mockReset().mockResolvedValue(undefined);
64
- vi.mocked(createAccount).mockReset().mockResolvedValue(undefined);
65
- });
66
-
67
- describe('UserAccountsPage', () => {
68
- it('shows the admins-only state (and never loads) for non-admins', () => {
69
- renderPage({ isAdmin: false });
70
- expect(screen.getByText(/Admins only/)).toBeInTheDocument();
71
- expect(listAccounts).not.toHaveBeenCalled();
72
- });
73
-
74
- it('lists accounts with sign-in method; own row offers no actions', async () => {
75
- renderPage();
76
- await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
77
- expect(screen.getByText(/Single sign-on only/)).toBeInTheDocument();
78
- expect(
79
- screen.getByRole('button', { name: 'Set password for alice@example.com' }),
80
- ).toBeInTheDocument();
81
- expect(
82
- screen.getByRole('button', { name: 'Delete account alice@example.com' }),
83
- ).toBeInTheDocument();
84
- expect(
85
- screen.queryByRole('button', { name: 'Set password for admin@example.com' }),
86
- ).not.toBeInTheDocument();
87
- expect(
88
- screen.queryByRole('button', { name: 'Delete account admin@example.com' }),
89
- ).not.toBeInTheDocument();
90
- });
91
-
92
- it('sets a password for a user WITHOUT touching their name', async () => {
93
- renderPage();
94
- await waitFor(() => screen.getByText('Alice'));
95
- await userEvent.click(screen.getByRole('button', { name: 'Set password for alice@example.com' }));
96
- const dialog = within(screen.getByRole('dialog'));
97
- // Empty password → the confirm button stays disabled; nothing is sent.
98
- expect(dialog.getByRole('button', { name: 'Set password' })).toBeDisabled();
99
- await userEvent.type(dialog.getByLabelText('New password'), 'fresh-password-1');
100
- await userEvent.click(dialog.getByRole('button', { name: 'Set password' }));
101
- await waitFor(() =>
102
- expect(createAccount).toHaveBeenCalledWith('alice@example.com', '', 'fresh-password-1'),
103
- );
104
- expect(await screen.findByRole('status')).toHaveTextContent(
105
- 'Password set for alice@example.com',
106
- );
107
- });
108
-
109
- it('deletes an account after confirmation', async () => {
110
- renderPage();
111
- await waitFor(() => screen.getByText('Alice'));
112
- await userEvent.click(screen.getByRole('button', { name: 'Delete account alice@example.com' }));
113
- const dialog = within(screen.getByRole('dialog'));
114
- await userEvent.click(dialog.getByRole('button', { name: 'Delete account' }));
115
- await waitFor(() => expect(deleteAccount).toHaveBeenCalledWith('u-alice'));
116
- // List reloaded after the delete.
117
- expect(listAccounts).toHaveBeenCalledTimes(2);
118
- });
119
-
120
- it('a failed delete closes the dialog, surfaces the error, and does not reload', async () => {
121
- vi.mocked(deleteAccount).mockRejectedValueOnce(new Error('Failed to erase user'));
122
- renderPage();
123
- await waitFor(() => screen.getByText('Alice'));
124
- await userEvent.click(screen.getByRole('button', { name: 'Delete account alice@example.com' }));
125
- const dialog = within(screen.getByRole('dialog'));
126
- await userEvent.click(dialog.getByRole('button', { name: 'Delete account' }));
127
- await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
128
- expect(screen.getByText('Failed to erase user')).toBeInTheDocument();
129
- expect(listAccounts).toHaveBeenCalledTimes(1);
130
- });
131
-
132
- it('adds a new account and refreshes the list', async () => {
133
- renderPage();
134
- await waitFor(() => screen.getByText('Alice'));
135
- await userEvent.type(screen.getByLabelText('Email'), 'bob@example.com');
136
- await userEvent.type(screen.getByLabelText(/Name/), 'Bob');
137
- await userEvent.type(screen.getByLabelText('Password'), 'bobs-password-1');
138
- await userEvent.click(screen.getByRole('button', { name: 'Add account' }));
139
- await waitFor(() =>
140
- expect(createAccount).toHaveBeenCalledWith('bob@example.com', 'Bob', 'bobs-password-1'),
141
- );
142
- expect(listAccounts).toHaveBeenCalledTimes(2);
143
- });
144
-
145
- it('surfaces an add failure inline', async () => {
146
- vi.mocked(createAccount).mockRejectedValueOnce(
147
- new Error('Password must be at least 8 characters'),
148
- );
149
- renderPage();
150
- await waitFor(() => screen.getByText('Alice'));
151
- await userEvent.type(screen.getByLabelText('Email'), 'bob@example.com');
152
- await userEvent.type(screen.getByLabelText('Password'), 'short');
153
- await userEvent.click(screen.getByRole('button', { name: 'Add account' }));
154
- expect(await screen.findByRole('alert')).toHaveTextContent('at least 8 characters');
155
- });
156
- });
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, waitFor, within } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { UserAccountsPage } from '../components/UserAccountsPage';
5
+ import { AdminContext } from '../state/admin.context';
6
+ import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
7
+ import {
8
+ createAccount,
9
+ deleteAccount,
10
+ listAccounts,
11
+ } from '../../auth/services/account.api';
12
+
13
+ vi.mock('../../auth/services/account.api', () => ({
14
+ createAccount: vi.fn(),
15
+ deleteAccount: vi.fn(),
16
+ listAccounts: vi.fn(),
17
+ }));
18
+
19
+ const ME = { id: 'admin-1', email: 'admin@example.com', name: 'Admin' };
20
+ const ALICE = {
21
+ id: 'u-alice',
22
+ email: 'alice@example.com',
23
+ name: 'Alice',
24
+ hasPassword: false,
25
+ createdAt: '2026-01-01T00:00:00Z',
26
+ };
27
+
28
+ function renderPage(opts: { isAdmin?: boolean } = {}) {
29
+ const auth: AuthContextValue = {
30
+ user: ME,
31
+ token: 't',
32
+ isLoading: false,
33
+ login: vi.fn(async () => {}),
34
+ logout: vi.fn(),
35
+ };
36
+ return render(
37
+ <AuthContext.Provider value={auth}>
38
+ <AdminContext.Provider
39
+ value={{
40
+ isAdmin: opts.isAdmin ?? true,
41
+ unreadCount: 0,
42
+ lastSeen: null,
43
+ markSeen: () => {},
44
+ refresh: () => {},
45
+ rolesConfigCorrupted: false,
46
+ rolesConfigErrors: [],
47
+ runRolesRecovery: async () => {},
48
+ }}
49
+ >
50
+ <UserAccountsPage />
51
+ </AdminContext.Provider>
52
+ </AuthContext.Provider>,
53
+ );
54
+ }
55
+
56
+ beforeEach(() => {
57
+ vi.mocked(listAccounts)
58
+ .mockReset()
59
+ .mockResolvedValue([
60
+ { ...ME, hasPassword: true, createdAt: '2026-01-01T00:00:00Z' },
61
+ ALICE,
62
+ ]);
63
+ vi.mocked(deleteAccount).mockReset().mockResolvedValue(undefined);
64
+ vi.mocked(createAccount).mockReset().mockResolvedValue(undefined);
65
+ });
66
+
67
+ describe('UserAccountsPage', () => {
68
+ it('shows the admins-only state (and never loads) for non-admins', () => {
69
+ renderPage({ isAdmin: false });
70
+ expect(screen.getByText(/Admins only/)).toBeInTheDocument();
71
+ expect(listAccounts).not.toHaveBeenCalled();
72
+ });
73
+
74
+ it('lists accounts with sign-in method; own row offers no actions', async () => {
75
+ renderPage();
76
+ await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
77
+ expect(screen.getByText(/Single sign-on only/)).toBeInTheDocument();
78
+ expect(
79
+ screen.getByRole('button', { name: 'Set password for alice@example.com' }),
80
+ ).toBeInTheDocument();
81
+ expect(
82
+ screen.getByRole('button', { name: 'Delete account alice@example.com' }),
83
+ ).toBeInTheDocument();
84
+ expect(
85
+ screen.queryByRole('button', { name: 'Set password for admin@example.com' }),
86
+ ).not.toBeInTheDocument();
87
+ expect(
88
+ screen.queryByRole('button', { name: 'Delete account admin@example.com' }),
89
+ ).not.toBeInTheDocument();
90
+ });
91
+
92
+ it('sets a password for a user WITHOUT touching their name', async () => {
93
+ renderPage();
94
+ await waitFor(() => screen.getByText('Alice'));
95
+ await userEvent.click(screen.getByRole('button', { name: 'Set password for alice@example.com' }));
96
+ const dialog = within(screen.getByRole('dialog'));
97
+ // Empty password → the confirm button stays disabled; nothing is sent.
98
+ expect(dialog.getByRole('button', { name: 'Set password' })).toBeDisabled();
99
+ await userEvent.type(dialog.getByLabelText('New password'), 'fresh-password-1');
100
+ await userEvent.click(dialog.getByRole('button', { name: 'Set password' }));
101
+ await waitFor(() =>
102
+ expect(createAccount).toHaveBeenCalledWith('alice@example.com', '', 'fresh-password-1'),
103
+ );
104
+ expect(await screen.findByRole('status')).toHaveTextContent(
105
+ 'Password set for alice@example.com',
106
+ );
107
+ });
108
+
109
+ it('deletes an account after confirmation', async () => {
110
+ renderPage();
111
+ await waitFor(() => screen.getByText('Alice'));
112
+ await userEvent.click(screen.getByRole('button', { name: 'Delete account alice@example.com' }));
113
+ const dialog = within(screen.getByRole('dialog'));
114
+ await userEvent.click(dialog.getByRole('button', { name: 'Delete account' }));
115
+ await waitFor(() => expect(deleteAccount).toHaveBeenCalledWith('u-alice'));
116
+ // List reloaded after the delete.
117
+ expect(listAccounts).toHaveBeenCalledTimes(2);
118
+ });
119
+
120
+ it('a failed delete closes the dialog, surfaces the error, and does not reload', async () => {
121
+ vi.mocked(deleteAccount).mockRejectedValueOnce(new Error('Failed to erase user'));
122
+ renderPage();
123
+ await waitFor(() => screen.getByText('Alice'));
124
+ await userEvent.click(screen.getByRole('button', { name: 'Delete account alice@example.com' }));
125
+ const dialog = within(screen.getByRole('dialog'));
126
+ await userEvent.click(dialog.getByRole('button', { name: 'Delete account' }));
127
+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
128
+ expect(screen.getByText('Failed to erase user')).toBeInTheDocument();
129
+ expect(listAccounts).toHaveBeenCalledTimes(1);
130
+ });
131
+
132
+ it('adds a new account and refreshes the list', async () => {
133
+ renderPage();
134
+ await waitFor(() => screen.getByText('Alice'));
135
+ await userEvent.type(screen.getByLabelText('Email'), 'bob@example.com');
136
+ await userEvent.type(screen.getByLabelText(/Name/), 'Bob');
137
+ await userEvent.type(screen.getByLabelText('Password'), 'bobs-password-1');
138
+ await userEvent.click(screen.getByRole('button', { name: 'Add account' }));
139
+ await waitFor(() =>
140
+ expect(createAccount).toHaveBeenCalledWith('bob@example.com', 'Bob', 'bobs-password-1'),
141
+ );
142
+ expect(listAccounts).toHaveBeenCalledTimes(2);
143
+ });
144
+
145
+ it('surfaces an add failure inline', async () => {
146
+ vi.mocked(createAccount).mockRejectedValueOnce(
147
+ new Error('Password must be at least 8 characters'),
148
+ );
149
+ renderPage();
150
+ await waitFor(() => screen.getByText('Alice'));
151
+ await userEvent.type(screen.getByLabelText('Email'), 'bob@example.com');
152
+ await userEvent.type(screen.getByLabelText('Password'), 'short');
153
+ await userEvent.click(screen.getByRole('button', { name: 'Add account' }));
154
+ expect(await screen.findByRole('alert')).toHaveTextContent('at least 8 characters');
155
+ });
156
+ });