Test: add editor test coverage (#3598)
This commit is contained in:
@ -2,7 +2,7 @@ const workflowStatus = { draft: 'Drafts', review: 'In Review', ready: 'Ready' };
|
||||
const editorStatus = { draft: 'Draft', review: 'In review', ready: 'Ready' };
|
||||
const setting1 = { limit: 10, author: 'John Doe' };
|
||||
const setting2 = { name: 'Jane Doe', description: 'description' };
|
||||
const publishTypes = { publishNow: 'Publish now' };
|
||||
const publishTypes = { publishNow: 'Publish now', publishAndCreateNew: 'Publish and create new', publishAndDuplicate: 'Publish and duplicate' };
|
||||
const notifications = {
|
||||
saved: 'Entry saved',
|
||||
published: 'Entry published',
|
||||
|
@ -169,6 +169,20 @@ function publishEntryInEditor(publishType) {
|
||||
assertNotification(notifications.published);
|
||||
}
|
||||
|
||||
function publishAndCreateNewEntryInEditor() {
|
||||
selectDropdownItem('Publish', publishTypes.publishAndCreateNew);
|
||||
assertNotification(notifications.published);
|
||||
cy.url().should('eq', `http://localhost:8080/#/collections/posts/new`);
|
||||
cy.get('[id^="title-field"]').should('have.value', '');
|
||||
}
|
||||
|
||||
function publishAndDuplicateEntryInEditor(entry) {
|
||||
selectDropdownItem('Publish', publishTypes.publishAndDuplicate);
|
||||
assertNotification(notifications.published);
|
||||
cy.url().should('eq', `http://localhost:8080/#/collections/posts/new`);
|
||||
cy.get('[id^="title-field"]').should('have.value', entry.title);
|
||||
}
|
||||
|
||||
function selectDropdownItem(label, item) {
|
||||
cy.contains('[role="button"]', label).as('dropDownButton');
|
||||
cy.get('@dropDownButton')
|
||||
@ -205,12 +219,11 @@ function populateEntry(entry, onDone = flushClockAndSave) {
|
||||
if (key === 'body') {
|
||||
cy.getMarkdownEditor()
|
||||
.click()
|
||||
.clear()
|
||||
.type(value);
|
||||
.clear({ force: true })
|
||||
.type(value, { force: true });
|
||||
} else {
|
||||
cy.get(`[id^="${key}-field"]`)
|
||||
.clear()
|
||||
.type(value);
|
||||
cy.get(`[id^="${key}-field"]`).clear({ force: true });
|
||||
cy.get(`[id^="${key}-field"]`).type(value, { force: true });
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,7 +244,7 @@ function createPostAndExit(entry) {
|
||||
exitEditor();
|
||||
}
|
||||
|
||||
function publishEntry() {
|
||||
function publishEntry({ createNew = false, duplicate = false } = {}) {
|
||||
cy.clock().then(clock => {
|
||||
// some input fields are de-bounced thus require advancing the clock
|
||||
if (clock) {
|
||||
@ -242,23 +255,91 @@ function publishEntry() {
|
||||
cy.wait(500);
|
||||
}
|
||||
|
||||
cy.contains('[role="button"]', 'Publish').as('publishButton');
|
||||
cy.get('@publishButton')
|
||||
.parent()
|
||||
.within(() => {
|
||||
cy.get('@publishButton').click();
|
||||
cy.contains('[role="menuitem"] span', 'Publish now').click();
|
||||
});
|
||||
if (createNew) {
|
||||
selectDropdownItem('Publish', publishTypes.publishAndCreateNew);
|
||||
} else if (duplicate) {
|
||||
selectDropdownItem('Publish', publishTypes.publishAndDuplicate);
|
||||
} else {
|
||||
selectDropdownItem('Publish', publishTypes.publishNow);
|
||||
}
|
||||
|
||||
assertNotification(notifications.saved);
|
||||
});
|
||||
}
|
||||
|
||||
function createPostAndPublish(entry) {
|
||||
cy.contains('a', 'New Post').click();
|
||||
newPost();
|
||||
populateEntry(entry, publishEntry);
|
||||
exitEditor();
|
||||
}
|
||||
|
||||
function createPostPublishAndCreateNew(entry) {
|
||||
newPost();
|
||||
populateEntry(entry, () => publishEntry({ createNew: true }));
|
||||
cy.url().should('eq', `http://localhost:8080/#/collections/posts/new`);
|
||||
cy.get('[id^="title-field"]').should('have.value', '');
|
||||
|
||||
exitEditor();
|
||||
}
|
||||
|
||||
function createPostPublishAndDuplicate(entry) {
|
||||
newPost();
|
||||
populateEntry(entry, () => publishEntry({ duplicate: true }));
|
||||
cy.url().should('eq', `http://localhost:8080/#/collections/posts/new`);
|
||||
cy.get('[id^="title-field"]').should('have.value', entry.title);
|
||||
|
||||
exitEditor();
|
||||
}
|
||||
|
||||
function editPostAndPublish(entry1, entry2) {
|
||||
goToEntry(entry1);
|
||||
cy.contains('button', 'Delete entry');
|
||||
cy.contains('span', 'Published');
|
||||
|
||||
populateEntry(entry2, publishEntry);
|
||||
// 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/, '-')}`,
|
||||
);
|
||||
}
|
||||
|
||||
function editPostPublishAndCreateNew(entry1, entry2) {
|
||||
goToEntry(entry1);
|
||||
cy.contains('button', 'Delete entry');
|
||||
cy.contains('span', 'Published');
|
||||
|
||||
populateEntry(entry2, () => publishEntry({ createNew: true }));
|
||||
cy.url().should('eq', `http://localhost:8080/#/collections/posts/new`);
|
||||
cy.get('[id^="title-field"]').should('have.value', '');
|
||||
}
|
||||
|
||||
function editPostPublishAndDuplicate(entry1, entry2) {
|
||||
goToEntry(entry1);
|
||||
cy.contains('button', 'Delete entry');
|
||||
cy.contains('span', 'Published');
|
||||
|
||||
populateEntry(entry2, () => publishEntry({ duplicate: true }));
|
||||
cy.url().should('eq', `http://localhost:8080/#/collections/posts/new`);
|
||||
cy.get('[id^="title-field"]').should('have.value', entry2.title);
|
||||
}
|
||||
|
||||
function duplicatePostAndPublish(entry1) {
|
||||
goToEntry(entry1);
|
||||
cy.contains('button', 'Delete entry');
|
||||
selectDropdownItem('Published', 'Duplicate');
|
||||
publishEntry();
|
||||
|
||||
cy.url().should(
|
||||
'eq',
|
||||
`http://localhost:8080/#/collections/posts/entries/1970-01-01-${entry1.title
|
||||
.toLowerCase()
|
||||
.replace(/\s/, '-')}-1`,
|
||||
);
|
||||
}
|
||||
|
||||
function updateExistingPostAndExit(fromEntry, toEntry) {
|
||||
goToWorkflow();
|
||||
cy.contains('h2', fromEntry.title)
|
||||
@ -393,4 +474,13 @@ module.exports = {
|
||||
newPost,
|
||||
populateEntry,
|
||||
goToEntry,
|
||||
publishEntry,
|
||||
createPostPublishAndCreateNew,
|
||||
createPostPublishAndDuplicate,
|
||||
editPostAndPublish,
|
||||
editPostPublishAndCreateNew,
|
||||
editPostPublishAndDuplicate,
|
||||
duplicatePostAndPublish,
|
||||
publishAndCreateNewEntryInEditor,
|
||||
publishAndDuplicateEntryInEditor,
|
||||
};
|
||||
|
Reference in New Issue
Block a user