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
2017-01-18 15:46:37 -08:00

147 lines
No EOL
4.1 KiB
TypeScript

import IInjectorService = angular.auto.IInjectorService;
describe("Service: AngularViewArray", () => {
var angularViewArray: any;
beforeEach(angular.mock.module('quay'));
beforeEach(inject(($injector: IInjectorService) => {
angularViewArray = $injector.get('AngularViewArray');
}));
describe("create", () => {
it("returns a ViewArray object", () => {
var viewArray: any = angularViewArray.create();
expect(viewArray).toBeDefined();
});
describe("returned ViewArray object", () => {
var viewArray: any;
beforeEach(() => {
viewArray = angularViewArray.create();
});
describe("constructor", () => {
// TODO
});
describe("length", () => {
it("returns the number of entries", () => {
viewArray.entries = [{}, {}, {}];
expect(viewArray.length()).toEqual(viewArray.entries.length);
});
});
describe("get", () => {
it("returns the entry at a given index", () => {
var index: number = 8;
viewArray.entries = new Array(10);
viewArray.entries[index] = 3;
expect(viewArray.get(index)).toEqual(viewArray.entries[index]);
});
});
describe("push", () => {
it("adds given element to the end of entries", () => {
var element: number = 3;
var originalLength: number = viewArray.length();
viewArray.push(element);
expect(viewArray.entries.length).toEqual(originalLength + 1);
expect(viewArray.get(originalLength)).toEqual(element);
});
it("sets 'hasEntries' to true", () => {
viewArray.push(2);
expect(viewArray.hasEntries).toBe(true);
});
it("starts timer if 'isVisible' is true", () => {
spyOn(viewArray, "startTimer_").and.returnValue(null);
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);
viewArray.isVisible = false;
viewArray.push(2);
expect(viewArray.startTimer_).not.toHaveBeenCalled();
});
});
describe("toggle", () => {
it("sets 'isVisible' to false if currently true", () => {
viewArray.isVisible = true;
viewArray.toggle();
expect(viewArray.isVisible).toBe(false);
});
it("sets 'isVisible' to true if currently false", () => {
viewArray.isVisible = false;
viewArray.toggle();
expect(viewArray.isVisible).toBe(true);
});
});
describe("setVisible", () => {
it("sets 'isVisible' to false if given false", () => {
viewArray.setVisible(false);
expect(viewArray.isVisible).toBe(false);
});
it("sets 'visibleEntries' to empty array if given false", () => {
viewArray.setVisible(false);
expect(viewArray.visibleEntries.length).toEqual(0);
});
it("shows additional entries if given true", () => {
spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
viewArray.setVisible(true);
expect(viewArray.showAdditionalEntries_).toHaveBeenCalled();
});
it("does not show additional entries if given false", () => {
spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
viewArray.setVisible(false);
expect(viewArray.showAdditionalEntries_).not.toHaveBeenCalled();
});
it("starts timer if given true", () => {
spyOn(viewArray, "startTimer_").and.returnValue(null);
viewArray.setVisible(true);
expect(viewArray.startTimer_).toHaveBeenCalled();
});
it("stops timer if given false", () => {
spyOn(viewArray, "stopTimer_").and.returnValue(null);
viewArray.setVisible(true);
expect(viewArray.stopTimer_).toHaveBeenCalled();
});
});
});
});
});