blob: 7d967f5463ec0a0b6631b1fcae85542629de6ca8 [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);
});
});