Ghost/test/unit/helpers/cancel_link_spec.js
Hannah Wolfe 7f1d3ebc07
Move tests from core to root (#11700)
- move all test files from core/test to test/
- updated all imports and other references
- all code inside of core/ is then application code
- tests are correctly at the root level
- consistent with other repos/projects

Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
2020-03-30 16:26:47 +01:00

113 lines
3.6 KiB
JavaScript

const should = require('should');
const hbs = require('../../../core/frontend/services/themes/engine');
const helpers = require('../../../core/frontend/helpers');
const configUtils = require('../../utils/configUtils');
describe('{{cancel_link}} helper', function () {
before(function (done) {
hbs.express4({partialsDir: [configUtils.config.get('paths').helperTemplates]});
hbs.cachePartials(function () {
done();
});
});
const defaultLinkClass = /class="gh-subscription-cancel"/;
const defaultErrorElementClass = /class="gh-error gh-error-subscription-cancel"/;
const defaultCancelLinkText = /Cancel subscription/;
const defaultContinueLinkText = /Continue subscription/;
it('should throw if subscription data is incorrect', function () {
const runHelper = function (data) {
return function () {
helpers.cancel_link.call(data);
};
};
runHelper('not an object').should.throw();
runHelper(function () {}).should.throw();
});
it('can render cancel subscription link', function () {
const rendered = helpers.cancel_link.call({
id: 'sub_cancel',
cancel_at_period_end: false
});
should.exist(rendered);
rendered.string.should.match(defaultLinkClass);
rendered.string.should.match(/data-members-cancel-subscription="sub_cancel"/);
rendered.string.should.match(defaultCancelLinkText);
rendered.string.should.match(defaultErrorElementClass);
});
it('can render continue subscription link', function () {
const rendered = helpers.cancel_link.call({
id: 'sub_continue',
cancel_at_period_end: true
});
should.exist(rendered);
rendered.string.should.match(defaultLinkClass);
rendered.string.should.match(/data-members-continue-subscription="sub_continue"/);
rendered.string.should.match(defaultContinueLinkText);
});
it('can render custom link class', function () {
const rendered = helpers.cancel_link.call({
id: 'sub_cancel',
cancel_at_period_end: false
}, {
hash: {
class: 'custom-link-class'
}
});
should.exist(rendered);
rendered.string.should.match(/custom-link-class/);
});
it('can render custom error class', function () {
const rendered = helpers.cancel_link.call({
id: 'sub_cancel',
cancel_at_period_end: false
}, {
hash: {
errorClass: 'custom-error-class'
}
});
should.exist(rendered);
rendered.string.should.match(/custom-error-class/);
});
it('can render custom cancel subscription link attributes', function () {
const rendered = helpers.cancel_link.call({
id: 'sub_cancel',
cancel_at_period_end: false
}, {
hash: {
cancelLabel: 'custom cancel link text'
}
});
should.exist(rendered);
rendered.string.should.match(/custom cancel link text/);
});
it('can render custom continue subscription link attributes', function () {
const rendered = helpers.cancel_link.call({
id: 'sub_cancel',
cancel_at_period_end: true
}, {
hash: {
continueLabel: 'custom continue link text'
}
});
should.exist(rendered);
rendered.string.should.match(/custom continue link text/);
});
});