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) {
|
function flushClockAndSave() {
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cy.clock().then(clock => {
|
cy.clock().then(clock => {
|
||||||
// some input fields are de-bounced thus require advancing the clock
|
// some input fields are de-bounced thus require advancing the clock
|
||||||
if (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() {
|
function newPost() {
|
||||||
cy.contains('a', 'New Post').click();
|
cy.contains('a', 'New Post').click();
|
||||||
}
|
}
|
||||||
@ -257,7 +261,7 @@ function unpublishEntry(entry) {
|
|||||||
function duplicateEntry(entry) {
|
function duplicateEntry(entry) {
|
||||||
selectDropdownItem('Published', 'Duplicate');
|
selectDropdownItem('Published', 'Duplicate');
|
||||||
cy.url().should('contain', '/#/collections/posts/new');
|
cy.url().should('contain', '/#/collections/posts/new');
|
||||||
cy.contains('button', 'Save').click();
|
flushClockAndSave();
|
||||||
updateWorkflowStatusInEditor(editorStatus.ready);
|
updateWorkflowStatusInEditor(editorStatus.ready);
|
||||||
publishEntryInEditor(publishTypes.publishNow);
|
publishEntryInEditor(publishTypes.publishNow);
|
||||||
exitEditor();
|
exitEditor();
|
||||||
|
@ -529,7 +529,7 @@ export function publishUnpublishedEntry(collection: string, slug: string) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
dispatch(unpublishedEntryPublished(collection, slug, transactionID));
|
dispatch(unpublishedEntryPublished(collection, slug, transactionID));
|
||||||
dispatch(loadEntry(collections.get(collection), slug));
|
return dispatch(loadEntry(collections.get(collection), slug));
|
||||||
})
|
})
|
||||||
.catch((error: Error) => {
|
.catch((error: Error) => {
|
||||||
dispatch(
|
dispatch(
|
||||||
|
@ -24,6 +24,7 @@ import {
|
|||||||
import { ThunkDispatch } from 'redux-thunk';
|
import { ThunkDispatch } from 'redux-thunk';
|
||||||
import { AnyAction, Dispatch } from 'redux';
|
import { AnyAction, Dispatch } from 'redux';
|
||||||
import { waitForMediaLibraryToLoad } from './mediaLibrary';
|
import { waitForMediaLibraryToLoad } from './mediaLibrary';
|
||||||
|
import { waitUntil } from './waitUntil';
|
||||||
|
|
||||||
const { notifSend } = notifActions;
|
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 {
|
return {
|
||||||
type: DRAFT_CREATE_DUPLICATE_FROM_ENTRY,
|
type: DRAFT_CREATE_DUPLICATE_FROM_ENTRY,
|
||||||
payload: createEntry(entry.get('collection'), '', '', { data: entry.get('data') }),
|
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) {
|
export function retrieveLocalBackup(collection: Collection, slug: string) {
|
||||||
return async (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => {
|
return async (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
@ -318,10 +318,10 @@ export class Editor extends React.Component {
|
|||||||
return navigateToCollection(collection.get('name'));
|
return navigateToCollection(collection.get('name'));
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDuplicateEntry = async () => {
|
handleDuplicateEntry = () => {
|
||||||
const { createDraftDuplicateFromEntry, collection, entryDraft } = this.props;
|
const { createDraftDuplicateFromEntry, collection, entryDraft } = this.props;
|
||||||
|
|
||||||
await navigateToNewEntry(collection.get('name'));
|
navigateToNewEntry(collection.get('name'));
|
||||||
createDraftDuplicateFromEntry(entryDraft.get('entry'));
|
createDraftDuplicateFromEntry(entryDraft.get('entry'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user