blob: ad4a0235fe8dc0ed79d7029a367ff3a2960d9111 [file] [log] [blame]
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Jasmine test file for manager.js.
*/
describe('Manager', function() {
var testManager;
beforeEach(function() {
testManager = new Manager('0', 0);
});
it('should create a new manager instance', function() {
expect(testManager.id).toMatch('0');
expect(testManager.startTime).toEqual(0);
expect(testManager.services.length).toEqual(0);
expect(testManager.scans).toEqual(0);
expect(testManager.endTime).toEqual(-1);
});
it('should return the correct or new service when requested', function() {
var testService = new Service('0');
expect(testManager.services.length).toEqual(0);
expect(testManager.getService('0')).toEqual(testService);
expect(testManager.services.length).toEqual(1);
// When requested a second time, does not create a new service instance.
expect(testManager.getService('0')).toEqual(testService);
expect(testManager.services.length).toEqual(1);
});
it('should return the active service when requested', function() {
expect(testManager.getActiveService()).toBe(null);
var testService = testManager.getService('0');
expect(testManager.getActiveService()).toBe(null);
var inactiveUpdate = {state: 'Idle',
time: '2015-01-06T23:51:38.757505-08:00' };
var activeUpdate = {state: 'Online',
time: '2015-01-06T23:51:40.757505-08:00' };
testService.addUpdate(inactiveUpdate);
expect(testManager.getActiveService()).toBe(null);
testService.addUpdate(activeUpdate);
expect(testManager.getActiveService()).toEqual(testService);
});
it('should return the most recent active service when requested', function() {
var testService = testManager.getService('0');
var activeUpdate = {state: 'Online',
time: '2015-01-06T23:51:40.757505-08:00' };
testService.addUpdate(activeUpdate);
expect(testManager.getActiveService()).toEqual(testService);
var testService2 = testManager.getService('1');
var activeUpdate2 = {state: 'Online',
time: '2015-01-06T23:51:41.757505-08:00' };
testService2.addUpdate(activeUpdate2);
// TODO: need to implement this functionality
//expect(testManager.getActiveService()).toEqual(testService2);
});
it('should add series of supplicant states for graph', function() {
testManager.startTime = Date.parse('2015-01-06T23:51:40.755505-08:00');
var update = {time: '2015-01-06T23:51:40.760505-08:00',
oldState: 'DISCONNECTED',
newState: 'INTERFACE_DISABLED'};
testManager.addSupplicantState(update);
update = {time: '2015-01-06T23:51:40.761505-08:00',
oldState: 'INTERFACE_DISABLED',
newState: 'INACTIVE'};
testManager.addSupplicantState(update);
update = {time: '2015-01-06T23:51:40.762505-08:00',
oldState: 'INACTIVE',
newState: 'SCANNING'};
testManager.addSupplicantState(update);
var checkStates = testManager.supplicantStates;
expect(checkStates.length).toEqual(7);
expect(checkStates[0].x).toEqual(0);
expect(checkStates[1].x).toEqual(5);
expect(checkStates[0].y).toEqual('DISCONNECTED');
expect(checkStates[1].y).toEqual('DISCONNECTED');
expect(checkStates[5].x).toEqual(7);
expect(checkStates[6].x).toEqual(7);
expect(checkStates[5].y).toEqual('INACTIVE');
expect(checkStates[6].y).toEqual('SCANNING');
update = {time: '2015-01-06T23:51:40.763505-08:00',
oldState: 'AUTHENTICATING',
newState: 'AUTHENTICATED'};
testManager.addSupplicantState(update);
expect(checkStates.length).toEqual(11);
expect(checkStates[7].y).toEqual('SCANNING');
expect(checkStates[8].y).toEqual('AUTHENTICATING');
expect(checkStates[9].y).toEqual('AUTHENTICATING');
expect(checkStates[10].y).toEqual('AUTHENTICATED');
update = {time: '2015-01-06T23:51:40.764505-08:00',
oldState: 'AUTHENTICATED',
newState: 'AUTHENTICATED'};
testManager.addSupplicantState(update);
expect(checkStates.length).toEqual(11);
});
});