Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Commit

Permalink
Add tests for the the session reset confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Stockton committed Mar 18, 2015
1 parent bda8716 commit b85a1c3
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 10 deletions.
31 changes: 28 additions & 3 deletions test/spec/controllers/summarySyntacticalValidity.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Controller: SummarySyntacticalValidityCtrl', function () {
timeout,
Q,
Wizard,
mockNgDialog,
mockErrors = {
syntactical: {},
validity: {},
Expand All @@ -32,6 +33,17 @@ describe('Controller: SummarySyntacticalValidityCtrl', function () {
location = $location;
controller = $controller;
timeout = $timeout;

var mockNgDialogPromise = {
then: function(callback) {
callback('test');
}
};
mockNgDialog = {
openConfirm: function() { }
};
spyOn(mockNgDialog, 'openConfirm').and.returnValue(mockNgDialogPromise);

Q = $q;
Wizard = _Wizard_;
Wizard.initSteps();
Expand All @@ -40,10 +52,23 @@ describe('Controller: SummarySyntacticalValidityCtrl', function () {
$location: location,
$timeout: timeout,
HMDAEngine: mockEngine,
Wizard: _Wizard_
Wizard: _Wizard_,
ngDialog: mockNgDialog
});
}));

beforeEach(inject(function ($templateCache) {
var templateUrl = 'partials/confirmSessionReset.html';
var asynchronous = false;

var req = new XMLHttpRequest();
req.onload = function () {
$templateCache.put(templateUrl, this.responseText);
};
req.open('get', '/base/app/' + templateUrl, asynchronous);
req.send();
}));

it('should include the syntactical errors in the scope', function () {
expect(scope.syntacticalErrors).toEqual({});
});
Expand Down Expand Up @@ -210,8 +235,8 @@ describe('Controller: SummarySyntacticalValidityCtrl', function () {
scope.$digest();
});

it('should direct the user to the home (/) page', function () {
expect(location.path()).toBe('/');
it('should display the confirmation dialog', function () {
expect(mockNgDialog.openConfirm).toHaveBeenCalled();
});
});
});
33 changes: 28 additions & 5 deletions test/spec/controllers/validationSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,50 @@ describe('Controller: ValidationSummaryCtrl', function () {

var scope,
location,
mockNgDialog,
mockEngine = {
getHmdaJson: function() { return {hmdaFile: { transmittalSheet: {}}}; }
};

beforeEach(angular.mock.module('hmdaPilotApp'));

beforeEach(inject(function ($rootScope, $location, $controller, _FileMetadata_) {
beforeEach(inject(function ($rootScope, $q, $location, $controller, _FileMetadata_) {
scope = $rootScope.$new();
location = $location;
var FileMetadata = _FileMetadata_;
FileMetadata.setFilename('test.foo');

var mockNgDialogPromise = {
then: function(callback) {
callback('test');
}
};
mockNgDialog = {
openConfirm: function() { }
};
spyOn(mockNgDialog, 'openConfirm').and.returnValue(mockNgDialogPromise);

$controller('ValidationSummaryCtrl', {
$scope: scope,
$location: location,
FileMetadata: _FileMetadata_,
HMDAEngine: mockEngine
HMDAEngine: mockEngine,
ngDialog: mockNgDialog
});
}));

beforeEach(inject(function ($templateCache) {
var templateUrl = 'partials/confirmSessionReset.html';
var asynchronous = false;

var req = new XMLHttpRequest();
req.onload = function () {
$templateCache.put(templateUrl, this.responseText);
};
req.open('get', '/base/app/' + templateUrl, asynchronous);
req.send();
}));

describe('initial scope', function() {
it('should include the file metadata', function() {
expect(scope.fileMetadata).toBeDefined();
Expand All @@ -46,10 +70,9 @@ describe('Controller: ValidationSummaryCtrl', function () {
});

describe('startOver()', function() {
it('should direct the user to the /selectFile page', function () {
it('should display the confirmation dialog', function () {
scope.startOver();
scope.$digest();
expect(location.path()).toBe('/selectFile');
expect(mockNgDialog.openConfirm).toHaveBeenCalled();
});
});
});
41 changes: 39 additions & 2 deletions test/spec/directives/wizardNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('Directive: WizardNav', function () {
var element,
scope,
StepFactory,
Wizard;
Wizard,
ngDialog;

beforeEach(inject(function ($templateCache) {
var templateUrl = 'partials/wizardNav.html';
Expand All @@ -26,9 +27,29 @@ describe('Directive: WizardNav', function () {
req.send();
}));

beforeEach(inject(function ($rootScope, $compile, _StepFactory_, _Wizard_) {
beforeEach(inject(function ($templateCache) {
var templateUrl = 'partials/confirmSessionReset.html';
var asynchronous = false;

var req = new XMLHttpRequest();
req.onload = function () {
$templateCache.put(templateUrl, this.responseText);
};
req.open('get', '/base/app/' + templateUrl, asynchronous);
req.send();
}));

beforeEach(inject(function ($rootScope, $compile, _StepFactory_, _Wizard_, _ngDialog_) {
StepFactory = _StepFactory_;
Wizard = _Wizard_;
ngDialog = _ngDialog_;

var mockNgDialogPromise = {
then: function(callback) {
callback('test');
}
};
spyOn(ngDialog, 'openConfirm').and.returnValue(mockNgDialogPromise);

scope = $rootScope.$new();

Expand Down Expand Up @@ -66,4 +87,20 @@ describe('Directive: WizardNav', function () {
it('should allow a completed step to be focusable', function () {
expect(jQuery('li.complete', element).hasClass('focusable')).toBeTruthy();
});

describe('when the navigating to /selectFile', function() {
it('should display a confirmation dialog', function() {
scope.$broadcast('$locationChangeStart', '#/selectFile');
scope.$digest();
expect(ngDialog.openConfirm).toHaveBeenCalled();
});
});

describe('when the navigating anywhere else', function() {
it('should not display the confirmation dialog', function() {
scope.$broadcast('$locationChangeStart', '#/test');
scope.$digest();
expect(ngDialog.openConfirm).not.toHaveBeenCalled();
});
});
});

0 comments on commit b85a1c3

Please sign in to comment.