2017-01-19 06:10:43 +00:00
|
|
|
import { angularViewArrayFactory } from './angular-view-array';
|
|
|
|
import { ViewArrayImpl } from './view-array.impl';
|
|
|
|
import * as angular from 'angular';
|
2017-01-07 08:28:02 +00:00
|
|
|
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
describe("Service: AngularViewArray", () => {
|
|
|
|
var angularViewArray: any;
|
2017-01-19 06:10:43 +00:00
|
|
|
var $interval: ng.IIntervalService;
|
2017-01-18 23:46:37 +00:00
|
|
|
|
|
|
|
beforeEach(angular.mock.module('quay'));
|
|
|
|
|
2017-01-19 06:10:43 +00:00
|
|
|
beforeEach(inject(($injector: ng.auto.IInjectorService) => {
|
|
|
|
$interval = $injector.get('$interval');
|
|
|
|
angularViewArray = angularViewArrayFactory($interval);
|
2017-01-07 08:28:02 +00:00
|
|
|
}));
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
describe("create", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("returns a ViewArray object", () => {
|
2017-01-19 06:10:43 +00:00
|
|
|
var viewArray: ViewArrayImpl = angularViewArray.create();
|
2017-01-07 08:28:02 +00:00
|
|
|
|
|
|
|
expect(viewArray).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
describe("returned ViewArray object", () => {
|
2017-01-19 06:10:43 +00:00
|
|
|
var viewArray: ViewArrayImpl;
|
2017-01-07 08:28:02 +00:00
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
beforeEach(() => {
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray = angularViewArray.create();
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
describe("constructor", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
// TODO
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
describe("length", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("returns the number of entries", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.entries = [{}, {}, {}];
|
|
|
|
|
|
|
|
expect(viewArray.length()).toEqual(viewArray.entries.length);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
describe("get", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("returns the entry at a given index", () => {
|
|
|
|
var index: number = 8;
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.entries = new Array(10);
|
|
|
|
viewArray.entries[index] = 3;
|
|
|
|
|
|
|
|
expect(viewArray.get(index)).toEqual(viewArray.entries[index]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
describe("push", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("adds given element to the end of entries", () => {
|
|
|
|
var element: number = 3;
|
|
|
|
var originalLength: number = viewArray.length();
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.push(element);
|
|
|
|
|
|
|
|
expect(viewArray.entries.length).toEqual(originalLength + 1);
|
|
|
|
expect(viewArray.get(originalLength)).toEqual(element);
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("sets 'hasEntries' to true", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.push(2);
|
|
|
|
|
|
|
|
expect(viewArray.hasEntries).toBe(true);
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("starts timer if 'isVisible' is true", () => {
|
|
|
|
spyOn(viewArray, "startTimer_").and.returnValue(null);
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.isVisible = true;
|
|
|
|
viewArray.push(2);
|
|
|
|
|
|
|
|
expect(viewArray.startTimer_).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("does not start timer if 'isVisible' is false", () => {
|
|
|
|
spyOn(viewArray, "startTimer_").and.returnValue(null);
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.isVisible = false;
|
|
|
|
viewArray.push(2);
|
|
|
|
|
|
|
|
expect(viewArray.startTimer_).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
describe("toggle", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("sets 'isVisible' to false if currently true", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.isVisible = true;
|
|
|
|
viewArray.toggle();
|
|
|
|
|
|
|
|
expect(viewArray.isVisible).toBe(false);
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("sets 'isVisible' to true if currently false", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.isVisible = false;
|
|
|
|
viewArray.toggle();
|
|
|
|
|
|
|
|
expect(viewArray.isVisible).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
describe("setVisible", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("sets 'isVisible' to false if given false", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.setVisible(false);
|
|
|
|
|
|
|
|
expect(viewArray.isVisible).toBe(false);
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("sets 'visibleEntries' to empty array if given false", () => {
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.setVisible(false);
|
|
|
|
|
|
|
|
expect(viewArray.visibleEntries.length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("shows additional entries if given true", () => {
|
|
|
|
spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.setVisible(true);
|
|
|
|
|
|
|
|
expect(viewArray.showAdditionalEntries_).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("does not show additional entries if given false", () => {
|
|
|
|
spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.setVisible(false);
|
|
|
|
|
|
|
|
expect(viewArray.showAdditionalEntries_).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("starts timer if given true", () => {
|
|
|
|
spyOn(viewArray, "startTimer_").and.returnValue(null);
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.setVisible(true);
|
|
|
|
|
|
|
|
expect(viewArray.startTimer_).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2017-01-18 23:46:37 +00:00
|
|
|
it("stops timer if given false", () => {
|
|
|
|
spyOn(viewArray, "stopTimer_").and.returnValue(null);
|
2017-01-07 08:28:02 +00:00
|
|
|
viewArray.setVisible(true);
|
|
|
|
|
|
|
|
expect(viewArray.stopTimer_).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|