-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontroller-template-with-test-element.js
74 lines (60 loc) · 1.7 KB
/
controller-template-with-test-element.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
function templateController($scope) {
$scope.someArray = [{
id: 1,
name: 'Name1'
}, {
id: 2,
name: 'Name2'
}, {
id: 3,
name: 'Name3'
}];
$scope.addToArray = function(name) {
var item = {};
item.id = $scope.someArray.length + 1;
item.name = name;
$scope.someArray.push(item);
};
}
templateController.$inject = ['$scope'];
angular
.module('ctrlTemplateWithTE', [])
.controller('templateController', templateController);
describe('templateController', function() {
var
element;
beforeEach(module('ctrlTemplateWithTE'));
beforeEach(module('templates'));
beforeEach(function() {
element = new TestElement();
element.createCtrl('templateController');
element.addTemplate('examples/TestElement/template.html');
});
it('should not be null', function() {
expect(element).toBeTruthy();
});
it('should show 3 span elements', function() {
expect(element.findAll('span').length).toBe(3);
});
it('second span should have class1 class', function() {
expect(element.findAll('span')[1].hasClass('class1')).toBeTruthy();
});
describe('button', function() {
it('should have .button class', function() {
expect(element.find('button').hasClass('button')).toBeTruthy();
});
});
describe('Add new item', function() {
var newVal = 'newName';
beforeEach(function() {
element.inputOn('.new-item', newVal, 1).then(function() {
element.clickOn('.button');
});
});
it('should add new element to array', function() {
expect(element.findAll('span').length).toBe(4);
expect(element.dom.text()).toContain(newVal);
expect(element.scope.someArray[3].id).toBe(4);
});
});
});