mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added tests for bookmark card
no issue
This commit is contained in:
parent
7abeaf6f18
commit
839cf0289f
3 changed files with 253 additions and 50 deletions
|
@ -37,11 +37,12 @@ module.exports = createCard({
|
||||||
name: 'bookmark',
|
name: 'bookmark',
|
||||||
type: 'dom',
|
type: 'dom',
|
||||||
render(opts) {
|
render(opts) {
|
||||||
if (!opts.payload.metadata) {
|
let {payload, env: {dom}} = opts;
|
||||||
|
|
||||||
|
if (!payload.metadata || !payload.metadata.url || !payload.metadata.title || !payload.metadata.description) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
let {payload, env: {dom}} = opts;
|
|
||||||
let figure = createElement(dom, 'figure', 'kg-card kg-bookmark-card');
|
let figure = createElement(dom, 'figure', 'kg-card kg-bookmark-card');
|
||||||
let linkTag = createElement(dom, 'a', 'kg-bookmark-container', [{
|
let linkTag = createElement(dom, 'a', 'kg-bookmark-container', [{
|
||||||
key: 'href',
|
key: 'href',
|
||||||
|
|
204
core/test/unit/lib/mobiledoc/cards/bookmark_spec.js
Normal file
204
core/test/unit/lib/mobiledoc/cards/bookmark_spec.js
Normal file
|
@ -0,0 +1,204 @@
|
||||||
|
const should = require('should');
|
||||||
|
const card = require('../../../../../server/lib/mobiledoc/cards/bookmark');
|
||||||
|
const SimpleDom = require('simple-dom');
|
||||||
|
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
|
||||||
|
|
||||||
|
describe('Bookmark card', function () {
|
||||||
|
it('renders', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {
|
||||||
|
url: 'http://example.com',
|
||||||
|
title: 'Title',
|
||||||
|
description: 'Description',
|
||||||
|
icon: 'http://example.com/icon.png',
|
||||||
|
thumbnail: 'http://exampple.com/thumbnail.png',
|
||||||
|
author: 'Author',
|
||||||
|
publisher: 'Publisher'
|
||||||
|
},
|
||||||
|
caption: 'Caption'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('<!--kg-card-begin: bookmark--><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="http://example.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Title</div><div class="kg-bookmark-description">Description</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="http://example.com/icon.png"><span class="kg-bookmark-author">Author</span><span class="kg-bookmark-publisher">Publisher</span></div></div><div class="kg-bookmark-thumbnail"><img src="http://exampple.com/thumbnail.png"></div></a><figcaption>Caption</figcaption></figure><!--kg-card-end: bookmark-->');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips icon when missing', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {
|
||||||
|
url: 'http://example.com',
|
||||||
|
title: 'Title',
|
||||||
|
description: 'Description',
|
||||||
|
icon: null,
|
||||||
|
thumbnail: 'http://exampple.com/thumbnail.png',
|
||||||
|
author: 'Author',
|
||||||
|
publisher: 'Publisher'
|
||||||
|
},
|
||||||
|
caption: 'Caption'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('<!--kg-card-begin: bookmark--><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="http://example.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Title</div><div class="kg-bookmark-description">Description</div><div class="kg-bookmark-metadata"><span class="kg-bookmark-author">Author</span><span class="kg-bookmark-publisher">Publisher</span></div></div><div class="kg-bookmark-thumbnail"><img src="http://exampple.com/thumbnail.png"></div></a><figcaption>Caption</figcaption></figure><!--kg-card-end: bookmark-->');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips thumbnail when missing', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {
|
||||||
|
url: 'http://example.com',
|
||||||
|
title: 'Title',
|
||||||
|
description: 'Description',
|
||||||
|
icon: 'http://example.com/icon.png',
|
||||||
|
thumbnail: null,
|
||||||
|
author: 'Author',
|
||||||
|
publisher: 'Publisher'
|
||||||
|
},
|
||||||
|
caption: 'Caption'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('<!--kg-card-begin: bookmark--><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="http://example.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Title</div><div class="kg-bookmark-description">Description</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="http://example.com/icon.png"><span class="kg-bookmark-author">Author</span><span class="kg-bookmark-publisher">Publisher</span></div></div></a><figcaption>Caption</figcaption></figure><!--kg-card-end: bookmark-->');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips author when missing', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {
|
||||||
|
url: 'http://example.com',
|
||||||
|
title: 'Title',
|
||||||
|
description: 'Description',
|
||||||
|
icon: 'http://example.com/icon.png',
|
||||||
|
thumbnail: 'http://exampple.com/thumbnail.png',
|
||||||
|
author: null,
|
||||||
|
publisher: 'Publisher'
|
||||||
|
},
|
||||||
|
caption: 'Caption'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('<!--kg-card-begin: bookmark--><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="http://example.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Title</div><div class="kg-bookmark-description">Description</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="http://example.com/icon.png"><span class="kg-bookmark-publisher">Publisher</span></div></div><div class="kg-bookmark-thumbnail"><img src="http://exampple.com/thumbnail.png"></div></a><figcaption>Caption</figcaption></figure><!--kg-card-end: bookmark-->');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips publisher when missing', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {
|
||||||
|
url: 'http://example.com',
|
||||||
|
title: 'Title',
|
||||||
|
description: 'Description',
|
||||||
|
icon: 'http://example.com/icon.png',
|
||||||
|
thumbnail: 'http://exampple.com/thumbnail.png',
|
||||||
|
author: 'Author',
|
||||||
|
publisher: null
|
||||||
|
},
|
||||||
|
caption: 'Caption'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('<!--kg-card-begin: bookmark--><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="http://example.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Title</div><div class="kg-bookmark-description">Description</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="http://example.com/icon.png"><span class="kg-bookmark-author">Author</span></div></div><div class="kg-bookmark-thumbnail"><img src="http://exampple.com/thumbnail.png"></div></a><figcaption>Caption</figcaption></figure><!--kg-card-end: bookmark-->');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips caption when missing', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {
|
||||||
|
url: 'http://example.com',
|
||||||
|
title: 'Title',
|
||||||
|
description: 'Description',
|
||||||
|
icon: 'http://example.com/icon.png',
|
||||||
|
thumbnail: 'http://exampple.com/thumbnail.png',
|
||||||
|
author: 'Author',
|
||||||
|
publisher: 'Publisher'
|
||||||
|
},
|
||||||
|
caption: ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('<!--kg-card-begin: bookmark--><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="http://example.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">Title</div><div class="kg-bookmark-description">Description</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="http://example.com/icon.png"><span class="kg-bookmark-author">Author</span><span class="kg-bookmark-publisher">Publisher</span></div></div><div class="kg-bookmark-thumbnail"><img src="http://exampple.com/thumbnail.png"></div></a></figure><!--kg-card-end: bookmark-->');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders nothing when payload is undefined', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: undefined
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders nothing when payload metadata is empty', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders nothing when url is missing', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {
|
||||||
|
url: null,
|
||||||
|
title: 'Test bookmark',
|
||||||
|
description: 'This is just a test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders nothing when title is missing', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {
|
||||||
|
url: 'http://example.com',
|
||||||
|
title: null,
|
||||||
|
description: 'This is just a test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders nothing when description is missing', function () {
|
||||||
|
let opts = {
|
||||||
|
env: {dom: new SimpleDom.Document()},
|
||||||
|
payload: {
|
||||||
|
metadata: {
|
||||||
|
url: 'http://example.com',
|
||||||
|
title: 'Test bookmark',
|
||||||
|
description: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serializer.serialize(card.render(opts))
|
||||||
|
.should.equal('');
|
||||||
|
});
|
||||||
|
});
|
|
@ -4,60 +4,58 @@ const SimpleDom = require('simple-dom');
|
||||||
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
|
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
|
||||||
|
|
||||||
describe('Markdown card', function () {
|
describe('Markdown card', function () {
|
||||||
describe('default', function () {
|
it('renders', function () {
|
||||||
it('Markdown Card renders', function () {
|
let opts = {
|
||||||
let opts = {
|
env: {
|
||||||
env: {
|
dom: new SimpleDom.Document()
|
||||||
dom: new SimpleDom.Document()
|
},
|
||||||
},
|
payload: {
|
||||||
payload: {
|
markdown: '#HEADING\r\n- list\r\n- items'
|
||||||
markdown: '#HEADING\r\n- list\r\n- items'
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
serializer.serialize(card.render(opts)).should.eql('<!--kg-card-begin: markdown--><h1 id="heading">HEADING</h1>\n<ul>\n<li>list</li>\n<li>items</li>\n</ul>\n<!--kg-card-end: markdown-->');
|
serializer.serialize(card.render(opts)).should.eql('<!--kg-card-begin: markdown--><h1 id="heading">HEADING</h1>\n<ul>\n<li>list</li>\n<li>items</li>\n</ul>\n<!--kg-card-end: markdown-->');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Accepts invalid HTML in markdown', function () {
|
it('Accepts invalid HTML in markdown', function () {
|
||||||
let opts = {
|
let opts = {
|
||||||
env: {
|
env: {
|
||||||
dom: new SimpleDom.Document()
|
dom: new SimpleDom.Document()
|
||||||
},
|
},
|
||||||
payload: {
|
payload: {
|
||||||
markdown: '#HEADING\r\n<h2>Heading 2>'
|
markdown: '#HEADING\r\n<h2>Heading 2>'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
serializer.serialize(card.render(opts)).should.eql('<!--kg-card-begin: markdown--><h1 id="heading">HEADING</h1>\n<h2>Heading 2><!--kg-card-end: markdown-->');
|
serializer.serialize(card.render(opts)).should.eql('<!--kg-card-begin: markdown--><h1 id="heading">HEADING</h1>\n<h2>Heading 2><!--kg-card-end: markdown-->');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Renders nothing when payload is undefined', function () {
|
it('Renders nothing when payload is undefined', function () {
|
||||||
let opts = {
|
let opts = {
|
||||||
env: {
|
env: {
|
||||||
dom: new SimpleDom.Document()
|
dom: new SimpleDom.Document()
|
||||||
},
|
},
|
||||||
payload: {
|
payload: {
|
||||||
markdown: undefined
|
markdown: undefined
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
serializer.serialize(card.render(opts)).should.eql('');
|
serializer.serialize(card.render(opts)).should.eql('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('[deprecated] version 1', function () {
|
it('[deprecated] version 1', function () {
|
||||||
let opts = {
|
let opts = {
|
||||||
env: {
|
env: {
|
||||||
dom: new SimpleDom.Document()
|
dom: new SimpleDom.Document()
|
||||||
},
|
},
|
||||||
payload: {
|
payload: {
|
||||||
markdown: '#HEADING\r\n- list\r\n- items'
|
markdown: '#HEADING\r\n- list\r\n- items'
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
version: 1
|
version: 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
serializer.serialize(card.render(opts)).should.eql('<!--kg-card-begin: markdown--><div class="kg-card-markdown"><h1 id="heading">HEADING</h1>\n<ul>\n<li>list</li>\n<li>items</li>\n</ul>\n</div><!--kg-card-end: markdown-->');
|
serializer.serialize(card.render(opts)).should.eql('<!--kg-card-begin: markdown--><div class="kg-card-markdown"><h1 id="heading">HEADING</h1>\n<ul>\n<li>list</li>\n<li>items</li>\n</ul>\n</div><!--kg-card-end: markdown-->');
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue