0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/test/unit/data/meta/paginated_url_spec.js
Hannah Wolfe 22e13acd65 Updated var declarations to const/let and no lists
- All var declarations are now const or let as per ES6
- All comma-separated lists / chained declarations are now one declaration per line
- This is for clarity/readability but also made running the var-to-const/let switch smoother
- ESLint rules updated to match

How this was done:

- npm install -g jscodeshift
- git clone https://github.com/cpojer/js-codemod.git
- git clone git@github.com:TryGhost/Ghost.git shallow-ghost
- cd shallow-ghost
- jscodeshift -t ../js-codemod/transforms/unchain-variables.js . -v=2
- jscodeshift -t ../js-codemod/transforms/no-vars.js . -v=2
- yarn
- yarn test
- yarn lint / fix various lint errors (almost all indent) by opening files and saving in vscode
- grunt test-regression
- sorted!
2020-04-29 16:51:13 +01:00

172 lines
6.4 KiB
JavaScript

const should = require('should');
const sinon = require('sinon');
const getPaginatedUrl = require('../../../../core/frontend/meta/paginated_url');
const urlUtils = require('../../../utils/urlUtils');
describe('getPaginatedUrl', function () {
let data;
let getTestUrls;
beforeEach(function () {
data = {};
});
getTestUrls = function getTestUrls() {
return {
next: getPaginatedUrl('next', data, true),
prev: getPaginatedUrl('prev', data, true),
page1: getPaginatedUrl(1, data),
page5: getPaginatedUrl(5, data),
page10: getPaginatedUrl(10, data)
};
};
it('should be a function', function () {
should.exist(getPaginatedUrl);
});
describe('index', function () {
it('should calculate correct urls for the first page of an index collection', function () {
// Setup tests
data.relativeUrl = '/';
data.pagination = {prev: null, next: 2};
// Execute test
const urls = getTestUrls();
// Check results
urls.should.have.property('next', 'http://127.0.0.1:2369/page/2/');
urls.should.have.property('prev', null);
urls.should.have.property('page1', '/');
urls.should.have.property('page5', '/page/5/');
urls.should.have.property('page10', '/page/10/');
});
it('should calculate correct urls for the second page of an index collection', function () {
// Setup tests
data.relativeUrl = '/page/2/';
data.pagination = {prev: 1, next: 3};
// Execute test
const urls = getTestUrls();
// Check results
urls.should.have.property('next', 'http://127.0.0.1:2369/page/3/');
urls.should.have.property('prev', 'http://127.0.0.1:2369/');
urls.should.have.property('page1', '/');
urls.should.have.property('page5', '/page/5/');
urls.should.have.property('page10', '/page/10/');
});
it('should calculate correct urls for the last page of an index collection', function () {
// Setup tests
data.relativeUrl = '/page/10/';
data.pagination = {prev: 9, next: null};
// Execute test
const urls = getTestUrls();
// Check results
urls.should.have.property('next', null);
urls.should.have.property('prev', 'http://127.0.0.1:2369/page/9/');
urls.should.have.property('page1', '/');
urls.should.have.property('page5', '/page/5/');
urls.should.have.property('page10', '/page/10/');
});
});
describe('other', function () {
it('should calculate correct urls for the first page of another collection', function () {
// Setup tests
data.relativeUrl = '/featured/';
data.pagination = {prev: null, next: 2};
// Execute test
const urls = getTestUrls();
// Check results
urls.should.have.property('next', 'http://127.0.0.1:2369/featured/page/2/');
urls.should.have.property('prev', null);
urls.should.have.property('page1', '/featured/');
urls.should.have.property('page5', '/featured/page/5/');
urls.should.have.property('page10', '/featured/page/10/');
});
it('should calculate correct urls for the second page of another collection', function () {
// Setup tests
data.relativeUrl = '/featured/page/2/';
data.pagination = {prev: 1, next: 3};
// Execute test
const urls = getTestUrls();
// Check results
urls.should.have.property('next', 'http://127.0.0.1:2369/featured/page/3/');
urls.should.have.property('prev', 'http://127.0.0.1:2369/featured/');
urls.should.have.property('page1', '/featured/');
urls.should.have.property('page5', '/featured/page/5/');
urls.should.have.property('page10', '/featured/page/10/');
});
it('should calculate correct urls for the last page of another collection', function () {
// Setup tests
data.relativeUrl = '/featured/page/10/';
data.pagination = {prev: 9, next: null};
// Execute test
const urls = getTestUrls();
// Check results
urls.should.have.property('next', null);
urls.should.have.property('prev', 'http://127.0.0.1:2369/featured/page/9/');
urls.should.have.property('page1', '/featured/');
urls.should.have.property('page5', '/featured/page/5/');
urls.should.have.property('page10', '/featured/page/10/');
});
});
describe('with /blog subdirectory', function () {
let sandbox;
before(function () {
sandbox = sinon.createSandbox();
urlUtils.stubUrlUtils({url: 'http://localhost:65535/blog'}, sandbox);
});
after(function () {
sandbox.restore();
});
it('should calculate correct urls for index', function () {
// Setup tests
data.relativeUrl = '/page/2/';
data.pagination = {prev: 1, next: 3};
// Execute test
const urls = getTestUrls();
// Check results
urls.should.have.property('next', 'http://localhost:65535/blog/page/3/');
urls.should.have.property('prev', 'http://localhost:65535/blog/');
urls.should.have.property('page1', '/blog/');
urls.should.have.property('page5', '/blog/page/5/');
urls.should.have.property('page10', '/blog/page/10/');
});
it('should calculate correct urls for another collection', function () {
// Setup tests
data.relativeUrl = '/featured/page/2/';
data.pagination = {prev: 1, next: 3};
// Execute test
const urls = getTestUrls();
// Check results
urls.should.have.property('next', 'http://localhost:65535/blog/featured/page/3/');
urls.should.have.property('prev', 'http://localhost:65535/blog/featured/');
urls.should.have.property('page1', '/blog/featured/');
urls.should.have.property('page5', '/blog/featured/page/5/');
urls.should.have.property('page10', '/blog/featured/page/10/');
});
});
});