This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/services/angular-view-array/angular-view-array.spec.ts

148 lines
4.1 KiB
TypeScript
Raw Normal View History

import IInjectorService = angular.auto.IInjectorService;
// import { ViewArrayImpl } from './view-array.impl';
2017-01-07 08:28:02 +00:00
describe("Service: AngularViewArray", () => {
var angularViewArray: any;
beforeEach(angular.mock.module('quay'));
beforeEach(inject(($injector: IInjectorService) => {
2017-01-07 08:28:02 +00:00
angularViewArray = $injector.get('AngularViewArray');
}));
describe("create", () => {
2017-01-07 08:28:02 +00:00
it("returns a ViewArray object", () => {
var viewArray: any = angularViewArray.create();
2017-01-07 08:28:02 +00:00
expect(viewArray).toBeDefined();
});
describe("returned ViewArray object", () => {
var viewArray: any;
2017-01-07 08:28:02 +00:00
beforeEach(() => {
2017-01-07 08:28:02 +00:00
viewArray = angularViewArray.create();
});
describe("constructor", () => {
2017-01-07 08:28:02 +00:00
// TODO
});
describe("length", () => {
2017-01-07 08:28:02 +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);
});
});
describe("get", () => {
2017-01-07 08:28:02 +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]);
});
});
describe("push", () => {
2017-01-07 08:28:02 +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);
});
it("sets 'hasEntries' to true", () => {
2017-01-07 08:28:02 +00:00
viewArray.push(2);
expect(viewArray.hasEntries).toBe(true);
});
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();
});
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();
});
});
describe("toggle", () => {
2017-01-07 08:28:02 +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);
});
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);
});
});
describe("setVisible", () => {
2017-01-07 08:28:02 +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);
});
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);
});
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();
});
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();
});
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();
});
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();
});
});
});
});
});