Test: add editor test coverage (#3598)

This commit is contained in:
Erez Rokah
2020-04-14 11:18:48 +03:00
committed by GitHub
parent 36ae69c96e
commit 166b070cb1
8 changed files with 288 additions and 73 deletions

View File

@ -21,9 +21,12 @@ import {
unpublishEntry,
publishEntryInEditor,
duplicateEntry,
goToEntry,
populateEntry,
publishAndCreateNewEntryInEditor,
publishAndDuplicateEntryInEditor,
} from '../utils/steps';
import { setting1, setting2, workflowStatus, editorStatus, publishTypes } from '../utils/constants';
import { fromJS } from 'immutable';
const entry1 = {
title: 'first title',
@ -54,7 +57,17 @@ describe('Test Backend Editorial Workflow', () => {
it('can create an entry', () => {
login();
createPostAndExit(entry1);
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 validate object fields', () => {
@ -80,6 +93,27 @@ describe('Test Backend Editorial Workflow', () => {
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);
@ -148,58 +182,8 @@ describe('Test Backend Editorial Workflow', () => {
});
it('cannot publish when "publish" is false', () => {
cy.visit('/', {
onBeforeLoad: window => {
window.CMS_MANUAL_INIT = true;
},
onLoad: window => {
window.CMS.init({
config: fromJS({
backend: {
name: 'test-repo',
},
publish_mode: 'editorial_workflow',
load_config_file: false,
media_folder: 'assets/uploads',
collections: [
{
label: 'Posts',
name: 'post',
folder: '_posts',
label_singular: 'Post',
create: true,
publish: false,
fields: [
{ label: 'Title', name: 'title', widget: 'string', tagname: 'h1' },
{
label: 'Publish Date',
name: 'date',
widget: 'datetime',
dateFormat: 'YYYY-MM-DD',
timeFormat: 'HH:mm',
format: 'YYYY-MM-DD HH:mm',
},
{
label: 'Cover Image',
name: 'image',
widget: 'image',
required: false,
tagname: '',
},
{
label: 'Body',
name: 'body',
widget: 'markdown',
hint: 'Main content goes here.',
},
],
},
],
}),
});
},
});
cy.contains('button', 'Login').click();
cy.task('updateConfig', { collections: [{ publish: false }] });
login();
createPost(entry1);
cy.contains('span', 'Publish').should('not.exist');
exitEditor();
@ -207,4 +191,19 @@ describe('Test Backend Editorial Workflow', () => {
updateWorkflowStatus(entry1, workflowStatus.draft, workflowStatus.ready);
cy.contains('button', 'Publish new entry').should('not.exist');
});
it.only('can create a new entry, publish and create new', () => {
login();
createPost(entry1);
updateWorkflowStatusInEditor(editorStatus.ready);
publishAndCreateNewEntryInEditor(entry1);
});
it.only('can create a new entry, publish and duplicate', () => {
login();
createPost(entry1);
updateWorkflowStatusInEditor(editorStatus.ready);
publishAndDuplicateEntryInEditor(entry1);
});
});

View File

@ -0,0 +1,101 @@
import {
login,
newPost,
populateEntry,
exitEditor,
createPostAndPublish,
assertPublishedEntry,
editPostAndPublish,
createPostPublishAndCreateNew,
createPostPublishAndDuplicate,
editPostPublishAndCreateNew,
editPostPublishAndDuplicate,
duplicatePostAndPublish,
} from '../utils/steps';
const entry1 = {
title: 'first title',
body: 'first body',
};
const entry2 = {
title: 'second title',
body: 'second body',
};
const backend = 'test';
describe('Test Backend Simple Workflow', () => {
before(() => {
Cypress.config('defaultCommandTimeout', 4000);
cy.task('setupBackend', { backend, options: { publish_mode: 'simple' } });
});
after(() => {
cy.task('teardownBackend', { backend });
});
it('successfully loads', () => {
login();
});
it('can create a new entry', () => {
login();
newPost();
populateEntry(entry1, () => {});
// new entry should show 'Unsaved changes'
cy.contains('div', 'Unsaved Changes');
cy.url().should('eq', `http://localhost:8080/#/collections/posts/new`);
exitEditor();
});
it('can publish a new entry', () => {
login();
createPostAndPublish(entry1);
assertPublishedEntry(entry1);
});
it('can publish a new entry and create new', () => {
login();
createPostPublishAndCreateNew(entry1);
assertPublishedEntry(entry1);
});
it('can publish a new entry and duplicate', () => {
login();
createPostPublishAndDuplicate(entry1);
assertPublishedEntry(entry1);
});
it('can edit an existing entry and publish', () => {
login();
createPostAndPublish(entry1);
assertPublishedEntry(entry1);
editPostAndPublish(entry1, entry2);
});
it('can edit an existing entry, publish and create new', () => {
login();
createPostAndPublish(entry1);
assertPublishedEntry(entry1);
editPostPublishAndCreateNew(entry1, entry2);
});
it('can edit an existing entry, publish and duplicate', () => {
login();
createPostAndPublish(entry1);
assertPublishedEntry(entry1);
editPostPublishAndDuplicate(entry1, entry2);
});
it('can duplicate an existing entry', () => {
login();
createPostAndPublish(entry1);
assertPublishedEntry(entry1);
duplicatePostAndPublish(entry1);
});
});