From ead2acc2d43f07e8a39eb5a21f9ffb6f5f80be63 Mon Sep 17 00:00:00 2001 From: Steve Van Opstal Date: Sat, 16 Apr 2016 10:47:14 +0200 Subject: [PATCH] feat(preview): initial implementation --- .../build/items/item-slot.component.spec.ts | 56 ++++++++ src/app/build/items/item-slot.component.ts | 112 +++++++++++++++ src/app/build/items/item.component.ts | 2 +- src/app/build/items/items.component.spec.ts | 104 +++++--------- src/app/build/items/items.component.ts | 124 +++++++---------- src/app/build/shop/item.component.ts | 3 +- src/app/build/shop/preview/item-bundle.ts | 4 + src/app/build/shop/preview/item.component.ts | 15 ++ .../shop/preview/items-from.component.ts | 25 ++++ .../build/shop/preview/preview.component.ts | 99 ++++++++++++++ src/app/build/shop/shop.component.spec.ts | 54 ++++---- src/app/build/shop/shop.component.ts | 129 ++++++++++-------- src/app/misc/lolapi.service.ts | 2 +- src/app/routes/build.component.ts | 5 +- src/assets/css/base.css | 2 +- src/assets/css/build.css | 124 ++++++++++++++--- 16 files changed, 599 insertions(+), 261 deletions(-) create mode 100644 src/app/build/items/item-slot.component.spec.ts create mode 100644 src/app/build/items/item-slot.component.ts create mode 100644 src/app/build/shop/preview/item-bundle.ts create mode 100644 src/app/build/shop/preview/item.component.ts create mode 100644 src/app/build/shop/preview/items-from.component.ts create mode 100644 src/app/build/shop/preview/preview.component.ts 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