fix: duplicate and new entry action (#3003)
* fix: duplicate and new entry action * test(e2e): flush clock when duplicating entry to handle debounced fields Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
This commit is contained in:
parent
e4ba4d9d74
commit
9e7aa0c500
@ -184,22 +184,7 @@ function selectDropdownItem(label, item) {
|
||||
});
|
||||
}
|
||||
|
||||
function populateEntry(entry) {
|
||||
const keys = Object.keys(entry);
|
||||
for (let key of keys) {
|
||||
const value = entry[key];
|
||||
if (key === 'body') {
|
||||
cy.getMarkdownEditor()
|
||||
.click()
|
||||
.clear()
|
||||
.type(value);
|
||||
} else {
|
||||
cy.get(`[id^="${key}-field"]`)
|
||||
.clear()
|
||||
.type(value);
|
||||
}
|
||||
}
|
||||
|
||||
function flushClockAndSave() {
|
||||
cy.clock().then(clock => {
|
||||
// some input fields are de-bounced thus require advancing the clock
|
||||
if (clock) {
|
||||
@ -218,6 +203,25 @@ function populateEntry(entry) {
|
||||
});
|
||||
}
|
||||
|
||||
function populateEntry(entry) {
|
||||
const keys = Object.keys(entry);
|
||||
for (let key of keys) {
|
||||
const value = entry[key];
|
||||
if (key === 'body') {
|
||||
cy.getMarkdownEditor()
|
||||
.click()
|
||||
.clear()
|
||||
.type(value);
|
||||
} else {
|
||||
cy.get(`[id^="${key}-field"]`)
|
||||
.clear()
|
||||
.type(value);
|
||||
}
|
||||
}
|
||||
|
||||
flushClockAndSave();
|
||||
}
|
||||
|
||||
function newPost() {
|
||||
cy.contains('a', 'New Post').click();
|
||||
}
|
||||
@ -257,7 +261,7 @@ function unpublishEntry(entry) {
|
||||
function duplicateEntry(entry) {
|
||||
selectDropdownItem('Published', 'Duplicate');
|
||||
cy.url().should('contain', '/#/collections/posts/new');
|
||||
cy.contains('button', 'Save').click();
|
||||
flushClockAndSave();
|
||||
updateWorkflowStatusInEditor(editorStatus.ready);
|
||||
publishEntryInEditor(publishTypes.publishNow);
|
||||
exitEditor();
|
||||
|
@ -529,7 +529,7 @@ export function publishUnpublishedEntry(collection: string, slug: string) {
|
||||
);
|
||||
|
||||
dispatch(unpublishedEntryPublished(collection, slug, transactionID));
|
||||
dispatch(loadEntry(collections.get(collection), slug));
|
||||
return dispatch(loadEntry(collections.get(collection), slug));
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
dispatch(
|
||||
|
@ -24,6 +24,7 @@ import {
|
||||
import { ThunkDispatch } from 'redux-thunk';
|
||||
import { AnyAction, Dispatch } from 'redux';
|
||||
import { waitForMediaLibraryToLoad } from './mediaLibrary';
|
||||
import { waitUntil } from './waitUntil';
|
||||
|
||||
const { notifSend } = notifActions;
|
||||
|
||||
@ -215,7 +216,7 @@ export function createDraftFromEntry(entry: EntryMap, metadata?: Map<string, unk
|
||||
};
|
||||
}
|
||||
|
||||
export function createDraftDuplicateFromEntry(entry: EntryMap) {
|
||||
export function draftDuplicateEntry(entry: EntryMap) {
|
||||
return {
|
||||
type: DRAFT_CREATE_DUPLICATE_FROM_ENTRY,
|
||||
payload: createEntry(entry.get('collection'), '', '', { data: entry.get('data') }),
|
||||
@ -277,6 +278,17 @@ export function persistLocalBackup(entry: EntryMap, collection: Collection) {
|
||||
};
|
||||
}
|
||||
|
||||
export function createDraftDuplicateFromEntry(entry: EntryMap) {
|
||||
return (dispatch: ThunkDispatch<State, {}, AnyAction>) => {
|
||||
dispatch(
|
||||
waitUntil({
|
||||
predicate: ({ type }) => type === DRAFT_CREATE_EMPTY,
|
||||
run: () => dispatch(draftDuplicateEntry(entry)),
|
||||
}),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function retrieveLocalBackup(collection: Collection, slug: string) {
|
||||
return async (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => {
|
||||
const state = getState();
|
||||
|
@ -318,10 +318,10 @@ export class Editor extends React.Component {
|
||||
return navigateToCollection(collection.get('name'));
|
||||
};
|
||||
|
||||
handleDuplicateEntry = async () => {
|
||||
handleDuplicateEntry = () => {
|
||||
const { createDraftDuplicateFromEntry, collection, entryDraft } = this.props;
|
||||
|
||||
await navigateToNewEntry(collection.get('name'));
|
||||
navigateToNewEntry(collection.get('name'));
|
||||
createDraftDuplicateFromEntry(entryDraft.get('entry'));
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user