From 66581ebd89fe882507f920b298bda96b0eae9996 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 3 Jul 2018 13:18:25 -0400 Subject: [PATCH] Rich Text: Remove createUndoLevel for split, merge (#7650) * History: Update redo button class name Already referenced as such in e2e/specs/hello.test.js * Testing: Add basic E2E tests for undo behavior * Rich Text: Remove createUndoLevel for split, merge --- editor/components/editor-history/redo.js | 2 +- editor/components/rich-text/index.js | 4 --- test/e2e/specs/undo.test.js | 40 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 test/e2e/specs/undo.test.js diff --git a/editor/components/editor-history/redo.js b/editor/components/editor-history/redo.js index 64457a35968ff..9bfe2ab756f3a 100644 --- a/editor/components/editor-history/redo.js +++ b/editor/components/editor-history/redo.js @@ -15,7 +15,7 @@ function EditorHistoryRedo( { hasRedo, redo } ) { shortcut={ displayShortcut.primaryShift( 'z' ) } disabled={ ! hasRedo } onClick={ redo } - className="editor-history__undo" + className="editor-history__redo" /> ); } diff --git a/editor/components/rich-text/index.js b/editor/components/rich-text/index.js index e8b2ef08096f6..62ccd90bd9229 100644 --- a/editor/components/rich-text/index.js +++ b/editor/components/rich-text/index.js @@ -513,8 +513,6 @@ export class RichText extends Component { return; } - this.onCreateUndoLevel(); - const forward = keyCode === DELETE; if ( this.props.onMerge ) { @@ -557,7 +555,6 @@ export class RichText extends Component { } event.preventDefault(); - this.onCreateUndoLevel(); const childNodes = Array.from( rootNode.childNodes ); const index = dom.nodeIndex( selectedNode ); @@ -571,7 +568,6 @@ export class RichText extends Component { this.restoreContentAndSplit( before, after ); } else { event.preventDefault(); - this.onCreateUndoLevel(); if ( event.shiftKey || ! this.props.onSplit ) { this.editor.execCommand( 'InsertLineBreak', false, event ); diff --git a/test/e2e/specs/undo.test.js b/test/e2e/specs/undo.test.js new file mode 100644 index 0000000000000..3f6e665e0045b --- /dev/null +++ b/test/e2e/specs/undo.test.js @@ -0,0 +1,40 @@ +/** + * Internal dependencies + */ +import '../support/bootstrap'; +import { + newPost, + newDesktopBrowserPage, + pressWithModifier, + getHTMLFromCodeEditor, +} from '../support/utils'; + +describe( 'undo', () => { + beforeAll( async () => { + await newDesktopBrowserPage(); + await newPost(); + } ); + + it( 'Should undo to expected level intervals', async () => { + await page.click( '.editor-default-block-appender' ); + + await page.keyboard.type( 'This' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( 'is' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( 'test' ); + + await pressWithModifier( 'mod', 'z' ); // Strip 3rd paragraph text + await pressWithModifier( 'mod', 'z' ); // Strip 3rd paragraph block + await pressWithModifier( 'mod', 'z' ); // Strip 2nd paragraph text + await pressWithModifier( 'mod', 'z' ); // Strip 2nd paragraph block + await pressWithModifier( 'mod', 'z' ); // Strip 1st paragraph text + await pressWithModifier( 'mod', 'z' ); // Strip 1st paragraph block + + expect( await getHTMLFromCodeEditor() ).toBe( '' ); + + // Should have no more history. + const undoButton = await page.$( '.editor-history__undo:not( :disabled )' ); + expect( undoButton ).toBeNull(); + } ); +} );