Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
tests(routing): add a test for synchronization with slow routing
Browse files Browse the repository at this point in the history
  • Loading branch information
juliemr committed Jan 12, 2014
1 parent 9c86a27 commit af5570f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
13 changes: 12 additions & 1 deletion spec/basic/synchronize_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var util = require('util');

describe('synchronizing with slow pages', function() {
ddescribe('synchronizing with slow pages', function() {
beforeEach(function() {
browser.get('index.html#/async');
});
Expand Down Expand Up @@ -72,4 +72,15 @@ describe('synchronizing with slow pages', function() {

expect(status.getText()).toEqual('done');
});

it('waits for slow routing changes', function() {
var status = element(by.binding('routingChangeStatus'));
var button = element(by.css('[ng-click="routingChange()"]'));

expect(status.getText()).toEqual('not started');

button.click();

expect(browser.getPageSource()).toMatch('polling mechanism');
});
});
9 changes: 9 additions & 0 deletions testapp/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@ angular.module('myApp', ['ngRoute', 'myApp.appVersion']).
$routeProvider.when('/async', {templateUrl: 'async/async.html', controller: AsyncCtrl});
$routeProvider.when('/conflict', {templateUrl: 'conflict/conflict.html', controller: ConflictCtrl});
$routeProvider.when('/polling', {templateUrl: 'polling/polling.html', controller: PollingCtrl});
$routeProvider.when('/slowloader', {
templateUrl: 'polling/polling.html',
controller: PollingCtrl,
resolve: {
slow: function($timeout) {
return $timeout(function() {}, 2000);
}
}
});
$routeProvider.otherwise({redirectTo: '/form'});
}]);
4 changes: 4 additions & 0 deletions testapp/async/async.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
<button ng-click="slowHttpPromise()">http promise</button>
<span ng-bind="slowHttpPromiseStatus"></span>
</li>
<li>
<button ng-click="routingChange()">routing change</button>
<span ng-bind="routingChangeStatus"></span>
</li>
</ul>
12 changes: 9 additions & 3 deletions testapp/async/async.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
function AsyncCtrl($scope, $http, $timeout) {
function AsyncCtrl($scope, $http, $timeout, $location) {
$scope.slowHttpStatus = 'not started';
$scope.slowFunctionStatus = 'not started';
$scope.slowTimeoutStatus = 'not started';
$scope.slowAngularTimeoutStatus = 'not started';
$scope.slowAngularTimeoutPromiseStatus = 'not started';
$scope.slowHttpPromiseStatus = 'not started';
$scope.routingChangeStatus = 'not started';

$scope.slowHttp = function() {
$scope.slowHttpStatus = 'pending...';
Expand Down Expand Up @@ -53,7 +54,12 @@ function AsyncCtrl($scope, $http, $timeout) {
}).then(function() {
$scope.slowHttpPromiseStatus = 'done';
});
}
};

$scope.routingChange = function() {
$scope.routingChangeStatus = 'pending...';
$location.url('/slowloader');
};
};

AsyncCtrl.$inject = ['$scope', '$http', '$timeout'];
AsyncCtrl.$inject = ['$scope', '$http', '$timeout', '$location'];

0 comments on commit af5570f

Please sign in to comment.