Skip to content

Commit

Permalink
Move default state out of run block
Browse files Browse the repository at this point in the history
`$scope.go()` inside the top-level run block will increase test complexity as a
mock template cache would need to be set up for each test that uses `$scope`
regardless of whether it depends on a template.

UI Router currently uses a state using an empty `url` as the default state, see:

angular-ui/ui-router#182
angular-ui/ui-router#174 (comment)

Since we're setting up the layout in a parent, abstract state, redirect to the
*real* index using `otherwise()`.
  • Loading branch information
tlvince committed Mar 17, 2014
1 parent 585ee12 commit 37b9c9f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
3 changes: 0 additions & 3 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,4 @@ angular.module('lmisChromeApp', [

// Convenience property to get the current state
$rootScope.$state = $state;

// Default state
$state.go('home.index.mainActivity');
});
6 changes: 4 additions & 2 deletions app/scripts/controllers/home.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict';

angular.module('lmisChromeApp')
.config(function($stateProvider) {
.config(function($urlRouterProvider, $stateProvider) {
// Initial state
$urlRouterProvider.otherwise('/main-activity');
$stateProvider.state('home', {
url: '/home',
url: '',
abstract: true,
templateUrl: 'views/home/index.html',
resolve: {
Expand Down
2 changes: 1 addition & 1 deletion test/spec/controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Home controller', function () {

var state = 'home.index.mainActivity';
it('should respond to URL', function() {
expect($state.href(state)).toEqual('#/home/main-activity');
expect($state.href(state)).toEqual('#/main-activity');
});

it('should go to the main activity state', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/spec/services/alertsfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ describe('Service: alertsFactory', function() {
scope.$apply(function() {
$state.go(ma);
alertsFactory.add({message: 'Test'});
expect(scope.alerts.length).toEqual(1);
});
expect(scope.alerts.length).toEqual(1);

scope.$apply(function() {
$state.go(dash);
expect(scope.alerts.length).toEqual(0);
});
expect(scope.alerts.length).toEqual(0);
});
});

Expand Down

0 comments on commit 37b9c9f

Please sign in to comment.