2021-06-29 19:10:51 +04:00
|
|
|
const should = require('should');
|
|
|
|
|
2021-10-06 11:12:21 +01:00
|
|
|
const {getSegmentsFromHtml} = require('../../../../../core/server/services/mega/segment-parser');
|
2021-06-29 19:10:51 +04:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2021-06-30 14:23:39 +04:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2021-06-29 19:10:51 +04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|