2021-10-14 20:10:36 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const CollectionRouter = require('../../../../../core/frontend/services/routing/CollectionRouter');
|
2021-10-18 21:01:38 +03:00
|
|
|
const RouterManager = require('../../../../../core/frontend/services/routing/router-manager');
|
2021-10-14 20:10:36 +03:00
|
|
|
const registry = require('../../../../../core/frontend/services/routing/registry');
|
|
|
|
|
|
|
|
const RESOURCE_CONFIG = {QUERY: {post: {controller: 'posts', resource: 'posts'}}};
|
|
|
|
|
2021-10-18 21:01:38 +03:00
|
|
|
describe('UNIT: services/routing/router-manager', function () {
|
2021-10-18 20:23:06 +03:00
|
|
|
let routerUpdatedSpy;
|
2021-10-18 19:48:26 +03:00
|
|
|
let routerCreatedSpy;
|
2021-10-14 20:10:36 +03:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2021-10-18 19:48:26 +03:00
|
|
|
routerCreatedSpy = sinon.spy();
|
2021-10-18 20:23:06 +03:00
|
|
|
routerUpdatedSpy = sinon.spy();
|
2021-10-14 20:10:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('timezone changes', function () {
|
|
|
|
describe('no dated permalink', function () {
|
|
|
|
it('default', function () {
|
2021-10-18 19:48:26 +03:00
|
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
2021-10-14 20:10:36 +03:00
|
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
|
2021-10-18 20:23:06 +03:00
|
|
|
const routerManager = new RouterManager({registry});
|
|
|
|
routerManager.init({
|
|
|
|
urlService: {
|
|
|
|
onRouterUpdated: routerUpdatedSpy
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
routerManager.handleTimezoneEdit({
|
2021-10-14 20:10:36 +03:00
|
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
|
|
_previousAttributes: {value: 'Europe/London'}
|
|
|
|
});
|
|
|
|
|
2021-10-18 20:23:06 +03:00
|
|
|
routerUpdatedSpy.called.should.be.false();
|
2021-10-14 20:10:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('tz has not changed', function () {
|
2021-10-18 19:48:26 +03:00
|
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
2021-10-14 20:10:36 +03:00
|
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
|
2021-10-18 20:23:06 +03:00
|
|
|
const routerManager = new RouterManager({registry});
|
|
|
|
routerManager.init({
|
|
|
|
urlService: {
|
|
|
|
onRouterUpdated: routerUpdatedSpy
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
routerManager.handleTimezoneEdit({
|
2021-10-14 20:10:36 +03:00
|
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
|
|
_previousAttributes: {value: 'America/Los_Angeles'}
|
|
|
|
});
|
|
|
|
|
2021-10-18 20:23:06 +03:00
|
|
|
routerUpdatedSpy.called.should.be.false();
|
2021-10-14 20:10:36 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with dated permalink', function () {
|
|
|
|
it('default', function () {
|
2021-10-18 19:48:26 +03:00
|
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
2021-10-14 20:10:36 +03:00
|
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
|
2021-10-18 20:23:06 +03:00
|
|
|
const routerManager = new RouterManager({registry});
|
|
|
|
routerManager.init({
|
|
|
|
urlService: {
|
|
|
|
onRouterUpdated: routerUpdatedSpy
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
routerManager.handleTimezoneEdit({
|
2021-10-14 20:10:36 +03:00
|
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
|
|
_previousAttributes: {value: 'Europe/London'}
|
|
|
|
});
|
|
|
|
|
2021-10-18 20:23:06 +03:00
|
|
|
routerUpdatedSpy.called.should.be.true();
|
2021-10-14 20:10:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('tz has not changed', function () {
|
2021-10-18 19:48:26 +03:00
|
|
|
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
2021-10-14 20:10:36 +03:00
|
|
|
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
|
|
|
|
2021-10-18 20:23:06 +03:00
|
|
|
const routerManager = new RouterManager({registry});
|
|
|
|
routerManager.init({
|
|
|
|
urlService: {
|
|
|
|
onRouterUpdated: routerUpdatedSpy
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
routerManager.handleTimezoneEdit({
|
2021-10-14 20:10:36 +03:00
|
|
|
attributes: {value: 'America/Los_Angeles'},
|
|
|
|
_previousAttributes: {value: 'America/Los_Angeles'}
|
|
|
|
});
|
|
|
|
|
2021-10-18 20:23:06 +03:00
|
|
|
routerUpdatedSpy.called.should.be.false();
|
2021-10-14 20:10:36 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|