Fix missing project scope in routes

pull/3605/head
Alex Dik 9 years ago
parent d642586313
commit 74f302b504
  1. 12
      frontend/app/routing.js
  2. 50
      frontend/tests/unit/tests/work_packages/routing-test.js

@ -195,7 +195,8 @@ angular.module('openproject')
'$rootElement', '$rootElement',
'$browser', '$browser',
'$rootScope', '$rootScope',
function($location, $rootElement, $browser, $rootScope) { '$state',
function($location, $rootElement, $browser, $rootScope, $state) {
// Our application is still a hybrid one, meaning most routes are still // Our application is still a hybrid one, meaning most routes are still
// handled by Rails. As such, we disable the default link-hijacking that // handled by Rails. As such, we disable the default link-hijacking that
// Angular's HTML5-mode turns on. // Angular's HTML5-mode turns on.
@ -223,5 +224,14 @@ angular.module('openproject')
} }
} }
}); });
$rootScope.$on('$stateChangeStart', function(event, toState, toParams){
var matchListState = toState.name.match(/work-packages\.list.*/);
if (matchListState && !toParams.projects && toParams.projectPath) {
toParams.projects = 'projects';
$state.go(toState, toParams);
}
});
} }
]); ]);

@ -0,0 +1,50 @@
describe('Routing', function () {
var $rootScope, $state, mockState = { go: function () {} };
beforeEach(module('openproject', function ($provide) {
$provide.value('$state', mockState);
}));
beforeEach(inject(function (_$rootScope_) {
$rootScope = _$rootScope_;
}));
describe('when the project id is set', function () {
var toState, toParams,
spy = sinon.spy(mockState, 'go'),
broadcast = function () {
$rootScope.$broadcast('$stateChangeStart', toState, toParams);
};
beforeEach(function () {
toState = { name: 'work-packages.list' };
toParams = { projectPath: 'my_project', projects: null };
});
it('sets the projects path segment to "projects" ', function () {
broadcast();
expect(toParams.projects).to.equal('projects');
});
it('routes to the given state', function () {
broadcast();
expect(spy.withArgs(toState, toParams).called).to.be.true;
});
it('routes to child states of work-packages.list', function () {
var childStates = ['child', 'my.other.child'];
childStates.forEach(function (childState) {
toState.name = 'work-packages.list.' + childState;
broadcast();
expect(spy.withArgs(toState, toParams).calledOnce).to.be.true;
});
});
it('is ignored on other routes than work-packages.list', function () {
toState.name = 'work-packages.other.route';
broadcast();
expect(spy.withArgs(toState, toParams).called).to.be.false;
})
});
});
Loading…
Cancel
Save