This repository has been archived by the owner on Jun 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
NewStageDialogControllerSpec.js
112 lines (104 loc) · 3.73 KB
/
NewStageDialogControllerSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
describe('NewStageDialogController',function() {
var module;
var $scope, controller, handshakeMock;
beforeEach(function() {
module = factory('controllers/NewStageDialogController',{
'services/log': logMock,
});
angular.mock.module(module.name);
angular.mock.inject(function($controller,$rootScope,$q) {
$scope = $rootScope.$new();
handshakeMock = createHandshakeMock($q);
controller = $controller('NewStageDialogController', {
'$scope': $scope,
'$handshake': handshakeMock
});
});
});
describe('handshake receive',function() {
it('should show the dialog',function() {
handshakeMock.fire('newStage');
expect($scope.stage).toEqual({rounds:1});
expect($scope.dialogVisible).toBe(true);
expect($scope.generateId).toBe(true);
});
});
describe('nameChanged',function() {
it('should generate an id if id is not manually set',function() {
$scope.generateId = true;
$scope.stage.name = 'foo';
expect($scope.stage.id).toBeUndefined();
$scope.nameChanged();
expect($scope.stage.id).toBe('foo');
});
it('should not generate an id if id is manually set',function() {
$scope.generateId = false;
$scope.stage.name = 'foo';
expect($scope.stage.id).toBeUndefined();
$scope.nameChanged();
expect($scope.stage.id).toBeUndefined();
});
it('should create underscores for spaces and remove anything not valid as id',function() {
$scope.generateId = true;
$scope.stage.name = 'foo bar %&!baz[]//?';
$scope.nameChanged();
expect($scope.stage.id).toBe('foo_bar_baz');
});
});
describe('idChanged',function() {
it('should set the generateId flag to false as id is manually provided',function() {
$scope.idChanged();
expect($scope.generateId).toBe(false);
});
});
describe('ok ',function() {
it('should hide the dialog',function() {
handshakeMock.fire('newStage',{});
$scope.dialogVisible = true;
$scope.stage = {
name: 'foo',
rounds: 42
};
$scope.ok();
expect($scope.dialogVisible).toBe(false);
expect(handshakeMock.getPromise().resolve).toHaveBeenCalledWith({
stage: {
name: 'foo',
rounds: 42
}
});
});
});
describe('cancel',function() {
it('should hide the dialog',function() {
handshakeMock.fire('newStage',{});
$scope.dialogVisible = true;
$scope.cancel();
expect($scope.dialogVisible).toBe(false);
expect(handshakeMock.getPromise().resolve).toHaveBeenCalled();
});
});
describe('stageDefValid',function() {
it('should return false if id not filled in',function() {
$scope.stage = {
id: '',
name: 'foo'
};
expect($scope.stageDefValid()).toBe(false);
});
it('should return false if name not filled in',function() {
$scope.stage = {
id: 'foo',
name: ''
};
expect($scope.stageDefValid()).toBe(false);
});
it('should return true if name and id present not filled in',function() {
$scope.stage = {
id: 'foo',
name: 'foo'
};
expect($scope.stageDefValid()).toBe(true);
});
})
});