@prenta/admin 2.16.1 → 2.16.3
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 +12 -0
- package/dist/__tests__/fields/field-renderer-null.render.test.d.ts +2 -0
- package/dist/__tests__/fields/field-renderer-null.render.test.d.ts.map +1 -0
- package/dist/__tests__/fields/field-renderer-null.render.test.js +21 -0
- package/dist/__tests__/fields/field-renderer-null.render.test.js.map +1 -0
- package/dist/__tests__/lib/post-custom-fields.test.d.ts +2 -0
- package/dist/__tests__/lib/post-custom-fields.test.d.ts.map +1 -0
- package/dist/__tests__/lib/post-custom-fields.test.js +158 -0
- package/dist/__tests__/lib/post-custom-fields.test.js.map +1 -0
- package/dist/__tests__/lib/post-editor-custom-fields-api.test.d.ts +2 -0
- package/dist/__tests__/lib/post-editor-custom-fields-api.test.d.ts.map +1 -0
- package/dist/__tests__/lib/post-editor-custom-fields-api.test.js +104 -0
- package/dist/__tests__/lib/post-editor-custom-fields-api.test.js.map +1 -0
- package/dist/__tests__/lib/post-editor-custom-fields-undo.test.d.ts +2 -0
- package/dist/__tests__/lib/post-editor-custom-fields-undo.test.d.ts.map +1 -0
- package/dist/__tests__/lib/post-editor-custom-fields-undo.test.js +128 -0
- package/dist/__tests__/lib/post-editor-custom-fields-undo.test.js.map +1 -0
- package/dist/__tests__/views/editor-top-bar-layout.render.test.d.ts +2 -0
- package/dist/__tests__/views/editor-top-bar-layout.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/editor-top-bar-layout.render.test.js +157 -0
- package/dist/__tests__/views/editor-top-bar-layout.render.test.js.map +1 -0
- package/dist/__tests__/views/post-tab-custom-fields.render.test.d.ts +2 -0
- package/dist/__tests__/views/post-tab-custom-fields.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/post-tab-custom-fields.render.test.js +164 -0
- package/dist/__tests__/views/post-tab-custom-fields.render.test.js.map +1 -0
- package/dist/components/BreakpointPicker.d.ts.map +1 -1
- package/dist/components/BreakpointPicker.js +2 -2
- package/dist/components/BreakpointPicker.js.map +1 -1
- package/dist/fields/FieldRenderer.d.ts.map +1 -1
- package/dist/fields/FieldRenderer.js +7 -1
- package/dist/fields/FieldRenderer.js.map +1 -1
- package/dist/lib/post-custom-fields.d.ts +28 -0
- package/dist/lib/post-custom-fields.d.ts.map +1 -0
- package/dist/lib/post-custom-fields.js +173 -0
- package/dist/lib/post-custom-fields.js.map +1 -0
- package/dist/lib/post-editor-service.d.ts +29 -0
- package/dist/lib/post-editor-service.d.ts.map +1 -1
- package/dist/lib/post-editor-service.js +53 -0
- package/dist/lib/post-editor-service.js.map +1 -1
- package/dist/prenta-admin.css +1 -1
- package/dist/views/page-editor/EditorTopBar.d.ts.map +1 -1
- package/dist/views/page-editor/EditorTopBar.js +28 -17
- package/dist/views/page-editor/EditorTopBar.js.map +1 -1
- package/dist/views/post-editor/PostRowsField.d.ts +17 -0
- package/dist/views/post-editor/PostRowsField.d.ts.map +1 -0
- package/dist/views/post-editor/PostRowsField.js +29 -0
- package/dist/views/post-editor/PostRowsField.js.map +1 -0
- package/dist/views/post-editor/PostSectionEditor.d.ts.map +1 -1
- package/dist/views/post-editor/PostSectionEditor.js +16 -5
- package/dist/views/post-editor/PostSectionEditor.js.map +1 -1
- package/dist/views/post-editor/PostTab.d.ts +8 -5
- package/dist/views/post-editor/PostTab.d.ts.map +1 -1
- package/dist/views/post-editor/PostTab.js +53 -15
- package/dist/views/post-editor/PostTab.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/fields/field-renderer-null.render.test.tsx +34 -0
- package/src/__tests__/lib/post-custom-fields.test.ts +170 -0
- package/src/__tests__/lib/post-editor-custom-fields-api.test.ts +129 -0
- package/src/__tests__/lib/post-editor-custom-fields-undo.test.ts +152 -0
- package/src/__tests__/views/editor-top-bar-layout.render.test.tsx +198 -0
- package/src/__tests__/views/post-tab-custom-fields.render.test.tsx +239 -0
- package/src/components/BreakpointPicker.tsx +7 -6
- package/src/fields/FieldRenderer.tsx +6 -1
- package/src/lib/post-custom-fields.ts +191 -0
- package/src/lib/post-editor-service.ts +71 -0
- package/src/styles/responsive.css +44 -18
- package/src/views/page-editor/EditorTopBar.tsx +109 -65
- package/src/views/post-editor/PostRowsField.tsx +110 -0
- package/src/views/post-editor/PostSectionEditor.tsx +26 -7
- package/src/views/post-editor/PostTab.tsx +72 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostTab.js","sourceRoot":"","sources":["../../../src/views/post-editor/PostTab.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"PostTab.js","sourceRoot":"","sources":["../../../src/views/post-editor/PostTab.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAmB,MAAM,kCAAkC,CAAA;AACpF,OAAO,EAAE,gBAAgB,EAA8B,MAAM,iCAAiC,CAAA;AAC9F,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AASlD;;;;GAIG;AACH,SAAS,YAAY,CAAC,KAA4B,EAAE,MAAe;IACjE,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC7D,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC9F,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,MAAM,KAAK,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AAC,CACF,KAAC,aAAa,IACZ,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,GAC1C,CACH,IAjBO,KAAK,CAAC,IAAI,CAkBd,CACP,CAAA;oBACH,CAAC,CAAC,IACO,CACZ,IACG,CACP,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prenta/admin",
|
|
3
|
-
"version": "2.16.
|
|
3
|
+
"version": "2.16.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -99,16 +99,16 @@
|
|
|
99
99
|
"tailwindcss": "^4.0.0",
|
|
100
100
|
"typescript": "^5.7.0",
|
|
101
101
|
"vitest": "^4.1.12",
|
|
102
|
-
"@prenta/
|
|
103
|
-
"@prenta/
|
|
102
|
+
"@prenta/core": "8.21.8",
|
|
103
|
+
"@prenta/plugin-commerce": "1.0.1",
|
|
104
104
|
"@prenta/plugin-ai": "4.0.1",
|
|
105
105
|
"@prenta/plugin-blocks": "1.0.1",
|
|
106
|
-
"@prenta/
|
|
106
|
+
"@prenta/component-blocks": "0.3.1",
|
|
107
107
|
"@prenta/plugin-forms": "1.0.2",
|
|
108
108
|
"@prenta/plugin-media": "1.0.1",
|
|
109
|
-
"@prenta/plugin-navigation": "1.1.0",
|
|
110
109
|
"@prenta/plugin-seo": "2.0.1",
|
|
111
|
-
"@prenta/
|
|
110
|
+
"@prenta/plugin-navigation": "1.1.0",
|
|
111
|
+
"@prenta/sections-react": "0.20.24"
|
|
112
112
|
},
|
|
113
113
|
"scripts": {
|
|
114
114
|
"build": "tsc --project tsconfig.json && npx @tailwindcss/cli -i src/styles/build-input.css -o dist/prenta-admin.css --minify && node scripts/copy-font-files.mjs",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
3
|
+
import { cleanup, render } from '@testing-library/react'
|
|
4
|
+
import { FieldRenderer } from '../../fields/FieldRenderer.js'
|
|
5
|
+
|
|
6
|
+
afterEach(cleanup)
|
|
7
|
+
|
|
8
|
+
describe('FieldRenderer', () => {
|
|
9
|
+
// The collection editor passes a stored null straight through, and the
|
|
10
|
+
// text control reads value.length.
|
|
11
|
+
it.each(['text', 'url', 'email'])('renders a stored null %s value as empty', (type) => {
|
|
12
|
+
const { container } = render(
|
|
13
|
+
<FieldRenderer
|
|
14
|
+
field={{ name: 'ctaUrl', type, label: 'CTA link' }}
|
|
15
|
+
value={null}
|
|
16
|
+
onChange={() => {}}
|
|
17
|
+
/>,
|
|
18
|
+
)
|
|
19
|
+
expect(container.querySelector('input')?.value).toBe('')
|
|
20
|
+
expect(container.textContent).not.toContain('Unknown field type')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('gives a boolean field a toggle', () => {
|
|
24
|
+
const { container } = render(
|
|
25
|
+
<FieldRenderer
|
|
26
|
+
field={{ name: 'featured', type: 'boolean', label: 'Featured' }}
|
|
27
|
+
value={null}
|
|
28
|
+
onChange={() => {}}
|
|
29
|
+
/>,
|
|
30
|
+
)
|
|
31
|
+
expect(container.textContent).toContain('Featured')
|
|
32
|
+
expect(container.textContent).not.toContain('Unknown field type')
|
|
33
|
+
})
|
|
34
|
+
})
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
import { customPostFields } from '../../lib/post-custom-fields.js'
|
|
4
|
+
|
|
5
|
+
/** The shape of a case-study post type: shared post fields plus its own. */
|
|
6
|
+
const caseStudyFields = {
|
|
7
|
+
title: { type: 'text', label: 'Case study title', required: true },
|
|
8
|
+
slug: { type: 'slug', label: 'Slug' },
|
|
9
|
+
sections: { type: 'json', label: 'Sections' },
|
|
10
|
+
excerpt: { type: 'text', label: 'Summary' },
|
|
11
|
+
featuredImage: { type: 'media', label: 'Hero image' },
|
|
12
|
+
body: { type: 'richText', label: 'Body' },
|
|
13
|
+
category: { type: 'text', label: 'Category' },
|
|
14
|
+
tags: { type: 'array', label: 'Tags', fields: { tag: { type: 'text', label: 'Tag' } } },
|
|
15
|
+
publishDate: { type: 'date', label: 'Publish date' },
|
|
16
|
+
metaTitle: { type: 'text', label: 'Meta title' },
|
|
17
|
+
metaDescription: { type: 'text', label: 'Meta description' },
|
|
18
|
+
ogImage: { type: 'media', label: 'OG image' },
|
|
19
|
+
canonical: { type: 'url', label: 'Canonical' },
|
|
20
|
+
noIndex: { type: 'boolean', label: 'No index' },
|
|
21
|
+
clientName: { type: 'text', label: 'Client name', required: true, maxLength: 120 },
|
|
22
|
+
industry: { type: 'text' },
|
|
23
|
+
challenge: { type: 'richText', label: 'Challenge' },
|
|
24
|
+
keyMetrics: {
|
|
25
|
+
type: 'array',
|
|
26
|
+
label: 'Key metrics',
|
|
27
|
+
maxRows: 6,
|
|
28
|
+
fields: {
|
|
29
|
+
value: { type: 'text', label: 'Value', required: true, maxLength: 32 },
|
|
30
|
+
label: { type: 'text', label: 'Label', required: true },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
publishedDate: { type: 'date', label: 'Published' },
|
|
34
|
+
ctaUrl: { type: 'url', label: 'CTA link', admin: { description: 'Where the button goes' } },
|
|
35
|
+
featured: { type: 'boolean', label: 'Featured' },
|
|
36
|
+
services: { type: 'relationship', label: 'Services', relationTo: 'services', hasMany: true },
|
|
37
|
+
logo: { type: 'media', label: 'Client logo' },
|
|
38
|
+
gallery: {
|
|
39
|
+
type: 'array',
|
|
40
|
+
label: 'Gallery',
|
|
41
|
+
fields: { image: { type: 'media', label: 'Image' } },
|
|
42
|
+
},
|
|
43
|
+
budget: { type: 'number', label: 'Budget' },
|
|
44
|
+
designPayload: { type: 'json', label: 'Design payload' },
|
|
45
|
+
internalNotes: { type: 'text', label: 'Internal notes', hidden: true },
|
|
46
|
+
importedFrom: { type: 'text', label: 'Imported from', admin: { readOnly: true } },
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const names = () => customPostFields(caseStudyFields).map((f) => f.name)
|
|
50
|
+
|
|
51
|
+
describe('customPostFields', () => {
|
|
52
|
+
it("returns the post type's own editable fields in config order", () => {
|
|
53
|
+
expect(names()).toEqual([
|
|
54
|
+
'clientName',
|
|
55
|
+
'industry',
|
|
56
|
+
'challenge',
|
|
57
|
+
'keyMetrics',
|
|
58
|
+
'publishedDate',
|
|
59
|
+
'ctaUrl',
|
|
60
|
+
'featured',
|
|
61
|
+
])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('leaves out what the Post tab, the canvas and the SEO tab already edit', () => {
|
|
65
|
+
for (const owned of [
|
|
66
|
+
'title',
|
|
67
|
+
'slug',
|
|
68
|
+
'body',
|
|
69
|
+
'sections',
|
|
70
|
+
'tags',
|
|
71
|
+
'metaTitle',
|
|
72
|
+
'canonical',
|
|
73
|
+
'noIndex',
|
|
74
|
+
'ogImage',
|
|
75
|
+
]) {
|
|
76
|
+
expect(names()).not.toContain(owned)
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('leaves out hidden and read-only fields', () => {
|
|
81
|
+
expect(names()).not.toContain('internalNotes')
|
|
82
|
+
expect(names()).not.toContain('importedFrom')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('leaves out types whose control would store the wrong thing', () => {
|
|
86
|
+
// media writes a placeholder, relationship searches another collection,
|
|
87
|
+
// number turns an empty box into 0, json has no control.
|
|
88
|
+
for (const unsafe of ['services', 'logo', 'gallery', 'budget', 'designPayload']) {
|
|
89
|
+
expect(names()).not.toContain(unsafe)
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('carries label, required, max length and help text, and names an unlabelled field', () => {
|
|
94
|
+
const byName = Object.fromEntries(customPostFields(caseStudyFields).map((f) => [f.name, f]))
|
|
95
|
+
expect(byName.clientName).toMatchObject({
|
|
96
|
+
label: 'Client name',
|
|
97
|
+
required: true,
|
|
98
|
+
type: 'text',
|
|
99
|
+
maxLength: 120,
|
|
100
|
+
})
|
|
101
|
+
expect(byName.industry?.label).toBe('Industry')
|
|
102
|
+
expect(byName.ctaUrl?.helpText).toBe('Where the button goes')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('turns an array of text columns into editable rows', () => {
|
|
106
|
+
const metrics = customPostFields(caseStudyFields).find((f) => f.name === 'keyMetrics')
|
|
107
|
+
expect(metrics).toMatchObject({
|
|
108
|
+
type: 'rows',
|
|
109
|
+
maxRows: 6,
|
|
110
|
+
rowFields: [
|
|
111
|
+
{ name: 'value', label: 'Value', required: true, maxLength: 32 },
|
|
112
|
+
{ name: 'label', label: 'Label', required: true },
|
|
113
|
+
],
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('flattens labelled select options and skips a multi-value select', () => {
|
|
118
|
+
const out = customPostFields({
|
|
119
|
+
region: {
|
|
120
|
+
type: 'select',
|
|
121
|
+
label: 'Region',
|
|
122
|
+
options: [{ label: 'Seattle', value: 'seattle' }, 'tampa'],
|
|
123
|
+
},
|
|
124
|
+
channels: { type: 'select', label: 'Channels', multiple: true, options: ['seo', 'ppc'] },
|
|
125
|
+
})
|
|
126
|
+
expect(out.map((f) => f.name)).toEqual(['region'])
|
|
127
|
+
expect(out[0]?.options).toEqual(['seattle', 'tampa'])
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('skips a date that stores a time, which the date-only control would drop', () => {
|
|
131
|
+
const out = customPostFields({
|
|
132
|
+
eventDay: { type: 'date', label: 'Event day' },
|
|
133
|
+
publishedDate: { type: 'date', label: 'Published', includeTime: true },
|
|
134
|
+
})
|
|
135
|
+
expect(out.map((f) => f.name)).toEqual(['eventDay'])
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('skips an array with a hidden or read-only column', () => {
|
|
139
|
+
const column = { type: 'text', label: 'Value' }
|
|
140
|
+
const out = customPostFields({
|
|
141
|
+
open: { type: 'array', label: 'Open', fields: { value: column } },
|
|
142
|
+
withHidden: {
|
|
143
|
+
type: 'array',
|
|
144
|
+
label: 'With hidden',
|
|
145
|
+
fields: { value: column, secret: { type: 'text', label: 'Secret', hidden: true } },
|
|
146
|
+
},
|
|
147
|
+
withReadOnly: {
|
|
148
|
+
type: 'array',
|
|
149
|
+
label: 'With read-only',
|
|
150
|
+
fields: { value: column, source: { type: 'text', admin: { readOnly: true } } },
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
expect(out.map((f) => f.name)).toEqual(['open'])
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('skips names the server reads as status or page-builder envelope', () => {
|
|
157
|
+
const out = customPostFields({
|
|
158
|
+
status: { type: 'text', label: 'Status' },
|
|
159
|
+
layout: { type: 'text', label: 'Layout' },
|
|
160
|
+
data: { type: 'text', label: 'Data' },
|
|
161
|
+
})
|
|
162
|
+
expect(out).toEqual([])
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('returns nothing for a post type with only the shared fields, or no config', () => {
|
|
166
|
+
const shared = { title: caseStudyFields.title, body: caseStudyFields.body }
|
|
167
|
+
expect(customPostFields(shared)).toEqual([])
|
|
168
|
+
expect(customPostFields(undefined)).toEqual([])
|
|
169
|
+
})
|
|
170
|
+
})
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
const cmsApi = vi.fn()
|
|
5
|
+
vi.mock('../../lib/api.js', () => ({
|
|
6
|
+
cmsApi: (...args: unknown[]) => cmsApi(...args),
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
const { fetchPostForEditor, savePostDraft, customFieldValue } =
|
|
10
|
+
await import('../../lib/post-editor-service.js')
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
cmsApi.mockReset()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const storedRow = {
|
|
17
|
+
id: 'cs1',
|
|
18
|
+
title: 'Mary Frances',
|
|
19
|
+
slug: 'mary-frances',
|
|
20
|
+
status: 'DRAFT',
|
|
21
|
+
workflowStage: 'DRAFT',
|
|
22
|
+
reviewNote: null,
|
|
23
|
+
publishedAt: null,
|
|
24
|
+
updatedAt: '2026-11-26T15:41:39.442Z',
|
|
25
|
+
data: {
|
|
26
|
+
title: 'Mary Frances',
|
|
27
|
+
slug: 'mary-frances',
|
|
28
|
+
body: '<p>Body</p>',
|
|
29
|
+
excerpt: 'Summary',
|
|
30
|
+
metaTitle: 'Meta',
|
|
31
|
+
focusKeyword: 'ecommerce growth',
|
|
32
|
+
clientName: 'Mary Frances',
|
|
33
|
+
keyMetrics: [{ label: 'Revenue', value: '+60%' }],
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function sentBody(call: number): Record<string, unknown> {
|
|
38
|
+
const init = cmsApi.mock.calls[call]?.[1] as { body: string }
|
|
39
|
+
return JSON.parse(init.body) as Record<string, unknown>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('post editor custom fields', () => {
|
|
43
|
+
it('loads the stored values of fields the editor does not manage itself', async () => {
|
|
44
|
+
cmsApi.mockResolvedValueOnce({ data: storedRow, status: 200 })
|
|
45
|
+
const post = await fetchPostForEditor('case-studies', 'cs1')
|
|
46
|
+
|
|
47
|
+
expect(customFieldValue(post, 'clientName')).toBe('Mary Frances')
|
|
48
|
+
expect(customFieldValue(post, 'keyMetrics')).toEqual([{ label: 'Revenue', value: '+60%' }])
|
|
49
|
+
expect(customFieldValue(post, 'challenge')).toBeUndefined()
|
|
50
|
+
expect(post.customFields).not.toHaveProperty('body')
|
|
51
|
+
expect(post.customFields).not.toHaveProperty('title')
|
|
52
|
+
expect(post.customFieldEdits).toEqual({})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('shows a pending edit ahead of the stored value, including a cleared one', async () => {
|
|
56
|
+
cmsApi.mockResolvedValueOnce({ data: storedRow, status: 200 })
|
|
57
|
+
const post = await fetchPostForEditor('case-studies', 'cs1')
|
|
58
|
+
|
|
59
|
+
expect(
|
|
60
|
+
customFieldValue({ ...post, customFieldEdits: { clientName: 'MF' } }, 'clientName'),
|
|
61
|
+
).toBe('MF')
|
|
62
|
+
expect(customFieldValue({ ...post, customFieldEdits: { clientName: '' } }, 'clientName')).toBe(
|
|
63
|
+
'',
|
|
64
|
+
)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('saves edited custom fields with the draft', async () => {
|
|
68
|
+
cmsApi
|
|
69
|
+
.mockResolvedValueOnce({ data: storedRow, status: 200 })
|
|
70
|
+
.mockResolvedValueOnce({ data: storedRow, status: 200 })
|
|
71
|
+
const post = await fetchPostForEditor('case-studies', 'cs1')
|
|
72
|
+
|
|
73
|
+
await savePostDraft({
|
|
74
|
+
...post,
|
|
75
|
+
customFieldEdits: { challenge: '<p>Growth had leveled off.</p>', clientName: 'MF' },
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const [url, init] = cmsApi.mock.calls[1] as [string, { method: string }]
|
|
79
|
+
expect(url).toBe('/collections/case-studies/cs1')
|
|
80
|
+
expect(init.method).toBe('PUT')
|
|
81
|
+
expect(sentBody(1)).toMatchObject({
|
|
82
|
+
challenge: '<p>Growth had leveled off.</p>',
|
|
83
|
+
clientName: 'MF',
|
|
84
|
+
title: 'Mary Frances',
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('does not re-send values nobody edited', async () => {
|
|
89
|
+
cmsApi
|
|
90
|
+
.mockResolvedValueOnce({ data: storedRow, status: 200 })
|
|
91
|
+
.mockResolvedValueOnce({ data: storedRow, status: 200 })
|
|
92
|
+
const post = await fetchPostForEditor('case-studies', 'cs1')
|
|
93
|
+
|
|
94
|
+
await savePostDraft(post)
|
|
95
|
+
|
|
96
|
+
const body = sentBody(1)
|
|
97
|
+
// The server merges a save onto the stored document. Re-sending a loaded
|
|
98
|
+
// copy would overwrite what the SEO tab saved after this post was opened.
|
|
99
|
+
expect(body).not.toHaveProperty('focusKeyword')
|
|
100
|
+
expect(body).not.toHaveProperty('clientName')
|
|
101
|
+
expect(body).not.toHaveProperty('keyMetrics')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('never lets a custom field edit replace a field the editor owns', async () => {
|
|
105
|
+
cmsApi
|
|
106
|
+
.mockResolvedValueOnce({ data: storedRow, status: 200 })
|
|
107
|
+
.mockResolvedValueOnce({ data: storedRow, status: 200 })
|
|
108
|
+
const post = await fetchPostForEditor('case-studies', 'cs1')
|
|
109
|
+
|
|
110
|
+
await savePostDraft({ ...post, customFieldEdits: { title: 'Hijacked', sections: 'nope' } })
|
|
111
|
+
|
|
112
|
+
const body = sentBody(1)
|
|
113
|
+
expect(body.title).toBe('Mary Frances')
|
|
114
|
+
expect(Array.isArray(body.sections)).toBe(true)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('starts clean again after a save', async () => {
|
|
118
|
+
cmsApi.mockResolvedValueOnce({ data: storedRow, status: 200 }).mockResolvedValueOnce({
|
|
119
|
+
data: { ...storedRow, data: { ...storedRow.data, clientName: 'MF' } },
|
|
120
|
+
status: 200,
|
|
121
|
+
})
|
|
122
|
+
const post = await fetchPostForEditor('case-studies', 'cs1')
|
|
123
|
+
|
|
124
|
+
const saved = await savePostDraft({ ...post, customFieldEdits: { clientName: 'MF' } })
|
|
125
|
+
|
|
126
|
+
expect(saved.customFieldEdits).toEqual({})
|
|
127
|
+
expect(customFieldValue(saved, 'clientName')).toBe('MF')
|
|
128
|
+
})
|
|
129
|
+
})
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
const cmsApi = vi.fn()
|
|
5
|
+
vi.mock('../../lib/api.js', () => ({
|
|
6
|
+
cmsApi: (...args: unknown[]) => cmsApi(...args),
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
const { fetchPostForEditor, savePostDraft, rebaseCustomFieldEdits, customFieldValue } =
|
|
10
|
+
await import('../../lib/post-editor-service.js')
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
cmsApi.mockReset()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
/** The fields the Post tab edits for this post type. */
|
|
17
|
+
const NAMES = ['clientName', 'industry', 'keyMetrics']
|
|
18
|
+
|
|
19
|
+
function row(data: Record<string, unknown>) {
|
|
20
|
+
return {
|
|
21
|
+
id: 'cs1',
|
|
22
|
+
title: 'Mary Frances',
|
|
23
|
+
slug: 'mary-frances',
|
|
24
|
+
status: 'DRAFT',
|
|
25
|
+
workflowStage: 'DRAFT',
|
|
26
|
+
reviewNote: null,
|
|
27
|
+
publishedAt: null,
|
|
28
|
+
updatedAt: null,
|
|
29
|
+
data: { title: 'Mary Frances', slug: 'mary-frances', ...data },
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function sentBody(call: number): Record<string, unknown> {
|
|
34
|
+
const init = cmsApi.mock.calls[call]?.[1] as { body: string }
|
|
35
|
+
return JSON.parse(init.body) as Record<string, unknown>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('rebaseCustomFieldEdits (undo and redo)', () => {
|
|
39
|
+
it('turns an undone, already-saved change back into a pending edit', async () => {
|
|
40
|
+
// Open with A, change to B, save. The history snapshot still says A.
|
|
41
|
+
cmsApi.mockResolvedValueOnce({ data: row({ clientName: 'A' }), status: 200 })
|
|
42
|
+
const beforeEdit = await fetchPostForEditor('case-studies', 'cs1')
|
|
43
|
+
cmsApi.mockResolvedValueOnce({ data: row({ clientName: 'B' }), status: 200 })
|
|
44
|
+
const saved = await savePostDraft({ ...beforeEdit, customFieldEdits: { clientName: 'B' } })
|
|
45
|
+
|
|
46
|
+
const undone = rebaseCustomFieldEdits(beforeEdit, saved, NAMES)
|
|
47
|
+
|
|
48
|
+
expect(customFieldValue(undone, 'clientName')).toBe('A')
|
|
49
|
+
expect(undone.customFieldEdits).toEqual({ clientName: 'A' })
|
|
50
|
+
|
|
51
|
+
cmsApi.mockResolvedValueOnce({ data: row({ clientName: 'A' }), status: 200 })
|
|
52
|
+
await savePostDraft(undone)
|
|
53
|
+
expect(sentBody(2).clientName).toBe('A')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('clears a value that did not exist in the restored snapshot', async () => {
|
|
57
|
+
cmsApi.mockResolvedValueOnce({ data: row({}), status: 200 })
|
|
58
|
+
const beforeEdit = await fetchPostForEditor('case-studies', 'cs1')
|
|
59
|
+
cmsApi.mockResolvedValueOnce({ data: row({ industry: 'Fashion' }), status: 200 })
|
|
60
|
+
const saved = await savePostDraft({ ...beforeEdit, customFieldEdits: { industry: 'Fashion' } })
|
|
61
|
+
|
|
62
|
+
const undone = rebaseCustomFieldEdits(beforeEdit, saved, NAMES)
|
|
63
|
+
|
|
64
|
+
// null reaches the server; undefined would be dropped from the request.
|
|
65
|
+
expect(undone.customFieldEdits).toEqual({ industry: null })
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('leaves nothing pending when the snapshot matches what is stored', async () => {
|
|
69
|
+
cmsApi.mockResolvedValueOnce({
|
|
70
|
+
data: row({ clientName: 'A', keyMetrics: [{ value: '+60%', label: 'Revenue' }] }),
|
|
71
|
+
status: 200,
|
|
72
|
+
})
|
|
73
|
+
const post = await fetchPostForEditor('case-studies', 'cs1')
|
|
74
|
+
|
|
75
|
+
expect(rebaseCustomFieldEdits(post, post, NAMES).customFieldEdits).toEqual({})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('never turns an old copy of a key another tab owns into an edit', async () => {
|
|
79
|
+
// Open, change the client name, save; then the SEO tab saves a new focus
|
|
80
|
+
// keyword and the editor reloads. Undo restores the first snapshot.
|
|
81
|
+
cmsApi.mockResolvedValueOnce({
|
|
82
|
+
data: row({ clientName: 'A', focusKeyword: 'old keyword' }),
|
|
83
|
+
status: 200,
|
|
84
|
+
})
|
|
85
|
+
const beforeEdit = await fetchPostForEditor('case-studies', 'cs1')
|
|
86
|
+
cmsApi.mockResolvedValueOnce({
|
|
87
|
+
data: row({ clientName: 'B', focusKeyword: 'new keyword' }),
|
|
88
|
+
status: 200,
|
|
89
|
+
})
|
|
90
|
+
const afterSeoSave = await fetchPostForEditor('case-studies', 'cs1')
|
|
91
|
+
|
|
92
|
+
const undone = rebaseCustomFieldEdits(beforeEdit, afterSeoSave, NAMES)
|
|
93
|
+
|
|
94
|
+
expect(undone.customFieldEdits).toEqual({ clientName: 'A' })
|
|
95
|
+
expect(undone.customFields?.focusKeyword).toBe('new keyword')
|
|
96
|
+
|
|
97
|
+
cmsApi.mockResolvedValueOnce({ data: row({ clientName: 'A' }), status: 200 })
|
|
98
|
+
await savePostDraft(undone)
|
|
99
|
+
expect(sentBody(2)).not.toHaveProperty('focusKeyword')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('keeps an edit that was pending and never saved', async () => {
|
|
103
|
+
cmsApi.mockResolvedValueOnce({ data: row({ clientName: 'A' }), status: 200 })
|
|
104
|
+
const saved = await fetchPostForEditor('case-studies', 'cs1')
|
|
105
|
+
const snapshot = { ...saved, customFieldEdits: { clientName: 'B' } }
|
|
106
|
+
|
|
107
|
+
expect(rebaseCustomFieldEdits(snapshot, saved, NAMES).customFieldEdits).toEqual({
|
|
108
|
+
clientName: 'B',
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
describe('creating a post with custom fields', () => {
|
|
114
|
+
it('sends custom field edits with the first save', async () => {
|
|
115
|
+
cmsApi.mockResolvedValueOnce({ data: row({ clientName: 'Mary Frances' }), status: 200 })
|
|
116
|
+
|
|
117
|
+
const created = await savePostDraft({
|
|
118
|
+
id: null,
|
|
119
|
+
postType: 'case-studies',
|
|
120
|
+
title: 'Mary Frances',
|
|
121
|
+
slug: 'mary-frances',
|
|
122
|
+
excerpt: '',
|
|
123
|
+
featuredImage: '',
|
|
124
|
+
featuredImageUrl: '',
|
|
125
|
+
body: '',
|
|
126
|
+
category: '',
|
|
127
|
+
authorName: '',
|
|
128
|
+
canvasRelatedPosts: null,
|
|
129
|
+
tags: [],
|
|
130
|
+
status: 'DRAFT',
|
|
131
|
+
workflowStage: 'DRAFT',
|
|
132
|
+
reviewNote: null,
|
|
133
|
+
publishDate: null,
|
|
134
|
+
scheduledAt: null,
|
|
135
|
+
scheduledUnpublishAt: null,
|
|
136
|
+
sections: [],
|
|
137
|
+
seoTitle: '',
|
|
138
|
+
seoDescription: '',
|
|
139
|
+
publishedAt: null,
|
|
140
|
+
updatedAt: null,
|
|
141
|
+
customFields: {},
|
|
142
|
+
customFieldEdits: { clientName: 'Mary Frances' },
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
const [url, init] = cmsApi.mock.calls[0] as [string, { method: string }]
|
|
146
|
+
expect(url).toBe('/collections/case-studies')
|
|
147
|
+
expect(init.method).toBe('POST')
|
|
148
|
+
expect(sentBody(0).clientName).toBe('Mary Frances')
|
|
149
|
+
expect(created.customFieldEdits).toEqual({})
|
|
150
|
+
expect(customFieldValue(created, 'clientName')).toBe('Mary Frances')
|
|
151
|
+
})
|
|
152
|
+
})
|