-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathdynamicData.spec.js
132 lines (98 loc) · 4.12 KB
/
dynamicData.spec.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
'use strict';
describe('Controller: DynamicDataCtrl', function() {
var $scope, $element;
beforeEach(module('app'));
beforeEach(inject(function($rootScope, $controller, $window){
$scope = $rootScope.$new();
$controller('DynamicDataCtrl', {
$scope: $scope,
$window: $window
});
}));
describe('the controller properties', function() {
it('should have properties in scope', function() {
expect($scope.cart.items.length).toEqual(0);
expect($scope.item.name).toEqual('');
expect($scope.item.qty).toEqual(0);
expect($scope.item.price).toEqual(0);
expect($scope.dashboardOptions.hideToolbar).toEqual(true);
expect($scope.dashboardOptions.widgetDefinitions.length).toEqual(2);
expect($scope.dashboardOptions.widgetDefinitions[0].name).toEqual('cartDetail');
expect($scope.dashboardOptions.widgetDefinitions[0].title).toEqual('cart detail');
expect($scope.dashboardOptions.widgetDefinitions[0].templateUrl).toEqual('app/template/cartDetail.html');
expect($scope.dashboardOptions.widgetDefinitions[0].size).toBeDefined();
expect($scope.dashboardOptions.widgetDefinitions[0].cart).toEqual($scope.cart);
expect($scope.dashboardOptions.widgetDefinitions[1].name).toEqual('cartSummary');
expect($scope.dashboardOptions.widgetDefinitions[1].title).toEqual('cart summary');
expect($scope.dashboardOptions.widgetDefinitions[1].templateUrl).toEqual('app/template/cartSummary.html');
expect($scope.dashboardOptions.widgetDefinitions[1].size).toBeDefined();
expect($scope.dashboardOptions.widgetDefinitions[1].cart).toEqual($scope.cart);
expect($scope.dashboardOptions.defaultWidgets).toBeDefined();
expect($scope.dashboardOptions.storage).toBeDefined();
expect($scope.dashboardOptions.storageId).toEqual('demo_dynamic-data');
});
});
describe('the addItem method', function() {
it('should add item to cart', function() {
// simulate user filling the inputs and click Add
$scope.item.name = 'Apple';
$scope.item.qty = 2;
$scope.item.price = .75;
$scope.addItem();
expect($scope.cart.items.length).toEqual(1);
expect($scope.item.name).toEqual('');
expect($scope.item.qty).toEqual(0);
expect($scope.item.price).toEqual(0);
});
it('should not add item with blank name', function() {
$scope.item.qty = 2;
$scope.item.price = .75;
$scope.addItem();
expect($scope.cart.items.length).toEqual(0);
});
it('should not add item with qty 0', function() {
$scope.item.name = 'Apple';
$scope.item.price = .75;
$scope.addItem();
expect($scope.cart.items.length).toEqual(0);
});
it('should not add item with price 0', function() {
$scope.item.name = 'Apple';
$scope.item.qty = 2;
$scope.addItem();
expect($scope.cart.items.length).toEqual(0);
});
});
describe('the autoFillCart method', function() {
it('should fill cart with sample items', function() {
$scope.autoFillCart();
expect($scope.cart.items.length).toEqual(6);
});
});
});
describe('Controller: CartCtrl', function() {
var $scope, $element, CartDataModel;
beforeEach(module('app'));
beforeEach(inject(function($rootScope, $controller, _CartDataModel_) {
CartDataModel = _CartDataModel_;
$scope = $rootScope.$new();
$scope.cart = new CartDataModel();
$scope.cart.addItem({ name: 'Apple', qty: 2, price: .55 });
$scope.cart.addItem({ name: 'Banana', qty: 5, price: .75 });
$scope.cart.addItem({ name: 'Orange', qty: 3, price: .35 });
$controller('CartCtrl', { $scope: $scope });
}));
describe('the controller properties', function() {
it('should have cart in scope', function() {
expect($scope.cart.items.length).toEqual(3);
});
});
describe('the removeItem method', function() {
it('should remove one item', function() {
$scope.removeItem($scope.cart.items[1]);
expect($scope.cart.items.length).toEqual(2);
expect($scope.cart.items[0].name).toEqual('Apple');
expect($scope.cart.items[1].name).toEqual('Orange');
});
});
});