mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
51b78211c5
refs https://linear.app/tryghost/issue/CORE-104/decouple-frontend-routing-events-from-urlserver-events - A follow up rename after bootstrap module was transformed into class
104 lines
4.1 KiB
JavaScript
104 lines
4.1 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const CollectionRouter = require('../../../../../core/frontend/services/routing/CollectionRouter');
|
|
const RouterManager = require('../../../../../core/frontend/services/routing/router-manager');
|
|
const registry = require('../../../../../core/frontend/services/routing/registry');
|
|
|
|
const RESOURCE_CONFIG = {QUERY: {post: {controller: 'posts', resource: 'posts'}}};
|
|
|
|
describe('UNIT: services/routing/router-manager', function () {
|
|
let routerUpdatedSpy;
|
|
let routerCreatedSpy;
|
|
|
|
beforeEach(function () {
|
|
routerCreatedSpy = sinon.spy();
|
|
routerUpdatedSpy = sinon.spy();
|
|
});
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
describe('timezone changes', function () {
|
|
describe('no dated permalink', function () {
|
|
it('default', function () {
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
const routerManager = new RouterManager({registry});
|
|
routerManager.init({
|
|
urlService: {
|
|
onRouterUpdated: routerUpdatedSpy
|
|
}
|
|
});
|
|
|
|
routerManager.handleTimezoneEdit({
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
_previousAttributes: {value: 'Europe/London'}
|
|
});
|
|
|
|
routerUpdatedSpy.called.should.be.false();
|
|
});
|
|
|
|
it('tz has not changed', function () {
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
const routerManager = new RouterManager({registry});
|
|
routerManager.init({
|
|
urlService: {
|
|
onRouterUpdated: routerUpdatedSpy
|
|
}
|
|
});
|
|
|
|
routerManager.handleTimezoneEdit({
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
_previousAttributes: {value: 'America/Los_Angeles'}
|
|
});
|
|
|
|
routerUpdatedSpy.called.should.be.false();
|
|
});
|
|
});
|
|
|
|
describe('with dated permalink', function () {
|
|
it('default', function () {
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
const routerManager = new RouterManager({registry});
|
|
routerManager.init({
|
|
urlService: {
|
|
onRouterUpdated: routerUpdatedSpy
|
|
}
|
|
});
|
|
|
|
routerManager.handleTimezoneEdit({
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
_previousAttributes: {value: 'Europe/London'}
|
|
});
|
|
|
|
routerUpdatedSpy.called.should.be.true();
|
|
});
|
|
|
|
it('tz has not changed', function () {
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
const routerManager = new RouterManager({registry});
|
|
routerManager.init({
|
|
urlService: {
|
|
onRouterUpdated: routerUpdatedSpy
|
|
}
|
|
});
|
|
|
|
routerManager.handleTimezoneEdit({
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
_previousAttributes: {value: 'America/Los_Angeles'}
|
|
});
|
|
|
|
routerUpdatedSpy.called.should.be.false();
|
|
});
|
|
});
|
|
});
|
|
});
|