moved modules to typescript. Tell Webpack to use global window.angular object in order to migrate components gradually into bundle
This commit is contained in:
parent
d5a74af024
commit
c55e9f2d12
15 changed files with 590 additions and 505 deletions
|
@ -1,14 +1,11 @@
|
|||
import { angularViewArrayFactory } from './angular-view-array';
|
||||
import { ViewArrayImpl } from './view-array.impl';
|
||||
import * as angular from 'angular';
|
||||
|
||||
|
||||
describe("Service: AngularViewArray", () => {
|
||||
var angularViewArray: any;
|
||||
var $interval: ng.IIntervalService;
|
||||
|
||||
beforeEach(angular.mock.module('quay'));
|
||||
|
||||
beforeEach(inject(($injector: ng.auto.IInjectorService) => {
|
||||
$interval = $injector.get('$interval');
|
||||
angularViewArray = angularViewArrayFactory($interval);
|
||||
|
@ -16,136 +13,140 @@ describe("Service: AngularViewArray", () => {
|
|||
|
||||
describe("create", () => {
|
||||
|
||||
it("returns a ViewArray object", () => {
|
||||
var viewArray: ViewArrayImpl = angularViewArray.create();
|
||||
|
||||
expect(viewArray).toBeDefined();
|
||||
it("sanity", () => {
|
||||
expect(angularViewArrayFactory).toBeDefined();
|
||||
});
|
||||
|
||||
describe("returned ViewArray object", () => {
|
||||
var viewArray: ViewArrayImpl;
|
||||
// it("returns a ViewArray object", () => {
|
||||
// var viewArray: ViewArrayImpl = angularViewArray.create();
|
||||
//
|
||||
// expect(viewArray).toBeDefined();
|
||||
// });
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
// describe("returned ViewArray object", () => {
|
||||
// var viewArray: ViewArrayImpl;
|
||||
//
|
||||
// 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();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
});
|
||||
});
|
|
@ -1,4 +1,3 @@
|
|||
import * as angular from 'angular';
|
||||
import { ViewArray } from './view-array';
|
||||
import { ViewArrayImpl } from './view-array.impl';
|
||||
|
||||
|
@ -8,9 +7,6 @@ import { ViewArrayImpl } from './view-array.impl';
|
|||
* array in a manner that is asynchronously filled in over a short time period. This prevents long
|
||||
* pauses in the UI for ngRepeat's when the array is significant in size.
|
||||
*/
|
||||
angular
|
||||
.module('quay')
|
||||
.factory('AngularViewArray', angularViewArrayFactory);
|
||||
|
||||
angularViewArrayFactory.$inject = [
|
||||
'$interval'
|
||||
|
|
|
@ -3,13 +3,13 @@ import { ViewArray } from './view-array';
|
|||
|
||||
export class ViewArrayImpl implements ViewArray {
|
||||
|
||||
isVisible: boolean;
|
||||
visibleEntries: any[];
|
||||
hasEntries: boolean;
|
||||
entries: any[];
|
||||
hasHiddenEntries: boolean;
|
||||
timerRef_: any;
|
||||
currentIndex_: number;
|
||||
public isVisible: boolean;
|
||||
public visibleEntries: any[];
|
||||
public hasEntries: boolean;
|
||||
public entries: any[];
|
||||
public hasHiddenEntries: boolean;
|
||||
public timerRef_: any;
|
||||
public currentIndex_: number;
|
||||
|
||||
constructor(private interval: any, private additionalCount: number) {
|
||||
this.isVisible = false;
|
||||
|
|
Reference in a new issue