forked from decaporg/decap-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditorial_workflow_spec_test_backend.js
More file actions
312 lines (268 loc) · 9.44 KB
/
editorial_workflow_spec_test_backend.js
File metadata and controls
312 lines (268 loc) · 9.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import '../utils/dismiss-local-backup';
import {
login,
createPost,
createPostAndExit,
exitEditor,
goToWorkflow,
goToCollections,
updateWorkflowStatus,
publishWorkflowEntry,
assertWorkflowStatusInEditor,
assertPublishedEntry,
deleteEntryInEditor,
assertOnCollectionsPage,
assertEntryDeleted,
assertWorkflowStatus,
updateWorkflowStatusInEditor,
unpublishEntry,
publishEntryInEditor,
duplicateEntry,
goToEntry,
populateEntry,
publishAndCreateNewEntryInEditor,
publishAndDuplicateEntryInEditor,
assertNotification,
assertFieldValidationError,
} from '../utils/steps';
import { workflowStatus, editorStatus, publishTypes, notifications } from '../utils/constants';
const entry1 = {
title: 'first title',
body: 'first body',
};
const entry2 = {
title: 'second title',
body: 'second body',
};
const entry3 = {
title: 'third title',
body: 'third body',
};
describe('Test Backend Editorial Workflow', () => {
after(() => {
cy.task('teardownBackend', { backend: 'test' });
});
before(() => {
Cypress.config('defaultCommandTimeout', 4000);
cy.task('setupBackend', { backend: 'test' });
});
beforeEach(() => {
cy.task('updateConfig', { collections: [{ publish: true }] });
});
it('successfully loads', () => {
login();
});
it('can create an entry', () => {
login();
createPost(entry1);
// new entry should show 'Delete unpublished entry'
cy.contains('button', 'Delete unpublished entry');
cy.url().should(
'eq',
`http://localhost:8080/#/collections/posts/entries/1970-01-01-${entry1.title
.toLowerCase()
.replace(/\s/, '-')}`,
);
exitEditor();
});
it('can publish an editorial workflow entry', () => {
login();
createPostAndExit(entry1);
goToWorkflow();
updateWorkflowStatus(entry1, workflowStatus.draft, workflowStatus.ready);
publishWorkflowEntry(entry1);
});
it('can update an entry', () => {
login();
createPostAndExit(entry1);
goToWorkflow();
updateWorkflowStatus(entry1, workflowStatus.draft, workflowStatus.ready);
publishWorkflowEntry(entry1);
goToEntry(entry1);
populateEntry(entry2);
// existing entry should show 'Delete unpublished changes'
cy.contains('button', 'Delete unpublished changes');
// existing entry slug should remain the same after save'
cy.url().should(
'eq',
`http://localhost:8080/#/collections/posts/entries/1970-01-01-${entry1.title
.toLowerCase()
.replace(/\s/, '-')}`,
);
exitEditor();
});
it('can change workflow status', () => {
login();
createPostAndExit(entry1);
goToWorkflow();
updateWorkflowStatus(entry1, workflowStatus.draft, workflowStatus.review);
updateWorkflowStatus(entry1, workflowStatus.review, workflowStatus.ready);
updateWorkflowStatus(entry1, workflowStatus.ready, workflowStatus.review);
updateWorkflowStatus(entry1, workflowStatus.review, workflowStatus.draft);
updateWorkflowStatus(entry1, workflowStatus.draft, workflowStatus.ready);
});
it('can change status on and publish multiple entries', () => {
login();
createPostAndExit(entry1);
createPostAndExit(entry2);
createPostAndExit(entry3);
goToWorkflow();
updateWorkflowStatus(entry3, workflowStatus.draft, workflowStatus.ready);
updateWorkflowStatus(entry2, workflowStatus.draft, workflowStatus.ready);
updateWorkflowStatus(entry1, workflowStatus.draft, workflowStatus.ready);
publishWorkflowEntry(entry3);
publishWorkflowEntry(entry2);
publishWorkflowEntry(entry1);
goToCollections();
assertPublishedEntry([entry3, entry2, entry1]);
});
it('can delete an entry', () => {
login();
createPost(entry1);
deleteEntryInEditor();
assertOnCollectionsPage();
assertEntryDeleted(entry1);
});
it('can update workflow status from within the editor', () => {
login();
createPost(entry1);
assertWorkflowStatusInEditor(editorStatus.draft);
updateWorkflowStatusInEditor(editorStatus.review);
assertWorkflowStatusInEditor(editorStatus.review);
updateWorkflowStatusInEditor(editorStatus.ready);
assertWorkflowStatusInEditor(editorStatus.ready);
exitEditor();
goToWorkflow();
assertWorkflowStatus(entry1, workflowStatus.ready);
});
it('can unpublish an existing entry', () => {
// first publish an entry
login();
createPostAndExit(entry1);
goToWorkflow();
updateWorkflowStatus(entry1, workflowStatus.draft, workflowStatus.ready);
publishWorkflowEntry(entry1);
// then unpublish it
unpublishEntry(entry1);
});
it('can duplicate an existing entry', () => {
login();
createPost(entry1);
updateWorkflowStatusInEditor(editorStatus.ready);
publishEntryInEditor(publishTypes.publishNow);
duplicateEntry(entry1);
});
it('cannot publish when "publish" is false', () => {
cy.task('updateConfig', { collections: [{ publish: false }] });
login();
createPost(entry1);
cy.contains('span', 'Publish').should('not.exist');
exitEditor();
goToWorkflow();
updateWorkflowStatus(entry1, workflowStatus.draft, workflowStatus.ready);
cy.contains('button', 'Publish new entry').should('not.exist');
});
it('can create a new entry, publish and create new', () => {
login();
createPost(entry1);
updateWorkflowStatusInEditor(editorStatus.ready);
publishAndCreateNewEntryInEditor(entry1);
});
it('can create a new entry, publish and duplicate', () => {
login();
createPost(entry1);
updateWorkflowStatusInEditor(editorStatus.ready);
publishAndDuplicateEntryInEditor(entry1);
});
const inSidebar = func => {
cy.get('[class*=SidebarNavList]').within(func);
};
const inGrid = func => {
cy.get('[class*=CardsGrid]').within(func);
};
it('can access nested collection items', () => {
login();
inSidebar(() => cy.contains('a', 'Pages').click());
inSidebar(() => cy.contains('a', /^Directory$/));
inGrid(() => cy.contains('a', 'Root Page'));
inSidebar(() => cy.contains('a', /^Directory$/).click());
inSidebar(() => cy.contains('a', /^Sub Directory$/));
inSidebar(() => cy.contains('a', 'Another Sub Directory'));
inSidebar(() => cy.contains('a', /^Sub Directory$/).click());
inSidebar(() => cy.contains('a', 'Nested Directory'));
cy.url().should(
'eq',
'http://localhost:8080/#/collections/pages/filter/directory/sub-directory',
);
inSidebar(() => cy.contains('a', 'Pages').click());
inSidebar(() => cy.contains('a', 'Pages').click());
inGrid(() => cy.contains('a', 'Another Sub Directory').should('not.exist'));
});
it('can navigate to nested entry', () => {
login();
inSidebar(() => cy.contains('a', 'Pages').click());
inSidebar(() => cy.contains('a', /^Directory$/).click());
inSidebar(() => cy.contains('a', 'Another Sub Directory').click());
inGrid(() => cy.contains('a', 'Another Sub Directory'));
});
it(`can create a new entry with custom path`, () => {
login();
inSidebar(() => cy.contains('a', 'Pages').click());
inSidebar(() => cy.contains('a', /^Directory$/).click());
inSidebar(() => cy.contains('a', /^Sub Directory$/).click());
cy.contains('a', 'New Page').click();
cy.get('[id^="path-field"]').should('have.value', 'directory/sub-directory');
cy.get('[id^="path-field"]').type('/new-path');
cy.get('[id^="title-field"]').type('New Path Title');
cy.clock().then(clock => {
clock.tick(150);
});
cy.contains('button', 'Save').click();
assertNotification(notifications.saved);
updateWorkflowStatusInEditor(editorStatus.ready);
publishEntryInEditor(publishTypes.publishNow);
exitEditor();
inSidebar(() => cy.contains('a', 'New Path Title'));
inSidebar(() => cy.contains('a', /^Directory$/).click());
inSidebar(() => cy.contains('a', /^Directory$/).click());
inGrid(() => cy.contains('a', 'New Path Title').should('not.exist'));
});
it(`can't create an entry with an existing path`, () => {
login();
inSidebar(() => cy.contains('a', 'Pages').click());
inSidebar(() => cy.contains('a', /^Directory$/).click());
inSidebar(() => cy.contains('a', /^Sub Directory$/).click());
cy.contains('a', 'New Page').click();
cy.get('[id^="title-field"]').type('New Path Title');
cy.clock().then(clock => {
clock.tick(150);
});
cy.contains('button', 'Save').click();
assertFieldValidationError({
message: `Path 'directory/sub-directory' already exists`,
fieldLabel: 'Path',
});
});
it('can move an existing entry to a new path', () => {
login();
inSidebar(() => cy.contains('a', 'Pages').click());
inSidebar(() => cy.contains('a', /^Directory$/).click());
inGrid(() => cy.contains('a', /^Directory$/).click());
cy.get('[id^="path-field"]').should('have.value', 'directory');
cy.get('[id^="path-field"]').clear();
cy.get('[id^="path-field"]').type('new-directory');
cy.get('[id^="title-field"]').clear();
cy.get('[id^="title-field"]').type('New Directory');
cy.clock().then(clock => {
clock.tick(150);
});
cy.contains('button', 'Save').click();
assertNotification(notifications.saved);
updateWorkflowStatusInEditor(editorStatus.ready);
publishEntryInEditor(publishTypes.publishNow);
exitEditor();
inSidebar(() => cy.contains('a', 'New Directory').click());
inSidebar(() => cy.contains('a', /^Sub Directory$/));
inSidebar(() => cy.contains('a', 'Another Sub Directory'));
});
});