Skip to content

Commit

Permalink
Rich Text: Remove createUndoLevel for split, merge (#7650)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aduth authored Jul 3, 2018
1 parent 73b1f33 commit 66581eb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion editor/components/editor-history/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function EditorHistoryRedo( { hasRedo, redo } ) {
shortcut={ displayShortcut.primaryShift( 'z' ) }
disabled={ ! hasRedo }
onClick={ redo }
className="editor-history__undo"
className="editor-history__redo"
/>
);
}
Expand Down
4 changes: 0 additions & 4 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,6 @@ export class RichText extends Component {
return;
}

this.onCreateUndoLevel();

const forward = keyCode === DELETE;

if ( this.props.onMerge ) {
Expand Down Expand Up @@ -557,7 +555,6 @@ export class RichText extends Component {
}

event.preventDefault();
this.onCreateUndoLevel();

const childNodes = Array.from( rootNode.childNodes );
const index = dom.nodeIndex( selectedNode );
Expand All @@ -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 );
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/specs/undo.test.js
Original file line number Diff line number Diff line change
@@ -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();
} );
} );

0 comments on commit 66581eb

Please sign in to comment.