mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
9e96b04542
- this is a small part of a bit of cleanup of our test files - the goal is to make the existing tests clearer with a view to making it easier to write more tests - this makes the test structure follow the codebase structure more closely - eventually we will colocate the tests as we break the codebase down further
52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
const should = require('should');
|
|
|
|
const {getSegmentsFromHtml} = require('../../../../../core/server/services/mega/segment-parser');
|
|
|
|
describe('MEGA: Segment Parser', function () {
|
|
it('extracts a single segments used in HTML', function () {
|
|
const html = '<div data-gh-segment="status:-free"><p>Plain html with no replacements</p></div>';
|
|
|
|
const segments = getSegmentsFromHtml(html);
|
|
|
|
segments.length.should.equal(1);
|
|
segments[0].should.equal('status:-free');
|
|
});
|
|
|
|
it('extracts multiple segments used in HTML', function () {
|
|
const html = `
|
|
<div data-gh-segment="status:-free"><p>Text for paid</p></div>
|
|
<div data-gh-segment="status:free"><p>Text for free</p></div>
|
|
<div data-gh-segment="status:-free,label.slug:VIP"><p>Text for paid VIP</p></div>
|
|
`;
|
|
|
|
const segments = getSegmentsFromHtml(html);
|
|
|
|
segments.length.should.equal(3);
|
|
segments[0].should.equal('status:-free');
|
|
segments[1].should.equal('status:free');
|
|
segments[2].should.equal('status:-free,label.slug:VIP');
|
|
});
|
|
|
|
it('extracts only unique segments', function () {
|
|
const html = `
|
|
<div data-gh-segment="status:-free"><p>Text for paid</p></div>
|
|
<div data-gh-segment="status:free"><p>Text for free</p></div>
|
|
<div data-gh-segment="status:-free"><p>Another message for paid member</p></div>
|
|
`;
|
|
|
|
const segments = getSegmentsFromHtml(html);
|
|
|
|
segments.length.should.equal(2);
|
|
segments[0].should.equal('status:-free');
|
|
segments[1].should.equal('status:free');
|
|
});
|
|
|
|
it('extracts no segments from HTML', function () {
|
|
const html = '<div data-gh-somethingelse="status:-free"><p>Plain html with no replacements</p></div>';
|
|
|
|
const segments = getSegmentsFromHtml(html);
|
|
|
|
segments.length.should.equal(0);
|
|
});
|
|
});
|