mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
18344a16e2
refs https://linear.app/tryghost/issue/CORE-104/decouple-frontend-routing-events-from-urlserver-events - The 'settings.timezone.edited' event triggers a roundtrip chain of calls in the frontend routing to the url services. It was all handled by event listeners and handler that clearly don't belong there. - Extracted event realted listeners/handlers into methods and moved most of the logic to the "bootstrap" module, which soon is going to become a "RoutesManger" - The result of this refactor - no more events going back and forth between frontend routing and the backend!
74 lines
3.1 KiB
JavaScript
74 lines
3.1 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const CollectionRouter = require('../../../../../core/frontend/services/routing/CollectionRouter');
|
|
const bootstrap = require('../../../../../core/frontend/services/routing/bootstrap');
|
|
const registry = require('../../../../../core/frontend/services/routing/registry');
|
|
|
|
const RESOURCE_CONFIG = {QUERY: {post: {controller: 'posts', resource: 'posts'}}};
|
|
|
|
describe('UNIT: services/routing/bootstrap', function () {
|
|
let routesUpdatedStub;
|
|
|
|
beforeEach(function () {
|
|
sinon.stub(bootstrap.internal, 'routerCreated').returns();
|
|
routesUpdatedStub = sinon.stub(bootstrap.internal, 'routerUpdated').returns();
|
|
});
|
|
|
|
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);
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
bootstrap.handleTimezoneEdit({
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
_previousAttributes: {value: 'Europe/London'}
|
|
});
|
|
|
|
routesUpdatedStub.called.should.be.false();
|
|
});
|
|
|
|
it('tz has not changed', function () {
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
bootstrap.handleTimezoneEdit({
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
_previousAttributes: {value: 'America/Los_Angeles'}
|
|
});
|
|
|
|
routesUpdatedStub.called.should.be.false();
|
|
});
|
|
});
|
|
|
|
describe('with dated permalink', function () {
|
|
it('default', function () {
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG);
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
bootstrap.handleTimezoneEdit({
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
_previousAttributes: {value: 'Europe/London'}
|
|
});
|
|
|
|
routesUpdatedStub.called.should.be.true();
|
|
});
|
|
|
|
it('tz has not changed', function () {
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG);
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
bootstrap.handleTimezoneEdit({
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
_previousAttributes: {value: 'America/Los_Angeles'}
|
|
});
|
|
|
|
routesUpdatedStub.called.should.be.false();
|
|
});
|
|
});
|
|
});
|
|
});
|