blob: fcabb2e30c4fdcc952188884cede2b1166f14d86 [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"
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -080040 }
41 },
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080042 {
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
Bri Prebilic Cole093739a2015-01-23 10:22:50 -080082 it('should define TableService', function () {
83 expect(ts).toBeDefined();
84 });
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080085
86 function verifyTableTags(div) {
87 var table = div.select('table'),
88 tableHeaders;
89 expect(table).toBeTruthy();
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -080090 expect(table.attr('fixed-header')).toBeFalsy();
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080091 expect(table.select('thead')).toBeTruthy();
92 expect(table.select('tbody')).toBeTruthy();
93
94 tableHeaders = table.select('thead').selectAll('th');
95 tableHeaders.each(function(thElement, i) {
96 thElement = d3.select(this);
97 expect(thElement).toBeTruthy();
98 expect(thElement.html()).toBe(config.colText[i]);
99 });
100 }
101
102 function verifyData(div) {
103 var tbody = div.select('tbody'),
104 tableBoxes = tbody.selectAll('td');
105 expect(tbody).toBeTruthy();
106 expect(tbody.select('tr')).toBeTruthy();
107
108 tableBoxes.each(function(tdElement, i){
109 tdElement = d3.select(this);
110 if(i === 0) {
111 expect(tdElement.html()).toBe('of:0000000000000001');
112 }
113 if(i === 1) {
114 expect(tdElement.html()).toBe('Nicira, Inc.');
115 }
116 if(i === 2) {
117 expect(tdElement.html()).toBe('Open vSwitch');
118 }
119 expect(tdElement).toBeTruthy();
120 });
121 }
122
123 it('should create table tags', function () {
124 ts.renderTable(d3Elem, config);
125 verifyTableTags(d3Elem);
126 });
127
128 it('should load data into table', function () {
129 var colIds = ts.renderTable(d3Elem, config);
130 ts.loadTableData(fakeData, d3Elem, colIds);
131 verifyData(d3Elem);
132 });
133
134 it('should render table and load data', function () {
135 ts.renderAndLoadTable(d3Elem, config, fakeData);
136 verifyData(d3Elem);
137 });
138
139});