diff --git a/src/app/build/items/item-slot.component.spec.ts b/src/app/build/items/item-slot.component.spec.ts new file mode 100644 index 0000000..32815a2 --- /dev/null +++ b/src/app/build/items/item-slot.component.spec.ts @@ -0,0 +1,56 @@ +//import {spyOn} from 'jasmine'; +import {it, inject, beforeEachProviders, beforeEach} from 'angular2/testing'; + +import {ItemsComponent} from './items.component'; +import {ItemSlotComponent} from './item-slot.component'; + +describe('ItemSlotComponent', () => { + beforeEachProviders(() => [ + ItemsComponent, + + ItemSlotComponent + ]); + + let item1; + let item2; + + beforeEach(inject([ItemSlotComponent], (component) => { + item1 = { + 'id': 3341, + 'gold': { 'total': 0 } + }; + + item2 = { + 'id': 2003, + 'gold': { 'total': 50 } + }; + + component.config = { g: [0, 100, 200, 300], gameTime: 200, sampleSize: 20 }; + component.items = [item1, item2, item2, item2]; + })); + + it('should add an item', inject([ItemSlotComponent], (component) => { + spyOn(component, 'addTime'); + spyOn(component, 'addBundle'); + expect(component.addTime).not.toHaveBeenCalled(); + expect(component.addBundle).not.toHaveBeenCalled(); + component.addItem(item1); + expect(component.addTime).toHaveBeenCalled(); + expect(component.addBundle).toHaveBeenCalled(); + expect(component.items[4]).toHaveEqualContent(item1); + })); + + it('should calculate time', inject([ItemSlotComponent], (component) => { + component.addTime(item1); + expect(item1['time']).toBe(0); + component.addTime(item2); + expect(item2['time']).toBe(5); + })); + + it('should bundle', inject([ItemSlotComponent], (component) => { + component.addTime(item2); + component.addBundle(item2); + expect(component.items.length).toBe(2); + expect(component.items[1].bundle).toBe(3); + })); +}); diff --git a/src/app/build/items/item-slot.component.ts b/src/app/build/items/item-slot.component.ts new file mode 100644 index 0000000..e80bb52 --- /dev/null +++ b/src/app/build/items/item-slot.component.ts @@ -0,0 +1,112 @@ +import {Component, Input, Inject, forwardRef, OnInit} from 'angular2/core'; +import {NgClass} from 'angular2/common'; +import {Observable} from 'rxjs/Observable'; + +import {ItemsComponent} from './items.component'; +import {ItemComponent} from './item.component'; +import {Config} from '../config'; + +import * as d3 from 'd3'; //TODO: remove test + +@Component({ + selector: 'item-slot', + directives: [NgClass, ItemComponent], + template: ` + ` +}) + +export class ItemSlotComponent implements OnInit { + @Input() id: number; + @Input() config: Config; + private items: Array = new Array(); + + // TODO: move to itemComponent when angular allows attributes on