Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 1 | /* |
| 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 Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 19 | */ |
| 20 | describe('Controller: OvDeviceCtrl', function () { |
Bri Prebilic Cole | 902cb04 | 2015-02-11 14:04:15 -0800 | [diff] [blame] | 21 | var $log, $scope, $controller, ctrl, $mockHttp; |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 22 | |
| 23 | var fakeData = { |
Bri Prebilic Cole | 4fab8af | 2015-01-15 16:40:47 -0800 | [diff] [blame] | 24 | "devices": [{ |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 25 | "id": "of:0000000000000001", |
| 26 | "available": true, |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 27 | "mfr": "Nicira, Inc.", |
| 28 | "hw": "Open vSwitch", |
Bri Prebilic Cole | 4fab8af | 2015-01-15 16:40:47 -0800 | [diff] [blame] | 29 | "sw": "2.0.1" |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 30 | }, |
| 31 | { |
| 32 | "id": "of:0000000000000004", |
| 33 | "available": true, |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 34 | "mfr": "Nicira, Inc.", |
| 35 | "hw": "Open vSwitch", |
Bri Prebilic Cole | 4fab8af | 2015-01-15 16:40:47 -0800 | [diff] [blame] | 36 | "sw": "2.0.1" |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 37 | }] |
| 38 | }; |
| 39 | |
Simon Hunt | 14caf7c | 2015-03-02 15:51:18 -0800 | [diff] [blame] | 40 | // instantiate the Device module |
Simon Hunt | 9d28656 | 2015-03-09 13:53:50 -0700 | [diff] [blame] | 41 | beforeEach(module('ovDevice', 'onosRemote', 'onosLayer', 'onosSvg', |
| 42 | 'onosNav', 'ngRoute')); |
Simon Hunt | 14caf7c | 2015-03-02 15:51:18 -0800 | [diff] [blame] | 43 | |
Bri Prebilic Cole | 902cb04 | 2015-02-11 14:04:15 -0800 | [diff] [blame] | 44 | beforeEach(inject(function(_$log_, $rootScope, _$controller_, $httpBackend) { |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 45 | $log = _$log_; |
Bri Prebilic Cole | 902cb04 | 2015-02-11 14:04:15 -0800 | [diff] [blame] | 46 | $scope = $rootScope.$new(); |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 47 | $controller = _$controller_; |
| 48 | $mockHttp = $httpBackend; |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 49 | })); |
| 50 | |
Bri Prebilic Cole | e1bda3f | 2015-02-13 17:01:49 -0800 | [diff] [blame] | 51 | beforeEach(function() { |
Bri Prebilic Cole | e1bda3f | 2015-02-13 17:01:49 -0800 | [diff] [blame] | 52 | ctrl = $controller('OvDeviceCtrl', { $scope: $scope }); |
| 53 | $mockHttp.whenGET(/\/device$/).respond(fakeData); |
| 54 | }); |
| 55 | |
| 56 | |
Bri Prebilic Cole | 19a32dd | 2015-03-26 18:00:03 -0700 | [diff] [blame] | 57 | // TODO: rewrite test to account for websocket |
| 58 | xit('should be an empty array and then have device data', function () { |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 59 | expect(ctrl.deviceData).toEqual([]); |
Bri Prebilic Cole | 902cb04 | 2015-02-11 14:04:15 -0800 | [diff] [blame] | 60 | $scope.sortCallback(); |
Bri Prebilic Cole | 4fab8af | 2015-01-15 16:40:47 -0800 | [diff] [blame] | 61 | $mockHttp.flush(); |
| 62 | expect(ctrl.deviceData).toEqual(fakeData.devices); |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 63 | }); |
| 64 | |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 65 | }); |