@bevel-software/platform-core-frontend 0.21.0 → 0.22.0

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 (34) hide show
  1. package/package.json +2 -2
  2. package/src/core/registry.ts +57 -0
  3. package/src/modules/access/__tests__/ManageAccessDialog.request.test.tsx +376 -0
  4. package/src/modules/access/components/AccessRequestControl.tsx +155 -0
  5. package/src/modules/{library → access}/components/AccessRequestsBanner.tsx +62 -24
  6. package/src/modules/access/components/ManageAccessDialog.tsx +81 -4
  7. package/src/modules/access/hooks/useAccessRequests.ts +183 -0
  8. package/src/modules/access/requests.api.ts +121 -0
  9. package/src/modules/auth/components/LoginScreen.tsx +5 -0
  10. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +171 -38
  11. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +34 -19
  12. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +173 -6
  13. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +155 -98
  14. package/src/modules/library/__tests__/SkillPage.test.tsx +15 -0
  15. package/src/modules/library/__tests__/ToolPage.test.tsx +15 -1
  16. package/src/modules/library/__tests__/title-row-actions.ts +53 -1
  17. package/src/modules/library/components/PluginJoinRequests.tsx +2 -2
  18. package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
  19. package/src/modules/library/components/tool-page/ToolPage.tsx +11 -1
  20. package/src/modules/library/hooks/useJoinRequests.ts +26 -101
  21. package/src/modules/pr/services/pr-merge.api.ts +10 -2
  22. package/src/modules/settings/components/DeploymentPage.tsx +22 -0
  23. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +72 -4
  24. package/src/modules/setup/__tests__/setup.first-run.test.tsx +276 -0
  25. package/src/modules/setup/__tests__/setup.github.test.tsx +416 -0
  26. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +275 -0
  27. package/src/modules/setup/__tests__/setup.repository.test.tsx +373 -0
  28. package/src/modules/setup/__tests__/setup.test.tsx +8 -14
  29. package/src/modules/setup/components/GitHubRepositoryPanel.tsx +369 -0
  30. package/src/modules/setup/components/SetupGate.tsx +1 -0
  31. package/src/modules/setup/components/SetupScreen.tsx +464 -38
  32. package/src/modules/setup/services/setup.api.ts +93 -0
  33. package/src/modules/setup/utils/kept-draft.ts +86 -0
  34. package/src/shared/components/SlotBoundary.tsx +51 -0
@@ -0,0 +1,416 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+
5
+ const api = vi.hoisted(() => ({
6
+ fetchSetupStatus: vi.fn(),
7
+ saveSettings: vi.fn(),
8
+ testConnection: vi.fn(),
9
+ testOidc: vi.fn(),
10
+ syncNow: vi.fn(),
11
+ fetchGitHubApp: vi.fn(),
12
+ fetchGitHubRepositories: vi.fn(),
13
+ startGitHubAppRegistration: vi.fn(),
14
+ startGitHubAppInstallation: vi.fn(),
15
+ startGitHubAppRefresh: vi.fn(),
16
+ }));
17
+ vi.mock('../services/setup.api', async () => {
18
+ const actual = await vi.importActual<typeof import('../services/setup.api')>('../services/setup.api');
19
+ return { ...actual, ...api };
20
+ });
21
+ vi.mock('../../settings/services/github-facade.api', () => ({
22
+ fetchGitHubFacade: vi.fn(),
23
+ rotateGitHubFacade: vi.fn(),
24
+ fetchMarketplaceRegistration: vi.fn(async () => false),
25
+ setMarketplaceRegistration: vi.fn(),
26
+ }));
27
+
28
+ import { SetupScreen } from '../components/SetupScreen';
29
+ import {
30
+ SettingsProblems,
31
+ type GitHubAppStatus,
32
+ type GitMode,
33
+ type RepositoryStatus,
34
+ type SettingStatus,
35
+ } from '../services/setup.api';
36
+
37
+ const setting = (key: string, extra: Partial<SettingStatus> = {}): SettingStatus => ({
38
+ key,
39
+ section: 'knowledge-base',
40
+ source: 'unset',
41
+ value: '',
42
+ configured: false,
43
+ secret: false,
44
+ restartToApply: false,
45
+ ...extra,
46
+ });
47
+
48
+ const settingsOf = (repository = ''): SettingStatus[] => [
49
+ setting('gitMode', { restartToApply: true }),
50
+ setting('githubRepository', repository ? { source: 'stored', configured: true, value: repository } : {}),
51
+ setting('kbRepoUrl'),
52
+ setting('gitToken', { secret: true, value: undefined }),
53
+ setting('defaultBranch'),
54
+ setting('protectedBranches'),
55
+ ];
56
+
57
+ const MODES: GitMode[] = ['managed', 'github-app', 'token'];
58
+ const NO_APP: GitHubAppStatus = { registeredBy: null, app: null, installation: null, repository: null };
59
+ const APP = { slug: 'hexis-acme', url: 'https://github.com/apps/hexis-acme' };
60
+ const REGISTERED: GitHubAppStatus = { registeredBy: 'setup', app: APP, installation: null, repository: null };
61
+ const INSTALLED: GitHubAppStatus = { ...REGISTERED, installation: { id: '77', account: 'acme' } };
62
+ const REPOSITORIES = {
63
+ repositories: [
64
+ { fullName: 'acme/kb', private: true, defaultBranch: 'main', writable: true },
65
+ { fullName: 'acme/website', private: false, defaultBranch: 'trunk', writable: true },
66
+ ],
67
+ more: false,
68
+ };
69
+
70
+ const realLocation = window.location;
71
+ function standAt(search = '') {
72
+ Object.defineProperty(window, 'location', {
73
+ configurable: true,
74
+ value: { ...realLocation, href: `https://kb.acme.test/${search}`, search, origin: 'https://kb.acme.test', reload: vi.fn() },
75
+ });
76
+ }
77
+
78
+ function show(opts: { mode?: GitMode | null; stored?: string; variant?: 'setup' | 'settings'; modes?: GitMode[] } = {}) {
79
+ const repository: RepositoryStatus = { mode: opts.mode ?? null, modes: opts.modes ?? MODES };
80
+ render(<SetupScreen settings={settingsOf(opts.stored)} onSaved={() => {}} variant={opts.variant ?? 'setup'} repository={repository} />);
81
+ }
82
+
83
+ const openGitHub = () => userEvent.click(screen.getByRole('tab', { name: 'GitHub' }));
84
+ const save = () => userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
85
+
86
+ beforeEach(() => {
87
+ for (const fn of Object.values(api)) fn.mockReset();
88
+ api.fetchGitHubApp.mockResolvedValue(NO_APP);
89
+ api.fetchGitHubRepositories.mockResolvedValue(REPOSITORIES);
90
+ standAt();
91
+ });
92
+
93
+ afterEach(() => {
94
+ Object.defineProperty(window, 'location', { configurable: true, value: realLocation });
95
+ });
96
+
97
+ describe('SetupScreen: the GitHub tab', () => {
98
+ it('is offered second, between the repository the deployment keeps and an address', () => {
99
+ show();
100
+ expect(screen.getAllByRole('tab').map((t) => t.textContent)).toEqual(['Managed for you', 'GitHub', 'Address and token']);
101
+ expect(screen.getByRole('tab', { name: 'Managed for you' })).toHaveAttribute('aria-selected', 'true');
102
+ });
103
+
104
+ it('is not drawn by a deployment that cannot connect to GitHub', () => {
105
+ show({ modes: ['managed', 'token'] });
106
+ expect(screen.queryByRole('tab', { name: 'GitHub' })).toBeNull();
107
+ });
108
+
109
+ it('asks GitHub nothing until it is opened', async () => {
110
+ show();
111
+ expect(api.fetchGitHubApp).not.toHaveBeenCalled();
112
+ await openGitHub();
113
+ await waitFor(() => expect(api.fetchGitHubApp).toHaveBeenCalled());
114
+ });
115
+ });
116
+
117
+ describe('the three steps of connecting GitHub', () => {
118
+ it('starts with creating the app, which sends the browser to GitHub with the manifest', async () => {
119
+ api.startGitHubAppRegistration.mockResolvedValue({
120
+ action: 'https://github.com/organizations/acme/settings/apps/new?state=abc',
121
+ manifest: { name: 'Hexis kb.acme.test', public: false },
122
+ });
123
+ const submitted: HTMLFormElement[] = [];
124
+ const submit = vi.spyOn(HTMLFormElement.prototype, 'submit').mockImplementation(function (this: HTMLFormElement) {
125
+ submitted.push(this);
126
+ });
127
+ try {
128
+ show();
129
+ await openGitHub();
130
+ await userEvent.type(await screen.findByLabelText('Organisation', { exact: false }), 'acme');
131
+ await userEvent.click(screen.getByRole('button', { name: 'Create the GitHub App' }));
132
+ await waitFor(() => expect(submitted).toHaveLength(1));
133
+ expect(api.startGitHubAppRegistration).toHaveBeenCalledWith('acme');
134
+ const form = submitted[0]!;
135
+ expect(form.method).toBe('post');
136
+ expect(form.action).toBe('https://github.com/organizations/acme/settings/apps/new?state=abc');
137
+ expect(JSON.parse((form.elements.namedItem('manifest') as HTMLInputElement).value)).toEqual({
138
+ name: 'Hexis kb.acme.test',
139
+ public: false,
140
+ });
141
+ // GitHub's form, on the page, never inside the settings form.
142
+ expect(form.closest('#setup-settings-form')).toBeNull();
143
+ expect(api.saveSettings).not.toHaveBeenCalled();
144
+ } finally {
145
+ submit.mockRestore();
146
+ }
147
+ });
148
+
149
+ it('keeps Enter in the organisation field from saving the settings form', async () => {
150
+ show();
151
+ await openGitHub();
152
+ const field = await screen.findByLabelText('Organisation', { exact: false });
153
+ expect(fireEvent.keyDown(field, { key: 'Enter' })).toBe(false);
154
+ expect(fireEvent.keyDown(field, { key: 'a' })).toBe(true);
155
+ });
156
+
157
+ it('says so in place when the app cannot be started', async () => {
158
+ api.startGitHubAppRegistration.mockRejectedValue(new Error('This deployment already has a GitHub App.'));
159
+ show();
160
+ await openGitHub();
161
+ await userEvent.click(await screen.findByRole('button', { name: 'Create the GitHub App' }));
162
+ expect(await screen.findByRole('alert')).toHaveTextContent('already has a GitHub App');
163
+ expect(screen.getByRole('button', { name: 'Create the GitHub App' })).toBeEnabled();
164
+ });
165
+
166
+ it('goes on to installing an app that exists, asking where on GitHub before it sends the browser there', async () => {
167
+ api.fetchGitHubApp.mockResolvedValue(REGISTERED);
168
+ api.startGitHubAppInstallation.mockResolvedValue('https://github.com/apps/hexis-acme/installations/new?state=abc');
169
+ const assign = vi.fn();
170
+ standAt();
171
+ Object.assign(window.location, { assign });
172
+ show();
173
+ await openGitHub();
174
+ await userEvent.click(await screen.findByRole('button', { name: 'Install the app on GitHub' }));
175
+ await waitFor(() => expect(assign).toHaveBeenCalledWith('https://github.com/apps/hexis-acme/installations/new?state=abc'));
176
+ expect(screen.queryByRole('button', { name: 'Create the GitHub App' })).toBeNull();
177
+ expect(api.fetchGitHubRepositories).not.toHaveBeenCalled();
178
+ expect(api.saveSettings).not.toHaveBeenCalled();
179
+ });
180
+
181
+ /** A round trip is started by asking, never by a link someone could be sent. */
182
+ it('has no link that starts a round trip', async () => {
183
+ for (const status of [REGISTERED, INSTALLED]) {
184
+ api.fetchGitHubApp.mockResolvedValue(status);
185
+ const { unmount } = render(
186
+ <SetupScreen settings={settingsOf()} onSaved={() => {}} repository={{ mode: 'github-app', chosen: 'github-app', modes: MODES }} />,
187
+ );
188
+ await screen.findByText(/hexis-acme/);
189
+ expect(screen.queryAllByRole('link').filter((a) => (a.getAttribute('href') ?? '').includes('/api/'))).toEqual([]);
190
+ unmount();
191
+ }
192
+ });
193
+
194
+ it('says so in place when GitHub cannot be opened', async () => {
195
+ api.fetchGitHubApp.mockResolvedValue(REGISTERED);
196
+ api.startGitHubAppInstallation.mockRejectedValue(new Error('This deployment has no GitHub App yet. Create it first.'));
197
+ show();
198
+ await openGitHub();
199
+ await userEvent.click(await screen.findByRole('button', { name: 'Install the app on GitHub' }));
200
+ expect(await screen.findByRole('alert')).toHaveTextContent('has no GitHub App yet');
201
+ expect(screen.getByRole('button', { name: 'Install the app on GitHub' })).toBeEnabled();
202
+ });
203
+
204
+ it('ends with choosing a repository among those the installation reaches', async () => {
205
+ api.fetchGitHubApp.mockResolvedValue(INSTALLED);
206
+ show();
207
+ await openGitHub();
208
+ const picker = await screen.findByRole('combobox', { name: 'Repository' });
209
+ await waitFor(() => expect(picker).toBeEnabled());
210
+ expect(screen.getByTestId('github-repository')).toHaveTextContent('Connected to acme through the app hexis-acme');
211
+ expect(Array.from((picker as HTMLSelectElement).options).map((o) => o.value)).toEqual(['', 'acme/kb', 'acme/website']);
212
+ // What the list is, and how it is brought up to date.
213
+ expect(screen.getByTestId('github-repository')).toHaveTextContent('your own GitHub account can write to');
214
+ expect(screen.getByRole('button', { name: 'Refresh the list' })).toBeEnabled();
215
+ });
216
+
217
+ /**
218
+ * Which repositories the app reaches is decided on GitHub, first; the list
219
+ * is what came of it. So the connection's controls come before the list.
220
+ */
221
+ it('puts the connection to GitHub above the repository it is chosen through', async () => {
222
+ api.fetchGitHubApp.mockResolvedValue(INSTALLED);
223
+ show();
224
+ await openGitHub();
225
+ const picker = await screen.findByRole('combobox', { name: 'Repository' });
226
+ for (const name of ['Change repositories on GitHub', 'Refresh the list']) {
227
+ const button = screen.getByRole('button', { name });
228
+ expect(button.compareDocumentPosition(picker) & Node.DOCUMENT_POSITION_FOLLOWING, name).toBeTruthy();
229
+ }
230
+ });
231
+
232
+ /**
233
+ * With the app installed, the address that installs it opens the
234
+ * installation's settings on GitHub, and GitHub offers no way back from
235
+ * there. In this tab the admin would be left on GitHub, the setup screen
236
+ * gone.
237
+ */
238
+ it('opens GitHub in another tab to change what the app reaches, and stays where it is', async () => {
239
+ api.fetchGitHubApp.mockResolvedValue(INSTALLED);
240
+ api.startGitHubAppInstallation.mockResolvedValue('https://github.com/apps/hexis-acme/installations/new?state=abc');
241
+ const assign = vi.fn();
242
+ standAt();
243
+ Object.assign(window.location, { assign });
244
+ const tab = { opener: window as unknown, location: { href: '' }, close: vi.fn() };
245
+ const open = vi.spyOn(window, 'open').mockReturnValue(tab as unknown as Window);
246
+ try {
247
+ show();
248
+ await openGitHub();
249
+ await userEvent.click(await screen.findByRole('button', { name: 'Change repositories on GitHub' }));
250
+ await waitFor(() => expect(tab.location.href).toBe('https://github.com/apps/hexis-acme/installations/new?state=abc'));
251
+ // Opened at the press, in a tab of its own, which is given no handle on this one.
252
+ expect(open).toHaveBeenCalledWith('', '_blank');
253
+ expect(tab.opener).toBeNull();
254
+ expect(assign).not.toHaveBeenCalled();
255
+ // And the way back is said: nothing changed there is in the list yet.
256
+ expect(await screen.findByTestId('github-managed')).toHaveTextContent('Refresh the list');
257
+ expect(screen.getByRole('combobox', { name: 'Repository' })).toBeInTheDocument();
258
+ } finally {
259
+ open.mockRestore();
260
+ }
261
+ });
262
+
263
+ it('goes itself when no tab may be opened, and closes the tab when GitHub cannot be asked', async () => {
264
+ api.fetchGitHubApp.mockResolvedValue(INSTALLED);
265
+ api.startGitHubAppInstallation.mockResolvedValue('https://github.com/apps/hexis-acme/installations/new?state=abc');
266
+ const assign = vi.fn();
267
+ standAt();
268
+ Object.assign(window.location, { assign });
269
+ const open = vi.spyOn(window, 'open').mockReturnValue(null);
270
+ try {
271
+ show();
272
+ await openGitHub();
273
+ await userEvent.click(await screen.findByRole('button', { name: 'Change repositories on GitHub' }));
274
+ await waitFor(() => expect(assign).toHaveBeenCalledWith('https://github.com/apps/hexis-acme/installations/new?state=abc'));
275
+
276
+ const tab = { opener: window as unknown, location: { href: '' }, close: vi.fn() };
277
+ open.mockReturnValue(tab as unknown as Window);
278
+ api.startGitHubAppInstallation.mockRejectedValue(new Error('GitHub could not be reached.'));
279
+ await userEvent.click(screen.getByRole('button', { name: 'Change repositories on GitHub' }));
280
+ expect(await screen.findByRole('alert')).toHaveTextContent('GitHub could not be reached');
281
+ expect(tab.close).toHaveBeenCalled();
282
+ expect(tab.location.href).toBe('');
283
+ } finally {
284
+ open.mockRestore();
285
+ }
286
+ });
287
+
288
+ it('refreshes the list by a sign-in that comes straight back', async () => {
289
+ api.fetchGitHubApp.mockResolvedValue(INSTALLED);
290
+ api.startGitHubAppRefresh.mockResolvedValue('https://github.com/login/oauth/authorize?client_id=Iv1.x&state=abc');
291
+ const assign = vi.fn();
292
+ standAt();
293
+ Object.assign(window.location, { assign });
294
+ show();
295
+ await openGitHub();
296
+ await userEvent.click(await screen.findByRole('button', { name: 'Refresh the list' }));
297
+ await waitFor(() => expect(assign).toHaveBeenCalledWith('https://github.com/login/oauth/authorize?client_id=Iv1.x&state=abc'));
298
+ expect(api.startGitHubAppInstallation).not.toHaveBeenCalled();
299
+ });
300
+
301
+ it('says the list is up to date when the browser comes back from refreshing it', async () => {
302
+ api.fetchGitHubApp.mockResolvedValue(INSTALLED);
303
+ standAt('?github=refreshed');
304
+ show();
305
+ expect(await screen.findByText('The list of repositories is up to date.')).toBeInTheDocument();
306
+ expect(screen.getByRole('tab', { name: 'GitHub' })).toHaveAttribute('aria-selected', 'true');
307
+ });
308
+
309
+ /** Installed by an owner who approved it later, in a browser of their own. */
310
+ it('offers to check again for an app that was installed somewhere this browser never came back from', async () => {
311
+ api.fetchGitHubApp.mockResolvedValue(REGISTERED);
312
+ api.startGitHubAppRefresh.mockResolvedValue('https://github.com/login/oauth/authorize?client_id=Iv1.x&state=abc');
313
+ const assign = vi.fn();
314
+ standAt();
315
+ Object.assign(window.location, { assign });
316
+ show();
317
+ await openGitHub();
318
+ await userEvent.click(await screen.findByRole('button', { name: 'Already installed? Check again' }));
319
+ await waitFor(() => expect(assign).toHaveBeenCalledWith('https://github.com/login/oauth/authorize?client_id=Iv1.x&state=abc'));
320
+ });
321
+ });
322
+
323
+ describe('saving a repository on GitHub', () => {
324
+ beforeEach(() => api.fetchGitHubApp.mockResolvedValue(INSTALLED));
325
+
326
+ it('sends the way and the repository, and leaves the proof to the server', async () => {
327
+ api.saveSettings.mockResolvedValue({ restartRequired: false, complete: true, settings: settingsOf('acme/kb'), repository: { mode: 'github-app', modes: MODES } });
328
+ show();
329
+ await openGitHub();
330
+ const picker = await screen.findByRole('combobox', { name: 'Repository' });
331
+ await waitFor(() => expect(picker).toBeEnabled());
332
+ await userEvent.selectOptions(picker, 'acme/kb');
333
+ await save();
334
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ gitMode: 'github-app', githubRepository: 'acme/kb' }));
335
+ expect(api.testConnection).not.toHaveBeenCalled();
336
+ });
337
+
338
+ it('does not send a repository that was chosen on a tab that was then left', async () => {
339
+ api.saveSettings.mockResolvedValue({ restartRequired: false, complete: true, settings: settingsOf(), repository: { mode: 'managed', modes: MODES } });
340
+ show();
341
+ await openGitHub();
342
+ const picker = await screen.findByRole('combobox', { name: 'Repository' });
343
+ await waitFor(() => expect(picker).toBeEnabled());
344
+ await userEvent.selectOptions(picker, 'acme/kb');
345
+ await userEvent.click(screen.getByRole('tab', { name: 'Managed for you' }));
346
+ await save();
347
+ await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ gitMode: 'managed' }));
348
+ });
349
+
350
+ it('shows a refusal beside the repository, with its tab opened', async () => {
351
+ const refusal = 'The GitHub App cannot reach that repository. Add the repository to the app’s installation on GitHub.';
352
+ api.saveSettings.mockRejectedValue(new SettingsProblems({ githubRepository: refusal }));
353
+ show({ mode: 'github-app', stored: 'acme/gone', variant: 'settings' });
354
+ await screen.findByRole('combobox', { name: 'Repository' });
355
+ await userEvent.click(screen.getByRole('tab', { name: 'Managed for you' }));
356
+ await userEvent.click(screen.getByRole('tab', { name: 'GitHub' }));
357
+ await save();
358
+ expect(await screen.findByText(refusal)).toBeInTheDocument();
359
+ expect(screen.getByRole('tab', { name: 'GitHub' })).toHaveAttribute('aria-selected', 'true');
360
+ expect(screen.getByRole('combobox', { name: 'Repository' })).toHaveAttribute('aria-invalid', 'true');
361
+ });
362
+
363
+ it('keeps showing a stored repository the installation no longer reaches, so it is not replaced unseen', async () => {
364
+ show({ mode: 'github-app', stored: 'acme/gone', variant: 'settings' });
365
+ const picker = (await screen.findByRole('combobox', { name: 'Repository' })) as HTMLSelectElement;
366
+ await waitFor(() => expect(picker).toBeEnabled());
367
+ expect(picker.value).toBe('acme/gone');
368
+ expect(Array.from(picker.options).map((o) => o.value)).toEqual(['', 'acme/gone', 'acme/kb', 'acme/website']);
369
+ });
370
+
371
+ it('says so when the repositories cannot be listed', async () => {
372
+ api.fetchGitHubRepositories.mockRejectedValue(new Error('GitHub could not be reached. Try again shortly.'));
373
+ show();
374
+ await openGitHub();
375
+ expect(await screen.findByText('GitHub could not be reached. Try again shortly.')).toBeInTheDocument();
376
+ });
377
+ });
378
+
379
+ describe('coming back from GitHub', () => {
380
+ it('opens on the GitHub tab, says what came of it, and takes it off the address', async () => {
381
+ api.fetchGitHubApp.mockResolvedValue(INSTALLED);
382
+ const replace = vi.spyOn(window.history, 'replaceState').mockImplementation(() => undefined);
383
+ try {
384
+ standAt('?github=connected');
385
+ show();
386
+ expect(screen.getByRole('tab', { name: 'GitHub' })).toHaveAttribute('aria-selected', 'true');
387
+ expect(await screen.findByText('GitHub is connected. Choose the repository below.')).toBeInTheDocument();
388
+ expect(replace).toHaveBeenCalledWith({}, '', '/');
389
+ } finally {
390
+ replace.mockRestore();
391
+ }
392
+ });
393
+
394
+ it.each([
395
+ ['not-yours', /not one your GitHub account can reach/],
396
+ ['nothing-to-write', /no repository your own GitHub account can write to/],
397
+ ['requested', /asked an owner of the organisation/],
398
+ ['unreachable', /could not be reached/],
399
+ ['something-new', /did not complete the connection/],
400
+ ])('says what %s means', async (outcome, said) => {
401
+ const replace = vi.spyOn(window.history, 'replaceState').mockImplementation(() => undefined);
402
+ try {
403
+ standAt(`?github=${outcome}`);
404
+ show();
405
+ expect(await screen.findByText(said)).toBeInTheDocument();
406
+ } finally {
407
+ replace.mockRestore();
408
+ }
409
+ });
410
+
411
+ it('opens where it always does on a deployment that does not offer GitHub', () => {
412
+ standAt('?github=connected');
413
+ show({ modes: ['managed', 'token'] });
414
+ expect(screen.getByRole('tab', { name: 'Managed for you' })).toHaveAttribute('aria-selected', 'true');
415
+ });
416
+ });