-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappSpec.js
executable file
·88 lines (71 loc) · 2.56 KB
/
appSpec.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
describe('Testing main controller', function() {
var $scope, ctrl, topologicalSortMock, result;
beforeEach(module('plunker'));
beforeEach(inject(function($rootScope, $controller) {
$scope = $rootScope.$new();
// mock the topologicalSort service with a fake result
result = "fake result";
topologicalSortMock = jasmine.createSpy().andReturn(result);
ctrl = $controller('MainCtrl', {
$scope: $scope,
topologicalSort: topologicalSortMock
});
}));
it('should exist', function () {
expect(!!ctrl).toBe(true);
});
describe("controller scope", function () {
it('should attach elements as an empty array', function () {
expect($scope.elements.length).toBe(0);
});
it('should attach form.select as null', function () {
expect($scope.form.select).toBeNull();
});
it('should attach form.text as an empty string', function () {
expect($scope.form.text).toBe("");
});
});
describe("add", function () {
var elementName;
beforeEach(function () {
$scope.form.text = elementName = "element added";
$scope.add();
});
it('should add an element', function () {
expect($scope.elements.length).toBe(1);
});
it('should add an element with the text as name', function () {
expect($scope.elements[0].name).toBe(elementName);
});
it('should reset form.text as an empty string', function () {
expect($scope.form.text).toBe("");
});
});
describe("requiredChanged", function () {
it('should invert the require value of the selected element to true', function () {
$scope.form.select = {name:"an element", require:{A:false}};
$scope.requiredChanged("A");
expect($scope.form.select.require["A"]).toBeTruthy();
});
it('should invert the require value of the selected element to false', function () {
$scope.form.select = {name:"an element", require:{A:true}};
$scope.requiredChanged("A");
expect($scope.form.select.require["A"]).toBeFalsy();
});
});
describe("sort", function () {
beforeEach(function () {
var a = {name:"A thing", require:{}};
var b = {name:"B", require:{}};
b.require[a.name] = true;
$scope.elements = [a, b];
$scope.sort();
});
it('should call the topologicalSort service with elements as parameter', function () {
expect(topologicalSortMock).toHaveBeenCalledWith($scope.elements);
});
it('should attach the result of the sort', function () {
expect($scope.result).toBe(result);
});
});
});