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

Commit

Permalink
Tests: Corrected tests connected with checking if changes are done in…
Browse files Browse the repository at this point in the history
… enqueueChanges call.
  • Loading branch information
scofalik committed Aug 22, 2017
1 parent df1711a commit cf3ca86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
11 changes: 8 additions & 3 deletions tests/deletecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ describe( 'DeleteCommand', () => {
it( 'uses enqueueChanges', () => {
setData( doc, '<p>foo[]bar</p>' );

const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );
doc.enqueueChanges( () => {
editor.execute( 'delete' );

editor.execute( 'delete' );
// We expect that command is executed in enqueue changes block. Since we are already in
// an enqueued block, the command execution will be postponed. Hence, no changes.
expect( getData( doc ) ).to.equal( '<p>foo[]bar</p>' );
} );

expect( spy.calledOnce ).to.be.true;
// After all enqueued changes are done, the command execution is reflected.
expect( getData( doc ) ).to.equal( '<p>fo[]bar</p>' );
} );

it( 'locks buffer when executing', () => {
Expand Down
26 changes: 10 additions & 16 deletions tests/inputcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe( 'InputCommand', () => {

testUtils.createSinonSandbox();

before( () => {
beforeEach( () => {
return ModelTestEditor.create()
.then( newEditor => {
editor = newEditor;
Expand All @@ -28,20 +28,17 @@ describe( 'InputCommand', () => {
editor.commands.add( 'input', inputCommand );

buffer = inputCommand.buffer;
buffer.size = 0;

doc.schema.registerItem( 'p', '$block' );
doc.schema.registerItem( 'h1', '$block' );
} );
} );

after( () => {
afterEach( () => {
return editor.destroy();
} );

beforeEach( () => {
buffer.size = 0;
} );

describe( 'buffer', () => {
it( 'has buffer getter', () => {
expect( editor.commands.get( 'input' ).buffer ).to.be.an.instanceof( ChangeBuffer );
Expand Down Expand Up @@ -69,13 +66,16 @@ describe( 'InputCommand', () => {
it( 'uses enqueueChanges', () => {
setData( doc, '<p>foo[]bar</p>' );

const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );
doc.enqueueChanges( () => {
editor.execute( 'input', { text: 'x' } );

editor.execute( 'input', {
text: ''
// We expect that command is executed in enqueue changes block. Since we are already in
// an enqueued block, the command execution will be postponed. Hence, no changes.
expect( getData( doc ) ).to.be.equal( '<p>foo[]bar</p>' );
} );

expect( spy.calledOnce ).to.be.true;
// After all enqueued changes are done, the command execution is reflected.
expect( getData( doc ) ).to.be.equal( '<p>foox[]bar</p>' );
} );

it( 'should lock and unlock buffer', () => {
Expand Down Expand Up @@ -202,23 +202,17 @@ describe( 'InputCommand', () => {
it( 'only removes content when no text given (with default non-collapsed range)', () => {
setData( doc, '<p>[fo]obar</p>' );

const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );

editor.execute( 'input' );

expect( spy.callCount ).to.be.equal( 1 );
expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>[]obar</p>' );
expect( buffer.size ).to.be.equal( 0 );
} );

it( 'does not change selection and content when no text given (with default collapsed range)', () => {
setData( doc, '<p>fo[]obar</p>' );

const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );

editor.execute( 'input' );

expect( spy.callCount ).to.be.equal( 1 );
expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>fo[]obar</p>' );
expect( buffer.size ).to.be.equal( 0 );
} );
Expand Down

0 comments on commit cf3ca86

Please sign in to comment.