blob: 532d5f198f251e8ae050cb90a3cf26b3bef57818 [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 service.js
*/
describe('Service', function() {
var testService;
beforeEach(function() {
testService = new Service('0');
});
it('should create a new service instance', function() {
expect(testService.serviceId).toMatch('0');
expect(testService.states.length).toEqual(0);
expect(testService.isActive).toBe(false);
expect(testService.connections).toEqual(0);
});
it('should be able to add a state update', function() {
var update1 = {state: 'Online', time: '2015-01-06T23:51:38.757505-08:00' };
testService.addUpdate(update1);
expect(testService.states.length).toEqual(1);
expect(testService.isActive).toBe(true);
expect(testService.connections).toEqual(0);
});
it('should distinguish between types of state updates', function() {
var update1 = {state: 'Idle', time: '2015-01-06T23:51:38.757505-08:00' };
var update2 = {state: 'Associating',
time: '2015-01-06T23:51:39.757505-08:00' };
var update3 = {state: 'Online', time: '2015-01-06T23:51:40.757505-08:00' };
var update4 = {state: 'Associating',
time: '2015-01-06T23:51:41.757505-08:00' };
testService.addUpdate(update1);
expect(testService.states.length).toEqual(1);
expect(testService.isActive).toBe(false);
expect(testService.connections).toEqual(0);
testService.addUpdate(update2);
expect(testService.states.length).toEqual(2);
expect(testService.isActive).toBe(true);
expect(testService.connections).toEqual(1);
testService.addUpdate(update3);
testService.addUpdate(update4);
expect(testService.states.length).toEqual(4);
expect(testService.isActive).toBe(true);
expect(testService.connections).toEqual(2);
});
it('should properly update the number of connection attempts', function() {
var update1 = {state: 'Associating',
time: '2015-01-06T23:51:38.757505-08:00' };
var update2 = {state: 'Connected',
time: '2015-01-06T23:51:39.757505-08:00' };
var update3 = {state: 'Online', time: '2015-01-06T23:51:40.757505-08:00' };
var update4 = {state: 'Associating',
time: '2015-01-06T23:51:41.757505-08:00' };
testService.addUpdate(update1);
expect(testService.states.length).toEqual(1);
expect(testService.isActive).toBe(true);
expect(testService.connections).toEqual(1);
testService.addUpdate(update2);
expect(testService.states.length).toEqual(2);
expect(testService.isActive).toBe(true);
expect(testService.connections).toEqual(1);
testService.addUpdate(update3);
testService.addUpdate(update4);
expect(testService.states.length).toEqual(4);
expect(testService.isActive).toBe(true);
expect(testService.connections).toEqual(2);
});
it('should return the current update when requested', function() {
var currentUpdate = testService.getCurrentUpdate();
expect(currentUpdate).toEqual(null);
var update1 = {state: 'Online', time: '2015-01-06T23:51:38.757505-08:00' };
testService.addUpdate(update1);
expect(testService.getCurrentUpdate()).toEqual(update1);
});
});