| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- import Model from '../../src/model/model';
- describe( 'Model', () => {
- let model;
- let changes = '';
- beforeEach( () => {
- model = new Model();
- changes = '';
- } );
- describe( 'change & enqueueChange', () => {
- it( 'should execute changes immediately', () => {
- model.change( () => {
- changes += 'A';
- } );
- expect( changes ).to.equal( 'A' );
- } );
- it( 'should pass returned value', () => {
- const ret = model.change( () => {
- changes += 'A';
- return 'B';
- } );
- changes += ret;
- expect( changes ).to.equal( 'AB' );
- } );
- it( 'should not mixed the order when nested change is called', () => {
- const ret = model.change( () => {
- changes += 'A';
- nested();
- return 'D';
- } );
- changes += ret;
- expect( changes ).to.equal( 'ABCD' );
- function nested() {
- const ret = model.change( () => {
- changes += 'B';
- return 'C';
- } );
- changes += ret;
- }
- } );
- it( 'should execute enqueueChanges immediately if its the first block', () => {
- model.enqueueChange( () => {
- changes += 'A';
- nested();
- } );
- expect( changes ).to.equal( 'ABC' );
- function nested() {
- const ret = model.change( () => {
- changes += 'B';
- return 'C';
- } );
- changes += ret;
- }
- } );
- it( 'should be possible to enqueueChanges immediately if its the first block', () => {
- model.enqueueChange( () => {
- changes += 'A';
- nested();
- } );
- expect( changes ).to.equal( 'AB' );
- function nested() {
- model.change( () => {
- changes += 'B';
- } );
- }
- } );
- it( 'should be possible to nest change in enqueueChanges', () => {
- model.enqueueChange( () => {
- changes += 'A';
- nested();
- changes += 'D';
- } );
- expect( changes ).to.equal( 'ABCD' );
- function nested() {
- const ret = model.change( () => {
- changes += 'B';
- return 'C';
- } );
- changes += ret;
- }
- } );
- it( 'should be possible to nest enqueueChanges in enqueueChanges', () => {
- model.enqueueChange( () => {
- changes += 'A';
- nestedEnqueue();
- changes += 'B';
- } );
- expect( changes ).to.equal( 'ABC' );
- function nestedEnqueue() {
- model.enqueueChange( () => {
- changes += 'C';
- } );
- }
- } );
- it( 'should be possible to nest enqueueChanges in changes', () => {
- const ret = model.change( () => {
- changes += 'A';
- nestedEnqueue();
- changes += 'B';
- return 'D';
- } );
- changes += ret;
- expect( changes ).to.equal( 'ABCD' );
- function nestedEnqueue() {
- model.enqueueChange( () => {
- changes += 'C';
- } );
- }
- } );
- } );
- } );
|