@prenta/admin 2.16.7 → 2.17.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.
- package/CHANGELOG.md +18 -0
- package/dist/AdminRoot.d.ts.map +1 -1
- package/dist/AdminRoot.js +23 -3
- package/dist/AdminRoot.js.map +1 -1
- package/dist/__tests__/components/command-palette-links.render.test.d.ts +2 -0
- package/dist/__tests__/components/command-palette-links.render.test.d.ts.map +1 -0
- package/dist/__tests__/components/command-palette-links.render.test.js +73 -0
- package/dist/__tests__/components/command-palette-links.render.test.js.map +1 -0
- package/dist/__tests__/components/live-preview-pane.render.test.d.ts +2 -0
- package/dist/__tests__/components/live-preview-pane.render.test.d.ts.map +1 -0
- package/dist/__tests__/components/live-preview-pane.render.test.js +45 -0
- package/dist/__tests__/components/live-preview-pane.render.test.js.map +1 -0
- package/dist/__tests__/fields/field-renderer-null.render.test.js +7 -0
- package/dist/__tests__/fields/field-renderer-null.render.test.js.map +1 -1
- package/dist/__tests__/layout/layout-command-palette.render.test.d.ts +2 -0
- package/dist/__tests__/layout/layout-command-palette.render.test.d.ts.map +1 -0
- package/dist/__tests__/layout/layout-command-palette.render.test.js +54 -0
- package/dist/__tests__/layout/layout-command-palette.render.test.js.map +1 -0
- package/dist/__tests__/lib/api-error.test.d.ts +2 -0
- package/dist/__tests__/lib/api-error.test.d.ts.map +1 -0
- package/dist/__tests__/lib/api-error.test.js +32 -0
- package/dist/__tests__/lib/api-error.test.js.map +1 -0
- package/dist/__tests__/lib/api.test.js +29 -0
- package/dist/__tests__/lib/api.test.js.map +1 -1
- package/dist/__tests__/lib/collection-routes.test.js +19 -1
- package/dist/__tests__/lib/collection-routes.test.js.map +1 -1
- package/dist/__tests__/lib/document-editor-path.test.d.ts +2 -0
- package/dist/__tests__/lib/document-editor-path.test.d.ts.map +1 -0
- package/dist/__tests__/lib/document-editor-path.test.js +42 -0
- package/dist/__tests__/lib/document-editor-path.test.js.map +1 -0
- package/dist/__tests__/lib/fetch-all-pages.test.js +11 -1
- package/dist/__tests__/lib/fetch-all-pages.test.js.map +1 -1
- package/dist/__tests__/lib/forms-service-rate-limit.test.d.ts +2 -0
- package/dist/__tests__/lib/forms-service-rate-limit.test.d.ts.map +1 -0
- package/dist/__tests__/lib/forms-service-rate-limit.test.js +19 -0
- package/dist/__tests__/lib/forms-service-rate-limit.test.js.map +1 -0
- package/dist/__tests__/lib/useApiData.test.js +20 -0
- package/dist/__tests__/lib/useApiData.test.js.map +1 -1
- package/dist/__tests__/views/collection-editor-redirect.render.test.d.ts +2 -0
- package/dist/__tests__/views/collection-editor-redirect.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/collection-editor-redirect.render.test.js +168 -0
- package/dist/__tests__/views/collection-editor-redirect.render.test.js.map +1 -0
- package/dist/__tests__/views/collection-list-nav.render.test.js +33 -0
- package/dist/__tests__/views/collection-list-nav.render.test.js.map +1 -1
- package/dist/__tests__/views/dashboard.test.js +50 -0
- package/dist/__tests__/views/dashboard.test.js.map +1 -1
- package/dist/__tests__/views/form-entries.render.test.js +7 -0
- package/dist/__tests__/views/form-entries.render.test.js.map +1 -1
- package/dist/__tests__/views/forms-list.render.test.js +12 -0
- package/dist/__tests__/views/forms-list.render.test.js.map +1 -1
- package/dist/__tests__/views/posts-list-view.render.test.js +31 -0
- package/dist/__tests__/views/posts-list-view.render.test.js.map +1 -1
- package/dist/__tests__/views/rate-limited-views.render.test.d.ts +2 -0
- package/dist/__tests__/views/rate-limited-views.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/rate-limited-views.render.test.js +148 -0
- package/dist/__tests__/views/rate-limited-views.render.test.js.map +1 -0
- package/dist/__tests__/views/script-tags.render.test.js +42 -0
- package/dist/__tests__/views/script-tags.render.test.js.map +1 -1
- package/dist/__tests__/views/trash.render.test.js +40 -1
- package/dist/__tests__/views/trash.render.test.js.map +1 -1
- package/dist/components/CommandPalette.d.ts +9 -1
- package/dist/components/CommandPalette.d.ts.map +1 -1
- package/dist/components/CommandPalette.js +21 -7
- package/dist/components/CommandPalette.js.map +1 -1
- package/dist/components/LivePreview.d.ts.map +1 -1
- package/dist/components/LivePreview.js +10 -2
- package/dist/components/LivePreview.js.map +1 -1
- package/dist/components/MediaPickerModal.d.ts.map +1 -1
- package/dist/components/MediaPickerModal.js +2 -2
- package/dist/components/MediaPickerModal.js.map +1 -1
- package/dist/fields/FieldRenderer.d.ts.map +1 -1
- package/dist/fields/FieldRenderer.js +2 -0
- package/dist/fields/FieldRenderer.js.map +1 -1
- package/dist/fields/JsonField.d.ts +12 -0
- package/dist/fields/JsonField.d.ts.map +1 -0
- package/dist/fields/JsonField.js +11 -0
- package/dist/fields/JsonField.js.map +1 -0
- package/dist/layout/Header.d.ts +7 -1
- package/dist/layout/Header.d.ts.map +1 -1
- package/dist/layout/Header.js +2 -2
- package/dist/layout/Header.js.map +1 -1
- package/dist/layout/Layout.d.ts.map +1 -1
- package/dist/layout/Layout.js +1 -1
- package/dist/layout/Layout.js.map +1 -1
- package/dist/lib/api-error.d.ts +23 -0
- package/dist/lib/api-error.d.ts.map +1 -0
- package/dist/lib/api-error.js +42 -0
- package/dist/lib/api-error.js.map +1 -0
- package/dist/lib/api.d.ts +6 -0
- package/dist/lib/api.d.ts.map +1 -1
- package/dist/lib/api.js +10 -0
- package/dist/lib/api.js.map +1 -1
- package/dist/lib/collection-routes.d.ts +8 -0
- package/dist/lib/collection-routes.d.ts.map +1 -1
- package/dist/lib/collection-routes.js +12 -0
- package/dist/lib/collection-routes.js.map +1 -1
- package/dist/lib/document-editor-path.d.ts +32 -0
- package/dist/lib/document-editor-path.d.ts.map +1 -0
- package/dist/lib/document-editor-path.js +75 -0
- package/dist/lib/document-editor-path.js.map +1 -0
- package/dist/lib/fetch-all-pages.d.ts.map +1 -1
- package/dist/lib/fetch-all-pages.js +4 -2
- package/dist/lib/fetch-all-pages.js.map +1 -1
- package/dist/lib/forms-service.d.ts.map +1 -1
- package/dist/lib/forms-service.js +3 -1
- package/dist/lib/forms-service.js.map +1 -1
- package/dist/lib/jobs-service.d.ts.map +1 -1
- package/dist/lib/jobs-service.js +4 -11
- package/dist/lib/jobs-service.js.map +1 -1
- package/dist/lib/posts-service.d.ts.map +1 -1
- package/dist/lib/posts-service.js +3 -1
- package/dist/lib/posts-service.js.map +1 -1
- package/dist/lib/useApiData.d.ts.map +1 -1
- package/dist/lib/useApiData.js +8 -4
- package/dist/lib/useApiData.js.map +1 -1
- package/dist/prenta-admin.css +1 -1
- package/dist/router/index.d.ts +5 -1
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +13 -3
- package/dist/router/index.js.map +1 -1
- package/dist/views/ApiKeys.js +1 -1
- package/dist/views/ApiKeys.js.map +1 -1
- package/dist/views/CollectionList.d.ts.map +1 -1
- package/dist/views/CollectionList.js +2 -2
- package/dist/views/CollectionList.js.map +1 -1
- package/dist/views/Dashboard.d.ts.map +1 -1
- package/dist/views/Dashboard.js +5 -3
- package/dist/views/Dashboard.js.map +1 -1
- package/dist/views/Forms.d.ts.map +1 -1
- package/dist/views/Forms.js +4 -1
- package/dist/views/Forms.js.map +1 -1
- package/dist/views/MediaBrowser.d.ts.map +1 -1
- package/dist/views/MediaBrowser.js +2 -2
- package/dist/views/MediaBrowser.js.map +1 -1
- package/dist/views/Pages/PagesListView.d.ts.map +1 -1
- package/dist/views/Pages/PagesListView.js +10 -8
- package/dist/views/Pages/PagesListView.js.map +1 -1
- package/dist/views/Pages.d.ts.map +1 -1
- package/dist/views/Pages.js +1 -1
- package/dist/views/Pages.js.map +1 -1
- package/dist/views/Posts/PostsListView.d.ts.map +1 -1
- package/dist/views/Posts/PostsListView.js +7 -6
- package/dist/views/Posts/PostsListView.js.map +1 -1
- package/dist/views/Redirects.d.ts.map +1 -1
- package/dist/views/Redirects.js +1 -1
- package/dist/views/Redirects.js.map +1 -1
- package/dist/views/ScriptTags.d.ts.map +1 -1
- package/dist/views/ScriptTags.js +3 -1
- package/dist/views/ScriptTags.js.map +1 -1
- package/dist/views/Trash.d.ts +10 -11
- package/dist/views/Trash.d.ts.map +1 -1
- package/dist/views/Trash.js +17 -16
- package/dist/views/Trash.js.map +1 -1
- package/dist/views/Users.d.ts.map +1 -1
- package/dist/views/Users.js +1 -1
- package/dist/views/Users.js.map +1 -1
- package/dist/views/entries/EntriesInbox.d.ts.map +1 -1
- package/dist/views/entries/EntriesInbox.js +1 -1
- package/dist/views/entries/EntriesInbox.js.map +1 -1
- package/package.json +3 -3
- package/src/AdminRoot.tsx +38 -6
- package/src/__tests__/components/command-palette-links.render.test.tsx +89 -0
- package/src/__tests__/components/live-preview-pane.render.test.tsx +62 -0
- package/src/__tests__/fields/field-renderer-null.render.test.tsx +16 -0
- package/src/__tests__/layout/layout-command-palette.render.test.tsx +69 -0
- package/src/__tests__/lib/api-error.test.ts +45 -0
- package/src/__tests__/lib/api.test.ts +47 -0
- package/src/__tests__/lib/collection-routes.test.ts +22 -0
- package/src/__tests__/lib/document-editor-path.test.ts +67 -0
- package/src/__tests__/lib/fetch-all-pages.test.ts +14 -1
- package/src/__tests__/lib/forms-service-rate-limit.test.ts +25 -0
- package/src/__tests__/lib/useApiData.test.ts +24 -0
- package/src/__tests__/views/collection-editor-redirect.render.test.tsx +197 -0
- package/src/__tests__/views/collection-list-nav.render.test.tsx +36 -0
- package/src/__tests__/views/dashboard.test.tsx +67 -0
- package/src/__tests__/views/form-entries.render.test.tsx +10 -0
- package/src/__tests__/views/forms-list.render.test.tsx +15 -0
- package/src/__tests__/views/posts-list-view.render.test.tsx +33 -0
- package/src/__tests__/views/rate-limited-views.render.test.tsx +163 -0
- package/src/__tests__/views/script-tags.render.test.tsx +43 -0
- package/src/__tests__/views/trash.render.test.tsx +42 -1
- package/src/components/CommandPalette.tsx +32 -5
- package/src/components/LivePreview.tsx +13 -2
- package/src/components/MediaPickerModal.tsx +18 -1
- package/src/fields/FieldRenderer.tsx +2 -0
- package/src/fields/JsonField.tsx +34 -0
- package/src/layout/Header.tsx +8 -1
- package/src/layout/Layout.tsx +6 -1
- package/src/lib/api-error.ts +47 -0
- package/src/lib/api.ts +17 -0
- package/src/lib/collection-routes.ts +15 -0
- package/src/lib/document-editor-path.ts +97 -0
- package/src/lib/fetch-all-pages.ts +4 -1
- package/src/lib/forms-service.ts +4 -2
- package/src/lib/jobs-service.ts +4 -10
- package/src/lib/posts-service.ts +3 -1
- package/src/lib/useApiData.ts +10 -4
- package/src/router/index.ts +25 -7
- package/src/views/ApiKeys.tsx +1 -1
- package/src/views/CollectionList.tsx +7 -4
- package/src/views/Dashboard.tsx +5 -3
- package/src/views/Forms.tsx +27 -22
- package/src/views/MediaBrowser.tsx +12 -8
- package/src/views/Pages/PagesListView.tsx +16 -11
- package/src/views/Pages.tsx +6 -3
- package/src/views/Posts/PostsListView.tsx +28 -19
- package/src/views/Redirects.tsx +7 -4
- package/src/views/ScriptTags.tsx +7 -3
- package/src/views/Trash.tsx +29 -16
- package/src/views/Users.tsx +7 -4
- package/src/views/entries/EntriesInbox.tsx +10 -7
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
4
|
+
|
|
5
|
+
const cmsApi = vi.fn()
|
|
6
|
+
vi.mock('../../lib/api.js', () => ({
|
|
7
|
+
cmsApi: (...args: unknown[]) => cmsApi(...args),
|
|
8
|
+
}))
|
|
9
|
+
|
|
10
|
+
// cmdk measures and scrolls its list; happy-dom implements neither.
|
|
11
|
+
vi.stubGlobal(
|
|
12
|
+
'ResizeObserver',
|
|
13
|
+
class {
|
|
14
|
+
observe() {}
|
|
15
|
+
unobserve() {}
|
|
16
|
+
disconnect() {}
|
|
17
|
+
},
|
|
18
|
+
)
|
|
19
|
+
Element.prototype.scrollIntoView ??= function scrollIntoView() {}
|
|
20
|
+
// The palette keeps recent items in localStorage.
|
|
21
|
+
const storage = new Map<string, string>()
|
|
22
|
+
vi.stubGlobal('localStorage', {
|
|
23
|
+
getItem: (key: string) => storage.get(key) ?? null,
|
|
24
|
+
setItem: (key: string, value: string) => void storage.set(key, String(value)),
|
|
25
|
+
removeItem: (key: string) => void storage.delete(key),
|
|
26
|
+
clear: () => storage.clear(),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const { CommandPalette } = await import('../../components/CommandPalette.js')
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
cleanup()
|
|
33
|
+
cmsApi.mockReset()
|
|
34
|
+
localStorage.clear()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const collections = {
|
|
38
|
+
pages: { slug: 'pages', type: 'page' },
|
|
39
|
+
articles: { slug: 'articles', type: 'post' },
|
|
40
|
+
notes: { slug: 'notes', admin: { group: 'Posts' } },
|
|
41
|
+
drafts: { slug: 'drafts', type: 'post', fields: [{ name: 'title', type: 'text' }] },
|
|
42
|
+
faqs: { slug: 'faqs' },
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Issue 1206: every document result linked to `/collections/<slug>/<id>`,
|
|
47
|
+
* the generic editor, even for pages and post types.
|
|
48
|
+
*/
|
|
49
|
+
describe('CommandPalette document links', () => {
|
|
50
|
+
it.each([
|
|
51
|
+
['a page', 'pages', '/pages/d1/edit'],
|
|
52
|
+
['a post type', 'articles', '/posts/articles/d1/edit'],
|
|
53
|
+
['a post type defined by its Posts group', 'notes', '/posts/notes/d1/edit'],
|
|
54
|
+
['a post type missing the post fields', 'drafts', '/collections/drafts/d1'],
|
|
55
|
+
['a plain collection', 'faqs', '/collections/faqs/d1'],
|
|
56
|
+
])('opens %s in its editor', async (_kind, collection, path) => {
|
|
57
|
+
cmsApi.mockResolvedValue({
|
|
58
|
+
data: {
|
|
59
|
+
documents: [
|
|
60
|
+
{
|
|
61
|
+
id: 'd1',
|
|
62
|
+
title: 'Launch notes',
|
|
63
|
+
slug: 'launch-notes',
|
|
64
|
+
collection,
|
|
65
|
+
status: 'DRAFT',
|
|
66
|
+
updatedAt: '2026-08-01T00:00:00.000Z',
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
media: [],
|
|
70
|
+
users: [],
|
|
71
|
+
},
|
|
72
|
+
status: 200,
|
|
73
|
+
})
|
|
74
|
+
const onNavigate = vi.fn()
|
|
75
|
+
render(
|
|
76
|
+
<CommandPalette
|
|
77
|
+
open
|
|
78
|
+
onOpenChange={() => {}}
|
|
79
|
+
onNavigate={onNavigate}
|
|
80
|
+
collections={collections}
|
|
81
|
+
/>,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
fireEvent.change(screen.getByRole('combobox'), { target: { value: 'launch' } })
|
|
85
|
+
fireEvent.click(await screen.findByText('Launch notes', {}, { timeout: 3000 }))
|
|
86
|
+
|
|
87
|
+
await waitFor(() => expect(onNavigate).toHaveBeenCalledWith(path))
|
|
88
|
+
})
|
|
89
|
+
})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
+
|
|
5
|
+
vi.mock('../../lib/api.js', () => ({
|
|
6
|
+
cmsApi: async () => ({ data: { token: 'tok' }, status: 200 }),
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
// The pane opens a live draft stream once it has a token; happy-dom has none.
|
|
10
|
+
vi.stubGlobal(
|
|
11
|
+
'EventSource',
|
|
12
|
+
class {
|
|
13
|
+
addEventListener() {}
|
|
14
|
+
removeEventListener() {}
|
|
15
|
+
close() {}
|
|
16
|
+
},
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
const { LivePreview } = await import('../../components/LivePreview.js')
|
|
20
|
+
|
|
21
|
+
afterEach(() => cleanup())
|
|
22
|
+
|
|
23
|
+
const classesOf = (el: Element | null) => el?.getAttribute('class')?.split(/\s+/) ?? []
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The pane stays in view, no taller than the viewport, and still fills a
|
|
27
|
+
* shorter container. No hard-coded sizes: only the viewport bound.
|
|
28
|
+
*/
|
|
29
|
+
function expectBoundedStickyPane(pane: Element | null) {
|
|
30
|
+
const classes = classesOf(pane)
|
|
31
|
+
expect(classes).toContain('sticky')
|
|
32
|
+
expect(classes).toContain('top-0')
|
|
33
|
+
expect(classes).toContain('h-full')
|
|
34
|
+
expect(classes).toContain('max-h-dvh')
|
|
35
|
+
expect(classes.filter((c) => /\[.*\d+px.*\]/.test(c))).toEqual([])
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Issue 1206: the pane was `h-full` beside a form thousands of pixels tall,
|
|
40
|
+
* so its empty-state hint sat far below the fold and the pane looked blank.
|
|
41
|
+
*/
|
|
42
|
+
describe('LivePreview pane', () => {
|
|
43
|
+
it('keeps the empty-state hint in a sticky, bounded pane', () => {
|
|
44
|
+
render(<LivePreview collection="faqs" values={{}} onClose={() => {}} />)
|
|
45
|
+
const hint = screen.getByText('Save the document first to enable preview')
|
|
46
|
+
expectBoundedStickyPane(hint.parentElement)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('keeps the preview frame in a sticky, bounded pane', async () => {
|
|
50
|
+
const { container } = render(
|
|
51
|
+
<LivePreview
|
|
52
|
+
collection="faqs"
|
|
53
|
+
documentId="doc-1"
|
|
54
|
+
previewUrl="https://example.test/faqs/shipping"
|
|
55
|
+
values={{}}
|
|
56
|
+
onClose={() => {}}
|
|
57
|
+
/>,
|
|
58
|
+
)
|
|
59
|
+
await screen.findByTitle('Page Preview')
|
|
60
|
+
expectBoundedStickyPane(container.firstElementChild)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
@@ -31,4 +31,20 @@ describe('FieldRenderer', () => {
|
|
|
31
31
|
expect(container.textContent).toContain('Featured')
|
|
32
32
|
expect(container.textContent).not.toContain('Unknown field type')
|
|
33
33
|
})
|
|
34
|
+
|
|
35
|
+
// Issue 1206: a json field showed "Unknown field type: json".
|
|
36
|
+
it('shows a json field as read-only formatted JSON', () => {
|
|
37
|
+
const { container, getByLabelText } = render(
|
|
38
|
+
<FieldRenderer
|
|
39
|
+
field={{ name: 'settings', type: 'json', label: 'Settings' }}
|
|
40
|
+
value={{ theme: 'dark', columns: 3 }}
|
|
41
|
+
onChange={() => {}}
|
|
42
|
+
/>,
|
|
43
|
+
)
|
|
44
|
+
expect(container.textContent).not.toContain('Unknown field type')
|
|
45
|
+
expect(getByLabelText('Settings').textContent).toBe(
|
|
46
|
+
JSON.stringify({ theme: 'dark', columns: 3 }, null, 2),
|
|
47
|
+
)
|
|
48
|
+
expect(container.querySelector('input, textarea')).toBeNull()
|
|
49
|
+
})
|
|
34
50
|
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
+
|
|
5
|
+
vi.mock('../../lib/notifications-client.js', () => ({
|
|
6
|
+
listNotifications: async () => ({ ok: true, result: [] }),
|
|
7
|
+
unreadCount: async () => ({ ok: true, result: 0 }),
|
|
8
|
+
markNotificationRead: async () => ({ ok: false, error: 'unused' }),
|
|
9
|
+
markAllNotificationsRead: async () => ({ ok: true, result: 0 }),
|
|
10
|
+
subscribeNotificationStream: () => ({ close() {} }),
|
|
11
|
+
notificationSummary: () => '',
|
|
12
|
+
}))
|
|
13
|
+
|
|
14
|
+
vi.mock('../../lib/forms-service.js', () => ({
|
|
15
|
+
fetchFormsSidebarCounts: async () => [],
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
vi.mock('../../components/ThemeProvider.js', () => ({
|
|
19
|
+
useTheme: () => ({
|
|
20
|
+
adminBrand: { primaryUrl: null, markUrl: null, darkUrl: null, initials: 'P' },
|
|
21
|
+
resolvedTheme: 'light',
|
|
22
|
+
setTheme: () => {},
|
|
23
|
+
density: 'default',
|
|
24
|
+
}),
|
|
25
|
+
}))
|
|
26
|
+
|
|
27
|
+
// The palette's own links are covered in command-palette-links; this file
|
|
28
|
+
// checks only what the admin shell hands it.
|
|
29
|
+
const paletteProps = vi.fn()
|
|
30
|
+
vi.mock('../../components/CommandPalette.js', () => ({
|
|
31
|
+
CommandPalette: (props: Record<string, unknown>) => {
|
|
32
|
+
paletteProps(props)
|
|
33
|
+
return <div data-testid="command-palette" />
|
|
34
|
+
},
|
|
35
|
+
}))
|
|
36
|
+
|
|
37
|
+
const { Layout } = await import('../../layout/Layout.js')
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
cleanup()
|
|
41
|
+
vi.clearAllMocks()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Issue 1206: the command palette needs the config's collections to open
|
|
46
|
+
* pages and post types in their canvas editors. Without them every result
|
|
47
|
+
* links to the generic `/collections/<slug>/<id>` editor.
|
|
48
|
+
*/
|
|
49
|
+
describe('admin Layout command palette', () => {
|
|
50
|
+
it('passes the config collections through the Header to the palette', async () => {
|
|
51
|
+
const collections = {
|
|
52
|
+
pages: { slug: 'pages', type: 'page', fields: [] },
|
|
53
|
+
articles: { slug: 'articles', type: 'post', fields: [] },
|
|
54
|
+
}
|
|
55
|
+
render(
|
|
56
|
+
<Layout
|
|
57
|
+
config={{ collections }}
|
|
58
|
+
session={{ user: { id: 'u1', email: 'admin@example.com' } }}
|
|
59
|
+
currentPath="/"
|
|
60
|
+
onNavigate={vi.fn()}
|
|
61
|
+
>
|
|
62
|
+
Body
|
|
63
|
+
</Layout>,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
await screen.findByTestId('command-palette')
|
|
67
|
+
expect(paletteProps).toHaveBeenLastCalledWith(expect.objectContaining({ collections }))
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { describeLoadError, parseRetryAfter } from '../../lib/api-error.js'
|
|
5
|
+
|
|
6
|
+
describe('parseRetryAfter', () => {
|
|
7
|
+
it('reads seconds', () => {
|
|
8
|
+
expect(parseRetryAfter('42')).toBe(42_000)
|
|
9
|
+
expect(parseRetryAfter(' 0 ')).toBe(0)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('reads an HTTP date against the given clock and never goes negative', () => {
|
|
13
|
+
const now = Date.parse('Wed, 21 Oct 2026 07:28:00 GMT')
|
|
14
|
+
expect(parseRetryAfter('Wed, 21 Oct 2026 07:29:00 GMT', now)).toBe(60_000)
|
|
15
|
+
expect(parseRetryAfter('Wed, 21 Oct 2026 07:27:00 GMT', now)).toBe(0)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('returns null for a missing or unreadable header', () => {
|
|
19
|
+
expect(parseRetryAfter(null)).toBeNull()
|
|
20
|
+
expect(parseRetryAfter('')).toBeNull()
|
|
21
|
+
expect(parseRetryAfter('later')).toBeNull()
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('describeLoadError', () => {
|
|
26
|
+
it('says when to retry a 429', () => {
|
|
27
|
+
expect(
|
|
28
|
+
describeLoadError({ error: 'Too many requests', status: 429, retryAfterMs: 1_000 }),
|
|
29
|
+
).toBe('Too many requests right now. Try again in 1 second.')
|
|
30
|
+
expect(
|
|
31
|
+
describeLoadError({ error: 'Too many requests', status: 429, retryAfterMs: 1_500 }),
|
|
32
|
+
).toBe('Too many requests right now. Try again in 2 seconds.')
|
|
33
|
+
expect(
|
|
34
|
+
describeLoadError({ error: 'Too many requests', status: 429, retryAfterMs: 150_000 }),
|
|
35
|
+
).toBe('Too many requests right now. Try again in 3 minutes.')
|
|
36
|
+
expect(describeLoadError({ error: 'Too many requests', status: 429 })).toBe(
|
|
37
|
+
'Too many requests right now. Try again in a minute.',
|
|
38
|
+
)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('keeps the server message for other failures', () => {
|
|
42
|
+
expect(describeLoadError({ error: 'Forbidden', status: 403 })).toBe('Forbidden')
|
|
43
|
+
expect(describeLoadError({ status: 500 })).toBe('Request failed (500)')
|
|
44
|
+
})
|
|
45
|
+
})
|
|
@@ -76,3 +76,50 @@ describe('cmsApi', () => {
|
|
|
76
76
|
await expect(cmsApi('/anything')).resolves.toEqual({ error: 'offline', status: 0 })
|
|
77
77
|
})
|
|
78
78
|
})
|
|
79
|
+
|
|
80
|
+
/** Issue 1209: a 429 carries how long to wait, so a view can say when to retry. */
|
|
81
|
+
describe('cmsApi Retry-After', () => {
|
|
82
|
+
function limited(headers: Record<string, string>): Response {
|
|
83
|
+
return new Response(JSON.stringify({ error: 'Too many requests' }), {
|
|
84
|
+
status: 429,
|
|
85
|
+
headers: { 'Content-Type': 'application/json', ...headers },
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
it('reads Retry-After seconds on a 429', async () => {
|
|
90
|
+
vi.stubGlobal(
|
|
91
|
+
'fetch',
|
|
92
|
+
vi.fn(async () => limited({ 'Retry-After': '30' })),
|
|
93
|
+
)
|
|
94
|
+
const res = await cmsApi('/script-tags')
|
|
95
|
+
expect(res.status).toBe(429)
|
|
96
|
+
expect(res.error).toBe('Too many requests')
|
|
97
|
+
expect(res.retryAfterMs).toBe(30_000)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('reads a Retry-After HTTP date against the response Date', async () => {
|
|
101
|
+
vi.stubGlobal(
|
|
102
|
+
'fetch',
|
|
103
|
+
vi.fn(async () =>
|
|
104
|
+
limited({
|
|
105
|
+
Date: 'Wed, 21 Oct 2026 07:28:00 GMT',
|
|
106
|
+
'Retry-After': 'Wed, 21 Oct 2026 07:29:30 GMT',
|
|
107
|
+
}),
|
|
108
|
+
),
|
|
109
|
+
)
|
|
110
|
+
expect((await cmsApi('/forms')).retryAfterMs).toBe(90_000)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('leaves retryAfterMs out when the header is missing or unreadable', async () => {
|
|
114
|
+
vi.stubGlobal(
|
|
115
|
+
'fetch',
|
|
116
|
+
vi.fn(async () => limited({ 'Retry-After': 'soon' })),
|
|
117
|
+
)
|
|
118
|
+
expect(await cmsApi('/forms')).not.toHaveProperty('retryAfterMs')
|
|
119
|
+
vi.stubGlobal(
|
|
120
|
+
'fetch',
|
|
121
|
+
vi.fn(async () => limited({})),
|
|
122
|
+
)
|
|
123
|
+
expect(await cmsApi('/forms')).not.toHaveProperty('retryAfterMs')
|
|
124
|
+
})
|
|
125
|
+
})
|
|
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
editPathForDoc,
|
|
5
|
+
isPostTypeCollection,
|
|
5
6
|
newPathForCollection,
|
|
6
7
|
sourceEditPath,
|
|
7
8
|
} from '../../lib/collection-routes.js'
|
|
@@ -47,3 +48,24 @@ describe('newPathForCollection', () => {
|
|
|
47
48
|
expect(newPathForCollection({ type: 'collection' }, 'authors')).toBe('/authors/new')
|
|
48
49
|
})
|
|
49
50
|
})
|
|
51
|
+
|
|
52
|
+
// Issue 1206: `admin.group: 'Posts'` is a synonym for `type: 'post'` in the
|
|
53
|
+
// Posts list, the nav and the server. The canvas redirects use that (after
|
|
54
|
+
// checking the post editor's fields, see document-editor-path); the plain
|
|
55
|
+
// link helpers below do not, so a Posts-group collection missing the post
|
|
56
|
+
// fields keeps opening in the generic editor that can edit it.
|
|
57
|
+
describe('post types defined by their Posts group', () => {
|
|
58
|
+
it.each(['Posts', 'posts', 'POSTS'])('treats admin.group %s as a post type', (group) => {
|
|
59
|
+
expect(isPostTypeCollection({ admin: { group } })).toBe(true)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('leaves the plain link helpers on the generic routes', () => {
|
|
63
|
+
expect(editPathForDoc({ admin: { group: 'Posts' } }, 'notes', 'n1')).toBe('/notes/n1')
|
|
64
|
+
expect(newPathForCollection({ admin: { group: 'Posts' } }, 'notes')).toBe('/notes/new')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('leaves other groups to the generic editor', () => {
|
|
68
|
+
expect(isPostTypeCollection({ admin: { group: 'Content' } })).toBe(false)
|
|
69
|
+
expect(editPathForDoc({ admin: { group: 'Content' } }, 'authors', 'a1')).toBe('/authors/a1')
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import type { CollectionRouteMeta } from '../../lib/collection-routes.js'
|
|
4
|
+
import {
|
|
5
|
+
canvasCreatePath,
|
|
6
|
+
canvasEditPath,
|
|
7
|
+
createPathForCollection,
|
|
8
|
+
documentEditorPath,
|
|
9
|
+
} from '../../lib/document-editor-path.js'
|
|
10
|
+
|
|
11
|
+
const fieldsNamed = (...names: string[]) => names.map((name) => ({ name, type: 'text' }))
|
|
12
|
+
const postFields = fieldsNamed(
|
|
13
|
+
'title',
|
|
14
|
+
'sections',
|
|
15
|
+
'excerpt',
|
|
16
|
+
'featuredImage',
|
|
17
|
+
'body',
|
|
18
|
+
'category',
|
|
19
|
+
'tags',
|
|
20
|
+
'publishDate',
|
|
21
|
+
'metaTitle',
|
|
22
|
+
'metaDescription',
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const config = {
|
|
26
|
+
collections: {
|
|
27
|
+
pages: {
|
|
28
|
+
slug: 'pages',
|
|
29
|
+
type: 'page',
|
|
30
|
+
fields: fieldsNamed('title', 'sections', 'path', 'metaTitle', 'metaDescription'),
|
|
31
|
+
},
|
|
32
|
+
articles: { slug: 'articles', type: 'post', fields: postFields },
|
|
33
|
+
notes: { slug: 'notes', admin: { group: 'Posts' }, fields: postFields },
|
|
34
|
+
bare: { slug: 'bare', admin: { group: 'Posts' }, fields: fieldsNamed('title') },
|
|
35
|
+
faqs: { slug: 'faqs', fields: fieldsNamed('title') },
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
const col = (slug: keyof typeof config.collections): CollectionRouteMeta =>
|
|
39
|
+
config.collections[slug] as CollectionRouteMeta
|
|
40
|
+
|
|
41
|
+
// Issue 1206: which editor a document opens in, checked against the fields
|
|
42
|
+
// each canvas editor writes.
|
|
43
|
+
describe('document editor paths', () => {
|
|
44
|
+
it('opens pages and post types with their fields in the canvas editors', () => {
|
|
45
|
+
expect(documentEditorPath(config, col('pages'), 'pages', 'p1')).toBe('/pages/p1/edit')
|
|
46
|
+
expect(documentEditorPath(config, col('articles'), 'articles', 'a1')).toBe(
|
|
47
|
+
'/posts/articles/a1/edit',
|
|
48
|
+
)
|
|
49
|
+
expect(documentEditorPath(config, col('notes'), 'notes', 'n1')).toBe('/posts/notes/n1/edit')
|
|
50
|
+
expect(createPathForCollection(config, 'articles')).toBe('/posts/articles/new')
|
|
51
|
+
expect(createPathForCollection(config, 'notes')).toBe('/posts/notes/new')
|
|
52
|
+
expect(createPathForCollection(config, 'pages')).toBe('/pages/new')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('keeps a Posts-group collection missing the post fields on the generic editor', () => {
|
|
56
|
+
expect(canvasEditPath(config, col('bare'), 'bare', 'b1')).toBeUndefined()
|
|
57
|
+
expect(canvasCreatePath(config, col('bare'), 'bare')).toBeUndefined()
|
|
58
|
+
expect(documentEditorPath(config, col('bare'), 'bare', 'b1')).toBe('/collections/bare/b1')
|
|
59
|
+
expect(createPathForCollection(config, 'bare')).toBe('/bare/new')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('keeps a plain collection on the generic editor', () => {
|
|
63
|
+
expect(documentEditorPath(config, col('faqs'), 'faqs', 'f1')).toBe('/collections/faqs/f1')
|
|
64
|
+
expect(createPathForCollection(config, 'faqs')).toBe('/faqs/new')
|
|
65
|
+
expect(createPathForCollection(config, 'unknown')).toBe('/unknown/new')
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { beforeEach, expect, it, vi } from 'vitest'
|
|
2
2
|
const cmsApi = vi.hoisted(() => vi.fn())
|
|
3
3
|
vi.mock('../../lib/api.js', () => ({ cmsApi }))
|
|
4
|
-
import { fetchAllPages } from '../../lib/fetch-all-pages.js'
|
|
4
|
+
import { fetchAllPages, PaginatedRequestError } from '../../lib/fetch-all-pages.js'
|
|
5
5
|
|
|
6
6
|
beforeEach(() => cmsApi.mockReset())
|
|
7
7
|
|
|
@@ -42,6 +42,19 @@ it('does not fetch more pages after cancellation', async () => {
|
|
|
42
42
|
expect(cmsApi).toHaveBeenCalledTimes(1)
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
+
/** Issue 1209: a rate-limited page carries its status and a message that says when to retry. */
|
|
46
|
+
it('rejects a 429 page with its status and when to retry', async () => {
|
|
47
|
+
cmsApi
|
|
48
|
+
.mockResolvedValueOnce({ data: { docs: [{ id: 'a' }], total: 2 } })
|
|
49
|
+
.mockResolvedValueOnce({ error: 'Too many requests', status: 429, retryAfterMs: 10_000 })
|
|
50
|
+
const failure = await fetchAllPages('/media?pageSize=1').catch((err: unknown) => err)
|
|
51
|
+
expect(failure).toBeInstanceOf(PaginatedRequestError)
|
|
52
|
+
expect((failure as PaginatedRequestError).status).toBe(429)
|
|
53
|
+
expect((failure as PaginatedRequestError).message).toBe(
|
|
54
|
+
'Too many requests right now. Try again in 10 seconds.',
|
|
55
|
+
)
|
|
56
|
+
})
|
|
57
|
+
|
|
45
58
|
it('rejects an incomplete unique dataset even when the server says this is the final page', async () => {
|
|
46
59
|
cmsApi.mockResolvedValue({ data: { docs: [{ id: 'a' }, { id: 'b' }], total: 3, totalPages: 2 } })
|
|
47
60
|
await expect(fetchAllPages('/media?pageSize=2')).rejects.toThrow('list changed')
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
const cmsApi = vi.hoisted(() => vi.fn())
|
|
5
|
+
vi.mock('../../lib/api.js', () => ({ cmsApi, getApiBase: () => '/api/cms' }))
|
|
6
|
+
|
|
7
|
+
import { fetchFormStats, fetchForms } from '../../lib/forms-service.js'
|
|
8
|
+
|
|
9
|
+
beforeEach(() => cmsApi.mockReset())
|
|
10
|
+
|
|
11
|
+
/** Issue 1209: a rate-limited Forms read says when to retry, not a bare "Too many requests". */
|
|
12
|
+
describe('forms-service read failures', () => {
|
|
13
|
+
it('throws a busy message with the Retry-After time on a 429', async () => {
|
|
14
|
+
cmsApi.mockResolvedValue({ error: 'Too many requests', status: 429, retryAfterMs: 30_000 })
|
|
15
|
+
await expect(fetchForms()).rejects.toThrow(
|
|
16
|
+
'Too many requests right now. Try again in 30 seconds.',
|
|
17
|
+
)
|
|
18
|
+
await expect(fetchFormStats()).rejects.toThrow('Try again in 30 seconds')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('keeps the server message for other failures', async () => {
|
|
22
|
+
cmsApi.mockResolvedValue({ error: 'Forbidden', status: 403 })
|
|
23
|
+
await expect(fetchForms()).rejects.toThrow(/^Forbidden$/)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -138,3 +138,27 @@ describe('useApiData', () => {
|
|
|
138
138
|
expect(cmsApiMock).toHaveBeenCalledTimes(2)
|
|
139
139
|
})
|
|
140
140
|
})
|
|
141
|
+
|
|
142
|
+
/** Issue 1209: a 429 ends in a busy message at once instead of three timed retries. */
|
|
143
|
+
describe('useApiData rate limiting', () => {
|
|
144
|
+
it('does not retry a 429 and says when to try again', async () => {
|
|
145
|
+
cmsApiMock.mockResolvedValue({ error: 'Too many requests', status: 429, retryAfterMs: 5_000 })
|
|
146
|
+
const { result } = renderHook(() => useApiData<unknown>('/x'))
|
|
147
|
+
await waitFor(() => expect(result.current.loading).toBe(false))
|
|
148
|
+
expect(result.current.error).toBe('Too many requests right now. Try again in 5 seconds.')
|
|
149
|
+
expect(result.current.exhausted).toBe(true)
|
|
150
|
+
expect(cmsApiMock).toHaveBeenCalledTimes(1)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('does not retry a 429 page of an all-pages load (MediaBrowser)', async () => {
|
|
154
|
+
cmsApiMock.mockResolvedValue({ error: 'Too many requests', status: 429, retryAfterMs: 5_000 })
|
|
155
|
+
const { result } = renderHook(() =>
|
|
156
|
+
useApiData<unknown>('/media?pageSize=100', null, { allPages: true, retryBaseMs: 1 }),
|
|
157
|
+
)
|
|
158
|
+
await waitFor(() => expect(result.current.exhausted).toBe(true))
|
|
159
|
+
expect(result.current.error).toBe('Too many requests right now. Try again in 5 seconds.')
|
|
160
|
+
// Give any wrongly scheduled retry time to fire before counting calls.
|
|
161
|
+
await new Promise((resolve) => setTimeout(resolve, 30))
|
|
162
|
+
expect(cmsApiMock).toHaveBeenCalledTimes(1)
|
|
163
|
+
})
|
|
164
|
+
})
|