blob: 82079fa38d3f5b7397e09f3eb25192e108c17c21 [file] [log] [blame]
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -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 -- Device Controller - Unit Tests
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080019 */
20describe('Controller: OvDeviceCtrl', function () {
Bri Prebilic Cole902cb042015-02-11 14:04:15 -080021 var $log, $scope, $controller, ctrl, $mockHttp;
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080022
23 var fakeData = {
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080024 "devices": [{
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080025 "id": "of:0000000000000001",
26 "available": true,
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080027 "mfr": "Nicira, Inc.",
28 "hw": "Open vSwitch",
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080029 "sw": "2.0.1"
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080030 },
31 {
32 "id": "of:0000000000000004",
33 "available": true,
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080034 "mfr": "Nicira, Inc.",
35 "hw": "Open vSwitch",
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080036 "sw": "2.0.1"
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080037 }]
38 };
39
Simon Hunt14caf7c2015-03-02 15:51:18 -080040 // instantiate the Device module
Simon Hunt9d286562015-03-09 13:53:50 -070041 beforeEach(module('ovDevice', 'onosRemote', 'onosLayer', 'onosSvg',
42 'onosNav', 'ngRoute'));
Simon Hunt14caf7c2015-03-02 15:51:18 -080043
Bri Prebilic Cole902cb042015-02-11 14:04:15 -080044 beforeEach(inject(function(_$log_, $rootScope, _$controller_, $httpBackend) {
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080045 $log = _$log_;
Bri Prebilic Cole902cb042015-02-11 14:04:15 -080046 $scope = $rootScope.$new();
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080047 $controller = _$controller_;
48 $mockHttp = $httpBackend;
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080049 }));
50
Bri Prebilic Colee1bda3f2015-02-13 17:01:49 -080051 beforeEach(function() {
Bri Prebilic Colee1bda3f2015-02-13 17:01:49 -080052 ctrl = $controller('OvDeviceCtrl', { $scope: $scope });
53 $mockHttp.whenGET(/\/device$/).respond(fakeData);
54 });
55
56
Bri Prebilic Cole19a32dd2015-03-26 18:00:03 -070057 // TODO: rewrite test to account for websocket
58 xit('should be an empty array and then have device data', function () {
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080059 expect(ctrl.deviceData).toEqual([]);
Bri Prebilic Cole902cb042015-02-11 14:04:15 -080060 $scope.sortCallback();
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080061 $mockHttp.flush();
62 expect(ctrl.deviceData).toEqual(fakeData.devices);
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080063 });
64
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080065});