blob: 1e853c02de1f08fe585b7494aa9b4f5baf8a2480 [file] [log] [blame]
Bri Prebilic Cole093739a2015-01-23 10:22:50 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 ONOS GUI -- Widget -- Table Service - Unit Tests
19 */
20describe('factory: fw/widget/table.js', function() {
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080021 var ts, $log, d3Elem;
22
23 var config = {
24 colIds: ['id', 'mfr', 'hw', 'sw', 'serial', 'annotations.protocol'],
25 colText: ['URI', 'Vendor', 'Hardware Version', 'Software Version',
26 'Serial Number', 'Protocol']
27 },
28 fakeData = {
29 "devices": [{
30 "id": "of:0000000000000001",
31 "available": true,
32 "_iconid_available": "deviceOnline",
33 "role": "MASTER",
34 "mfr": "Nicira, Inc.",
35 "hw": "Open vSwitch",
36 "sw": "2.0.1",
37 "serial": "None",
38 "annotations": {
39 "protocol": "OF_10"
40 }
41 },
42 {
43 "id": "of:0000000000000004",
44 "available": false,
45 "_iconid_available": "deviceOffline",
46 "role": "MASTER",
47 "mfr": "Nicira, Inc.",
48 "hw": "Open vSwitch",
49 "sw": "2.0.1",
50 "serial": "None",
51 "annotations": {
52 "protocol": "OF_10"
53 }
54 },
55 {
56 "id": "of:0000000000000092",
57 "available": false,
58 "_iconid_available": "deviceOffline",
59 "role": "MASTER",
60 "mfr": "Nicira, Inc.",
61 "hw": "Open vSwitch",
62 "sw": "2.0.1",
63 "serial": "None",
64 "annotations": {
65 "protocol": "OF_10"
66 }
67 }]
68 };
Bri Prebilic Cole093739a2015-01-23 10:22:50 -080069
70 beforeEach(module('onosWidget'));
71
72 beforeEach(inject(function (TableService, _$log_) {
73 ts = TableService;
74 $log = _$log_;
Simon Huntc4ae8302015-01-26 14:22:48 -080075 d3Elem = d3.select('body').append('div').attr('id', 'myDiv');
Bri Prebilic Cole093739a2015-01-23 10:22:50 -080076 }));
77
Simon Huntc4ae8302015-01-26 14:22:48 -080078 afterEach(function () {
79 d3.select('#myDiv').remove();
80 });
81
82
Bri Prebilic Cole093739a2015-01-23 10:22:50 -080083 it('should define TableService', function () {
84 expect(ts).toBeDefined();
85 });
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080086
87 function verifyTableTags(div) {
88 var table = div.select('table'),
89 tableHeaders;
90 expect(table).toBeTruthy();
91 expect(table.attr('fixed-header')).toBeTruthy();
92 expect(table.select('thead')).toBeTruthy();
93 expect(table.select('tbody')).toBeTruthy();
94
95 tableHeaders = table.select('thead').selectAll('th');
96 tableHeaders.each(function(thElement, i) {
97 thElement = d3.select(this);
98 expect(thElement).toBeTruthy();
99 expect(thElement.html()).toBe(config.colText[i]);
100 });
101 }
102
103 function verifyData(div) {
104 var tbody = div.select('tbody'),
105 tableBoxes = tbody.selectAll('td');
106 expect(tbody).toBeTruthy();
107 expect(tbody.select('tr')).toBeTruthy();
108
109 tableBoxes.each(function(tdElement, i){
110 tdElement = d3.select(this);
111 if(i === 0) {
112 expect(tdElement.html()).toBe('of:0000000000000001');
113 }
114 if(i === 1) {
115 expect(tdElement.html()).toBe('Nicira, Inc.');
116 }
117 if(i === 2) {
118 expect(tdElement.html()).toBe('Open vSwitch');
119 }
120 expect(tdElement).toBeTruthy();
121 });
122 }
123
124 it('should create table tags', function () {
125 ts.renderTable(d3Elem, config);
126 verifyTableTags(d3Elem);
127 });
128
129 it('should load data into table', function () {
130 var colIds = ts.renderTable(d3Elem, config);
131 ts.loadTableData(fakeData, d3Elem, colIds);
132 verifyData(d3Elem);
133 });
134
135 it('should render table and load data', function () {
136 ts.renderAndLoadTable(d3Elem, config, fakeData);
137 verifyData(d3Elem);
138 });
139
140});