Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
styts authored and inukshuk committed Dec 6, 2017
1 parent f201973 commit 2fb55ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/export/note.js
Expand Up @@ -4,13 +4,19 @@ const { NOTE } = require('../constants/type')

const { DOMSerializer } = require('prosemirror-model')
const { schema } = require('../components/editor/schema')
const { warn } = require('../common/log')

const serializer = DOMSerializer.fromSchema(schema)

function toHTML(doc) {
const node = schema.nodeFromJSON(doc)
const docFragment = serializer.serializeFragment(node)
return Array.from(docFragment.children).map(x => x.outerHTML).join('')
try {
const node = schema.nodeFromJSON(doc)
const docFragment = serializer.serializeFragment(node)
return Array.from(docFragment.children).map(x => x.outerHTML).join('')
} catch (error) {
warn('Could not convert note to html', { error, doc })
return ''
}
}

module.exports = function (note) {
Expand Down
2 changes: 1 addition & 1 deletion test/export/export_test.js
Expand Up @@ -104,7 +104,7 @@ describe('export', () => {
const item1 = (await ld)[0]['@graph'][0]
expect(item1.photo[0]).to.not.have.property('note')
expect(item1.photo[1]['note']['text']).to.eql('photo note')
expect(item1.photo[1]['note']['doc']).to.eql('{"foo":"bar"}')
expect(item1.photo[1]['note']['html']).to.eql('<p>photo note</p>')
})
})

Expand Down
16 changes: 15 additions & 1 deletion test/fixtures/export.js
Expand Up @@ -79,7 +79,21 @@ const tags = {
}

const notes = {
1: { text: 'photo note', state: { doc: { foo: 'bar' } } },
1: {
text: 'photo note',
state: {
doc: {
type: 'doc',
content: [{
type: 'paragraph',
content: [{
type: 'text',
text: 'photo note'
}]
}]
}
}
},
2: { text: 'selection note', state: {} }
}

Expand Down

0 comments on commit 2fb55ed

Please sign in to comment.