This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: Improved serialization of WrapOperation.
- Loading branch information
1 parent
6c1f87e
commit e52bffb
Showing
2 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import Model from '../../../src/model/model'; | ||
import Element from '../../../src/model/element'; | ||
import WrapOperation from '../../../src/model/operation/wrapoperation'; | ||
import Position from '../../../src/model/position'; | ||
|
||
describe( 'WrapOperation', () => { | ||
let model, doc, root; | ||
|
||
beforeEach( () => { | ||
model = new Model(); | ||
doc = model.document; | ||
root = doc.createRoot(); | ||
} ); | ||
|
||
describe( 'type', () => { | ||
it( 'should be wrap', () => { | ||
const op = new WrapOperation( | ||
new Position( root, [ 0 ] ), | ||
1, | ||
new Position( doc.graveyard, [ 0 ] ), | ||
doc.version | ||
); | ||
|
||
expect( op.type ).to.equal( 'wrap' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'toJSON', () => { | ||
it( 'should create proper serialized object #1', () => { | ||
const op = new WrapOperation( | ||
new Position( root, [ 0 ] ), | ||
1, | ||
new Position( doc.graveyard, [ 0 ] ), | ||
doc.version | ||
); | ||
|
||
const serialized = op.toJSON(); | ||
|
||
expect( serialized ).to.deep.equal( { | ||
__className: 'engine.model.operation.WrapOperation', | ||
baseVersion: 0, | ||
position: op.position.toJSON(), | ||
graveyardPosition: op.graveyardPosition.toJSON(), | ||
howMany: 1 | ||
} ); | ||
} ); | ||
|
||
it( 'should create proper serialized object #2', () => { | ||
const op = new WrapOperation( | ||
new Position( root, [ 0 ] ), | ||
1, | ||
new Element( 'paragraph' ), | ||
doc.version | ||
); | ||
|
||
const serialized = op.toJSON(); | ||
|
||
expect( serialized ).to.deep.equal( { | ||
__className: 'engine.model.operation.WrapOperation', | ||
baseVersion: 0, | ||
position: op.position.toJSON(), | ||
element: op.element.toJSON(), | ||
howMany: 1 | ||
} ); | ||
} ); | ||
} ); | ||
|
||
describe( 'fromJSON', () => { | ||
it( 'should create proper WrapOperation from json object', () => { | ||
const op = new WrapOperation( | ||
new Position( root, [ 0 ] ), | ||
1, | ||
new Position( doc.graveyard, [ 0 ] ), | ||
doc.version | ||
); | ||
|
||
const serialized = op.toJSON(); | ||
const deserialized = WrapOperation.fromJSON( serialized, doc ); | ||
|
||
expect( deserialized ).to.deep.equal( op ); | ||
} ); | ||
} ); | ||
} ); |