forked from ottypes/rich-text
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from reedsy/serialize-config
✨ Allow configuration of serialized fields
- Loading branch information
Showing
5 changed files
with
89 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
serializedProperties: { | ||
metadata: true, | ||
}, | ||
}; |
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
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,66 @@ | ||
var richText = require('../lib/type').type; | ||
var expect = require('chai').expect; | ||
var sinon = require('sinon'); | ||
const config = require('../lib/config'); | ||
|
||
describe('config', function() { | ||
describe('serialization', function() { | ||
it('serializes metadata by default', function() { | ||
var delta = richText.create(); | ||
delta.metadata = {foo: '123'}; | ||
expect(richText.serialize(delta)).to.eql({ | ||
ops: [], | ||
metadata: {foo: '123'}, | ||
}); | ||
}); | ||
|
||
it('deserializes metadata by default', function() { | ||
var delta = richText.deserialize({ | ||
ops: [], | ||
metadata: {lorem: 'ipsum'}, | ||
}); | ||
|
||
expect(delta.metadata).to.eql({lorem: 'ipsum'}); | ||
}); | ||
|
||
it('does not serialize an unspecified prop', function() { | ||
var delta = richText.create(); | ||
delta.$doNotSerialize = {foo: '123'}; | ||
expect(richText.serialize(delta)).to.eql({ | ||
ops: [], | ||
metadata: undefined, | ||
}); | ||
}); | ||
|
||
it('does not deserialize an unspecified prop', function () { | ||
var delta = richText.deserialize({ | ||
ops: [], | ||
$doNotSerialize: {lorem: 'ipsum'}, | ||
}); | ||
|
||
expect(delta).not.to.have.property('$doNotSerialize'); | ||
}); | ||
|
||
it('can specify extra props to serialize using config', function() { | ||
sinon.stub(config, 'serializedProperties').get(() => ({extra: true})); | ||
|
||
var delta = richText.create(); | ||
delta.extra = {foo: '123'}; | ||
expect(richText.serialize(delta)).to.eql({ | ||
ops: [], | ||
extra: {foo: '123'}, | ||
}); | ||
}); | ||
|
||
it('can specify extra props to deserialize using config', function () { | ||
sinon.stub(config, 'serializedProperties').get(() => ({extra: true})); | ||
|
||
var delta = richText.deserialize({ | ||
ops: [], | ||
extra: {lorem: 'ipsum'}, | ||
}); | ||
|
||
expect(delta.extra).to.eql({lorem: 'ipsum'}); | ||
}); | ||
}); | ||
}); |