Skip to content

Commit

Permalink
feat(lolapi): ignore unkown regions
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveVanOpstal committed Jul 8, 2016
1 parent b1bb98a commit 80a5057
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 213 deletions.
25 changes: 7 additions & 18 deletions src/client/build/build.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {provide} from '@angular/core';
import {addProviders, async, iit, inject, it} from '@angular/core/testing';
import {BaseRequestOptions, Http, Response, ResponseOptions} from '@angular/http';
import {BaseRequestOptions, Http} from '@angular/http';
import {MockBackend, MockConnection} from '@angular/http/testing';
import {ActivatedRoute, Router} from '@angular/router';

import {LolApiService} from '../misc/lolapi.service';
import {MockActivatedRoute} from '../testing';
import {MockActivatedRoute, MockMockBackend} from '../testing';

import {BuildComponent} from './build.component';

Expand All @@ -14,7 +14,7 @@ describe('BuildComponent', () => {
addProviders([
{provide: ActivatedRoute, useValue: new MockActivatedRoute()},

BaseRequestOptions, MockBackend, {
BaseRequestOptions, {provide: MockBackend, useValue: new MockMockBackend()}, {
provide: Http,
useFactory: function(backend, defaultOptions) {
return new Http(backend, defaultOptions);
Expand Down Expand Up @@ -52,10 +52,7 @@ describe('BuildComponent', () => {
it('should handle a champion request',
async(
inject([MockBackend, BuildComponent, LolApiService], (mockBackend, component, service) => {
let mockResponse = new Response(new ResponseOptions({status: 200, body: [{}]}));
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockRespond(mockResponse);
});
mockBackend.subscribe(false, {});

expect(component.champion).not.toBeDefined();
component.getData();
Expand All @@ -72,9 +69,7 @@ describe('BuildComponent', () => {
it('should handle a champion error',
async(
inject([MockBackend, BuildComponent, LolApiService], (mockBackend, component, service) => {
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockError();
});
mockBackend.subscribe();

expect(component.champion).not.toBeDefined();
component.getData();
Expand All @@ -93,11 +88,7 @@ describe('BuildComponent', () => {
async(
inject([MockBackend, BuildComponent, LolApiService], (mockBackend, component, service) => {
let samples = {xp: [0, 1], gold: [0, 1]};
let mockResponse =
new Response(new ResponseOptions({status: 200, body: {xp: [0, 1], gold: [0, 1]}}));
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockRespond(mockResponse);
});
mockBackend.subscribe(false, samples);

expect(component.samples).toBeDefined();
component.getMatchData('');
Expand All @@ -115,9 +106,7 @@ describe('BuildComponent', () => {
async(
inject([MockBackend, BuildComponent, LolApiService], (mockBackend, component, service) => {
let samples = {xp: [0, 1], gold: [0, 1]};
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockError();
});
mockBackend.subscribe();

expect(component.samples).toBeDefined();
component.getMatchData('');
Expand Down
76 changes: 32 additions & 44 deletions src/client/build/masteries/masteries.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {provide} from '@angular/core';
import {ComponentFixture, TestComponentBuilder, addProviders, async, beforeEach, inject, it} from '@angular/core/testing';
import {BaseRequestOptions, Http, Response, ResponseOptions} from '@angular/http';
import {BaseRequestOptions, Http} from '@angular/http';
import {MockBackend, MockConnection} from '@angular/http/testing';
import {ActivatedRoute} from '@angular/router';

import {LolApiService} from '../../misc/lolapi.service';
import {MockActivatedRoute} from '../../testing';
import {MockActivatedRoute, MockMockBackend} from '../../testing';

import {MasteriesComponent} from './masteries.component';
import {MasteryCategoryComponent} from './mastery-category.component';
Expand Down Expand Up @@ -70,12 +70,12 @@ const masteriesDataAltered = [
}
];

describe('MasteriesComponent', () => {
let providers = () => {
beforeEach(() => {
addProviders([
{provide: ActivatedRoute, useValue: new MockActivatedRoute()},

BaseRequestOptions, MockBackend, {
BaseRequestOptions, {provide: MockBackend, useValue: new MockMockBackend()}, {
provide: Http,
useFactory: function(backend, defaultOptions) {
return new Http(backend, defaultOptions);
Expand All @@ -86,21 +86,20 @@ describe('MasteriesComponent', () => {
LolApiService, MasteryCategoryComponent, MasteriesComponent
]);
});
};

describe('MasteriesComponent', () => {
providers();

let mockResponse = new Response(new ResponseOptions({status: 200, body: masteriesData}));
let component: MasteriesComponent;
beforeEach(async(inject(
[MockBackend, TestComponentBuilder],
(mockBackend: MockBackend, tcb: TestComponentBuilder) => {
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockRespond(mockResponse);
});
tcb.createAsync(MasteriesComponent)
.then((fixture: ComponentFixture<MasteriesComponent>) => {
fixture.detectChanges();
component = fixture.componentInstance;
});
})));
beforeEach(async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.createAsync(MasteriesComponent).then((fixture: ComponentFixture<MasteriesComponent>) => {
fixture.detectChanges();
component = fixture.componentInstance;
component.data = masteriesDataAltered;
fixture.detectChanges();
});
})));

it('should be initialised', () => {
expect(component.data).toBeDefined();
Expand Down Expand Up @@ -173,42 +172,31 @@ describe('MasteriesComponent', () => {
expect(mastery1.getRank()).toBe(0);
expect(mastery3.getRank()).toBe(30);
});

it('should get masteries', async(inject([LolApiService], (service: LolApiService) => {
component.ngOnInit();
return service.getMasteries()
.toPromise()
.then(() => {
expect(component.data).toHaveEqualContent(masteriesDataAltered);
})
.catch(() => {
expect(false).toBeTruthy();
});
})));
});

describe('MasteriesComponent', () => {
beforeEach(() => {
addProviders([
{provide: ActivatedRoute, useValue: new MockActivatedRoute()},
providers();

MockBackend, BaseRequestOptions, provide(Http, {
useFactory: (backend, defaultOptions) => {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
}),
it('should get masteries',
async(inject(
[MockBackend, MasteriesComponent, LolApiService],
(mockBackend, component: MasteriesComponent, service: LolApiService) => {
mockBackend.subscribe(false, masteriesData);

LolApiService, MasteryCategoryComponent, MasteriesComponent
]);
});
component.ngOnInit();
return service.getMasteries().subscribe(
() => {
expect(component.data).toHaveEqualContent(masteriesDataAltered);
},
() => {
fail('unexpected failure');
});
})));

it('should not get masteries',
async(inject(
[MockBackend, MasteriesComponent, LolApiService], (mockBackend, component, service) => {
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockError();
});
mockBackend.subscribe();

spyOn(component, 'alterData');
expect(component.alterData).not.toHaveBeenCalled();
Expand Down
26 changes: 11 additions & 15 deletions src/client/build/shop/shop.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {provide} from '@angular/core';
import {addProviders, async, beforeEach, inject, it} from '@angular/core/testing';
import {BaseRequestOptions, Http, Response, ResponseOptions} from '@angular/http';
import {BaseRequestOptions, Http} from '@angular/http';
import {MockBackend, MockConnection} from '@angular/http/testing';
import {ActivatedRoute} from '@angular/router';

import {LolApiService} from '../../misc/lolapi.service';
import {MockActivatedRoute} from '../../testing';
import {MockActivatedRoute, MockMockBackend} from '../../testing';

import {ShopComponent} from './shop.component';

Expand All @@ -18,7 +18,7 @@ describe('ShopComponent', () => {
addProviders([
{provide: ActivatedRoute, useValue: new MockActivatedRoute()},

BaseRequestOptions, MockBackend, {
BaseRequestOptions, {provide: MockBackend, useValue: new MockMockBackend()}, {
provide: Http,
useFactory: function(backend, defaultOptions) {
return new Http(backend, defaultOptions);
Expand All @@ -40,20 +40,18 @@ describe('ShopComponent', () => {
groups: [{MaxGroupOwnable: 2, key: 'PinkWards'}, {MaxGroupOwnable: -1, key: 'DoransItems'}]
};

it('should call getData() on contruct', inject([LolApiService], (service) => {
spyOn(ShopComponent.prototype, 'getData');
expect(ShopComponent.prototype.getData).not.toHaveBeenCalled();
let component = new ShopComponent(service);
expect(ShopComponent.prototype.getData).toHaveBeenCalled();
it('should get data',
inject([MockBackend, ShopComponent, LolApiService], (mockBackend, component, service) => {
spyOn(component, 'getData');
expect(component.getData).not.toHaveBeenCalled();
component.ngOnInit();
expect(component.getData).toHaveBeenCalled();
}));

it('should get items',
async(
inject([MockBackend, ShopComponent, LolApiService], (mockBackend, component, service) => {
let mockResponse = new Response(new ResponseOptions({status: 200, body: [{}]}));
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockRespond(mockResponse);
});
mockBackend.subscribe(false, []);

expect(component.items).toHaveEqualContent([]);
expect(component.originalItems).toHaveEqualContent([]);
Expand All @@ -72,9 +70,7 @@ describe('ShopComponent', () => {
it('should not get items',
async(
inject([MockBackend, ShopComponent, LolApiService], (mockBackend, component, service) => {
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockError();
});
mockBackend.subscribe();

expect(component.items).toHaveEqualContent([]);
expect(component.originalItems).toHaveEqualContent([]);
Expand Down
6 changes: 2 additions & 4 deletions src/client/build/shop/shop.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ export class ShopComponent implements OnInit {
private originalItems: Array<any> = [];
private pickedItem: Object;

constructor(private lolApi: LolApiService) {
this.getData();
}
constructor(private lolApi: LolApiService) {}

ngOnInit() {
this.getData();
Expand All @@ -107,7 +105,7 @@ export class ShopComponent implements OnInit {
() => this.loading = false);
}

// ngOnChanges(changes: { [key: string]: SimpleChange; }) {
// ngOnChanges(changes: SimpleChanges) {
// if (!changes['pickedItems'] || !changes['pickedItems'].currentValue) {
// return;
// }
Expand Down
15 changes: 5 additions & 10 deletions src/client/champions/champions.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {provide} from '@angular/core';
import {addProviders, async, inject, it} from '@angular/core/testing';
import {BaseRequestOptions, Http, Response, ResponseOptions} from '@angular/http';
import {BaseRequestOptions, Http} from '@angular/http';
import {MockBackend, MockConnection} from '@angular/http/testing';
import {ActivatedRoute, Router} from '@angular/router';

import {LolApiService} from '../misc/lolapi.service';
import {MockActivatedRoute, MockRouter} from '../testing';
import {MockActivatedRoute, MockMockBackend, MockRouter} from '../testing';

import {ChampionsComponent} from './champions.component';

Expand All @@ -14,7 +14,7 @@ describe('ChampionsComponent', () => {
addProviders([
{provide: ActivatedRoute, useValue: new MockActivatedRoute()},

BaseRequestOptions, MockBackend, {
BaseRequestOptions, {provide: MockBackend, useValue: new MockMockBackend()}, {
provide: Http,
useFactory: function(backend, defaultOptions) {
return new Http(backend, defaultOptions);
Expand All @@ -38,10 +38,7 @@ describe('ChampionsComponent', () => {
it('should get champions',
async(inject(
[MockBackend, ChampionsComponent, LolApiService], (mockBackend, component, service) => {
let mockResponse = new Response(new ResponseOptions({status: 200, body: [{}]}));
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockRespond(mockResponse);
});
mockBackend.subscribe(false, {});

expect(component.champions).not.toBeDefined();
component.getData();
Expand All @@ -58,9 +55,7 @@ describe('ChampionsComponent', () => {
it('should not get champions',
async(inject(
[MockBackend, ChampionsComponent, LolApiService], (mockBackend, component, service) => {
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockError();
});
mockBackend.subscribe();

expect(component.champions).not.toBeDefined();
component.getData();
Expand Down
6 changes: 3 additions & 3 deletions src/client/misc/ddragon.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {LocationStrategy} from '@angular/common';
import {SpyLocation} from '@angular/common/testing';
import {ElementRef, provide} from '@angular/core';
import {addProviders, async, beforeEach, inject, it} from '@angular/core/testing';
import {BaseRequestOptions, Http, Response, ResponseOptions} from '@angular/http';
import {ComponentFixture, TestComponentBuilder, addProviders, async, beforeEach, inject, it} from '@angular/core/testing';
import {BaseRequestOptions, Http} from '@angular/http';
import {MockBackend, MockConnection} from '@angular/http/testing';
import {ActivatedRoute, Router, RouterOutletMap, UrlSerializer} from '@angular/router';

import {LolApiService} from '../misc/lolapi.service';
import {MockActivatedRoute} from '../testing';
import {MockActivatedRoute, MockMockBackend} from '../testing';

import {DDragonDirective} from './ddragon.directive';

Expand Down
Loading

0 comments on commit 80a5057

Please sign in to comment.