Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge a74775b into 534a8dd
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Aug 9, 2019
2 parents 534a8dd + a74775b commit 5c8236a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/undoui.js
Expand Up @@ -24,10 +24,14 @@ export default class UndoUI extends Plugin {
*/
init() {
const editor = this.editor;
const locale = editor.locale;
const t = editor.t;

this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z', undoIcon );
this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y', redoIcon );
const localizedUndoIcon = locale.uiLanguageDirection == 'ltr' ? undoIcon : redoIcon;
const localizedRedoIcon = locale.uiLanguageDirection == 'ltr' ? redoIcon : undoIcon;

this._addButton( 'undo', t( 'Undo' ), 'CTRL+Z', localizedUndoIcon );
this._addButton( 'redo', t( 'Redo' ), 'CTRL+Y', localizedRedoIcon );
}

/**
Expand Down
63 changes: 63 additions & 0 deletions tests/undoui.js
Expand Up @@ -11,6 +11,9 @@ import UndoUI from '../src/undoui';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

import undoIcon from '../theme/icons/undo.svg';
import redoIcon from '../theme/icons/redo.svg';

describe( 'UndoUI', () => {
let editor, editorElement;

Expand All @@ -35,6 +38,66 @@ describe( 'UndoUI', () => {
testButton( 'undo', 'Undo', 'CTRL+Z' );
testButton( 'redo', 'Redo', 'CTRL+Y' );

describe( 'icons', () => {
describe( 'left–to–right UI', () => {
it( 'should display the right icon for undo', () => {
const undoButton = editor.ui.componentFactory.create( 'undo' );

expect( undoButton.icon ).to.equal( undoIcon );
} );

it( 'should display the right icon for redo', () => {
const redoButton = editor.ui.componentFactory.create( 'redo' );

expect( redoButton.icon ).to.equal( redoIcon );
} );
} );

describe( 'right–to–left UI', () => {
it( 'should display the right icon for undo', () => {
const element = document.createElement( 'div' );
document.body.appendChild( element );

return ClassicTestEditor
.create( element, {
plugins: [ UndoEditing, UndoUI ],
language: 'ar'
} )
.then( newEditor => {
const undoButton = newEditor.ui.componentFactory.create( 'undo' );

expect( undoButton.icon ).to.equal( redoIcon );

return newEditor.destroy();
} )
.then( () => {
element.remove();
} );
} );

it( 'should display the right icon for redo', () => {
const element = document.createElement( 'div' );
document.body.appendChild( element );

return ClassicTestEditor
.create( element, {
plugins: [ UndoEditing, UndoUI ],
language: 'ar'
} )
.then( newEditor => {
const redoButton = newEditor.ui.componentFactory.create( 'redo' );

expect( redoButton.icon ).to.equal( undoIcon );

return newEditor.destroy();
} )
.then( () => {
element.remove();
} );
} );
} );
} );

function testButton( featureName, label, featureKeystroke ) {
describe( `${ featureName } button`, () => {
let button;
Expand Down

0 comments on commit 5c8236a

Please sign in to comment.