Skip to content

Commit

Permalink
test(): correct and add
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveVanOpstal committed Mar 31, 2016
1 parent d388f44 commit 363c4ff
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 37 deletions.
39 changes: 35 additions & 4 deletions src/app/build/masteries.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {provide, Inject, forwardRef} from 'angular2/core';
import {BaseRequestOptions, Http} from 'angular2/http';
import {provide} from 'angular2/core';
import {BaseRequestOptions, Http, Response, ResponseOptions} from 'angular2/http';
import {RouteParams} from 'angular2/router';
import {RootRouter} from 'angular2/src/router/router';

import {it, inject, beforeEach, beforeEachProviders} from 'angular2/testing';
import {MockBackend} from 'angular2/http/testing';
import {it, inject, injectAsync, beforeEach, beforeEachProviders} from 'angular2/testing';
import {MockBackend, MockConnection} from 'angular2/http/testing';

import {LolApiService} from '../misc/lolapi.service';
import {MasteryCategoryComponent} from './mastery-category.component';
Expand Down Expand Up @@ -86,6 +86,37 @@ describe('MasteryCategoryComponent', () => {
expect(component.enable).toHaveBeenCalled();
}));


it('should get masteries', injectAsync([MockBackend, MasteriesComponent, LolApiService], (mockBackend, component, service) => {
spyOn(component, 'alterData');
let mockResponse = new Response(new ResponseOptions({ status: 200, body: [{}] }));
mockBackend.connections.subscribe(
(connection: MockConnection) => {
connection.mockRespond(mockResponse);
});

expect(component.alterData).not.toHaveBeenCalled();
component.getData();
return service.getMasteries().toPromise().then(() => {
expect(component.alterData).toHaveBeenCalled();
});
}));

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

expect(component.alterData).not.toHaveBeenCalled();
component.getData();
return service.getMasteries().toPromise().catch(() => {
expect(component.alterData).not.toHaveBeenCalled();
});
}));


it('should alter data', inject([MasteriesComponent], (component) => {
let newMasteries = {
tree: {
Expand Down
24 changes: 24 additions & 0 deletions src/app/build/mastery-category.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ describe('MasteryCategoryComponent', () => {
}));


it('should add a tier', inject([MasteryCategoryComponent], (component) => {
let tier = new MockMasteryTierComponent(component, 4);
component.addTier(tier);
expect(component.tiers[4]).toBeDefined();
}));


it('should enable tier zero', inject([MasteryCategoryComponent], (component) => {
component.enable();
expect(component.tiers[0].masteries[0].enabled).toBeTruthy();
Expand Down Expand Up @@ -185,6 +192,23 @@ describe('MasteryCategoryComponent', () => {
}));


it('should do nothing when tier or mastery is incorrect', inject([MasteryCategoryComponent], (component) => {
component.tiers[0].masteries[0].rank = 1;

spyOn(component.masteries, 'rankRemoved');
component.rankRemoved(null, component.tiers[0].masteries[0]);
expect(component.masteries.rankRemoved).not.toHaveBeenCalled();
component.rankRemoved(component.tiers[0], null);
expect(component.masteries.rankRemoved).not.toHaveBeenCalled();

spyOn(component.masteries, 'rankAdded');
component.rankAdded(null, component.tiers[0].masteries[0]);
expect(component.masteries.rankAdded).not.toHaveBeenCalled();
component.rankAdded(component.tiers[0], null);
expect(component.masteries.rankAdded).not.toHaveBeenCalled();
}));


it('should get rank', inject([MasteryCategoryComponent], (component) => {
component.tiers[0].masteries[0].rank = 1;
component.tiers[2].masteries[0].rank = 5;
Expand Down
4 changes: 2 additions & 2 deletions src/app/build/mastery-category.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class MasteryCategoryComponent implements OnInit {
}

public rankAdded(tier: MasteryTierComponent, mastery: MasteryComponent) {
if (!tier) {
if (!tier || !mastery) {
return;
}
if (tier.getRank() === mastery.getMaxRank()) {
Expand All @@ -71,7 +71,7 @@ export class MasteryCategoryComponent implements OnInit {
}

public rankRemoved(tier: MasteryTierComponent, mastery: MasteryComponent) {
if (!tier) {
if (!tier || !mastery) {
return;
}
if (tier.getRank() < mastery.getMaxRank()) {
Expand Down
8 changes: 8 additions & 0 deletions src/app/build/mastery-tier.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ describe('MasteryTierComponent', () => {
}));


it('should add a mastery', inject([MasteryTierComponent], (component) => {
let mastery = new MasteryComponent(component);
component.addMastery(mastery);
expect(component.masteries[0]).toBeDefined();
expect(component.masteries[0].enabled).toBeTruthy();
}));


it('should enable', inject([MasteryTierComponent], (component) => {
component.enable();
for (let mastery in component.masteries) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/choose/filters.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {provide} from 'angular2/core';

import {it, inject, beforeEach, beforeEachProviders} from 'angular2/testing';
import {it, inject, beforeEachProviders} from 'angular2/testing';

import {FiltersComponent} from './filters.component';

Expand Down
2 changes: 1 addition & 1 deletion src/app/choose/name.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {provide} from 'angular2/core';

import {it, inject, beforeEachProviders} from 'angular2/testing';
import {it, inject, beforeEach, beforeEachProviders} from 'angular2/testing';

import {NamePipe} from './name.pipe';

Expand Down
6 changes: 3 additions & 3 deletions src/app/choose/sort.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {provide} from 'angular2/core';

import {it, inject, beforeEachProviders} from 'angular2/testing';
import {it, inject, beforeEach, beforeEachProviders} from 'angular2/testing';

import {SortPipe} from './sort.pipe';

Expand All @@ -14,7 +14,7 @@ describe('SortPipe', () => {
beforeEach(() => {
champions = [
{ id: 1, name: 'Amumu', info: { attack: 1, magic: 8, defense: 6, difficulty: 3 } },
{ id: 2, name: 'Ahri', info: { attack: 3, magic: 7, defense: 4, difficulty: 5 } },
{ id: 2, name: 'Ahri', info: { attack: 3, magic: 8, defense: 4, difficulty: 5 } },
{ id: 3, name: 'Vel\'Koz', info: { attack: 2, magic: 10, defense: 2, difficulty: 8 } }
];
});
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('SortPipe', () => {

it('should order by \'magic\'', inject([SortPipe], (pipe) => {
let championIds = getChampionIds(pipe.transform(champions, ['magic']));
expect(championIds).toHaveEqualContent([3, 1, 2]); // 'magic' order
expect(championIds[0]).toBe(3); // 'magic' order, order of id:1 and id:2 are unknown
}));

it('should order by \'defense\'', inject([SortPipe], (pipe) => {
Expand Down
20 changes: 10 additions & 10 deletions src/app/choose/tags.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {provide} from 'angular2/core';

import {it, inject, beforeEachProviders} from 'angular2/testing';
import {it, inject, beforeEach, beforeEachProviders} from 'angular2/testing';

import {TagsPipe} from './tags.pipe';

Expand All @@ -13,9 +13,9 @@ describe('TagsPipe', () => {

beforeEach(() => {
champions = [
{ name: 'Amumu', tags: ['tank', 'mage'] },
{ name: 'Ahri', tags: ['mage', 'assassin'] },
{ name: 'Tryndamere', tags: ['fighter', 'assassin'], }
{ name: 'Amumu', tags: ['Tank', 'Mage'] },
{ name: 'Ahri', tags: ['Mage', 'Assassin'] },
{ name: 'Tryndamere', tags: ['Fighter', 'Melee', 'Assassin'], }
];
});

Expand All @@ -35,39 +35,39 @@ describe('TagsPipe', () => {
}));

it('should not filter on invalid champions', inject([TagsPipe], (pipe) => {
champions = pipe.transform(null, [['tank']]);
champions = pipe.transform(null, [['Tank']]);
expect(champions).toBe(null);
}));

it('should filter by \'Mage\'', inject([TagsPipe], (pipe) => {
let championes = pipe.transform(champions, [['mage']]);
let championes = pipe.transform(champions, [['Mage']]);
let championNames = getChampionNames(championes);
expect(championNames.length).toBe(2);
expect(championNames).toContain('Amumu');
expect(championNames).toContain('Ahri');
}));

it('should filter by \'Mage, Tank\'', inject([TagsPipe], (pipe) => {
let championNames = getChampionNames(pipe.transform(champions, [['mage', 'tank']]));
let championNames = getChampionNames(pipe.transform(champions, [['Mage', 'Tank']]));
expect(championNames.length).toBe(1);
expect(championNames).toContain('Amumu');
}));

it('should filter by \'Assassin\'', inject([TagsPipe], (pipe) => {
let championNames = getChampionNames(pipe.transform(champions, [['assassin']]));
let championNames = getChampionNames(pipe.transform(champions, [['Assassin']]));
expect(championNames.length).toBe(2);
expect(championNames).toContain('Ahri');
expect(championNames).toContain('Tryndamere');
}));

it('should filter by \'Fighter\'', inject([TagsPipe], (pipe) => {
let championNames = getChampionNames(pipe.transform(champions, [['fighter']]));
let championNames = getChampionNames(pipe.transform(champions, [['Fighter']]));
expect(championNames.length).toBe(1);
expect(championNames).toContain('Tryndamere');
}));

it('should filter by \'Support\'', inject([TagsPipe], (pipe) => {
champions = pipe.transform(champions, [['support']]);
champions = pipe.transform(champions, [['Support']]);
expect(champions.length).toBe(0);
}));
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/misc/bar.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {provide} from 'angular2/core';
import {it, inject} from 'angular2/testing';
import {it, inject, beforeEachProviders} from 'angular2/testing';

import {BarComponent} from './bar.component';

Expand Down
31 changes: 21 additions & 10 deletions src/app/misc/ddragon.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {provide, ElementRef} from 'angular2/core';
import {Router, RouteRegistry, Location, ROUTER_PRIMARY_COMPONENT, RouteParams} from 'angular2/router';
import {BaseRequestOptions, Http} from 'angular2/http';
import {BaseRequestOptions, Http, Response, ResponseOptions} from 'angular2/http';

import {it, inject, beforeEachProviders} from 'angular2/testing';
import {MockBackend} from 'angular2/http/testing';
import {it, inject, injectAsync, beforeEach, beforeEachProviders} from 'angular2/testing';
import {MockBackend, MockConnection} from 'angular2/http/testing';

import {LolApiService} from '../misc/lolapi.service';
import {DDragonDirective} from './ddragon.directive';
Expand Down Expand Up @@ -77,13 +77,22 @@ describe('DDragonDirective', () => {
});


// it('should update on contruct', inject([ElementRef, LolApiService], (elementRef, service) => {
// spyOn(DDragonDirective.prototype, 'updateElement');
// expect(DDragonDirective.prototype.updateElement).not.toHaveBeenCalled();
// let directive = new DDragonDirective(elementRef, service);
// expect(DDragonDirective.prototype.updateElement).toHaveBeenCalled();
// done();
// }));
it('should update on contruct', injectAsync([MockBackend, ElementRef, RouteParams, Http], (mockBackend, elementRef, routeParams, http) => {
let mockResponse = new Response(new ResponseOptions({ status: 200, body: [{}] }));
mockBackend.connections.subscribe(
(connection: MockConnection) => {
connection.mockRespond(mockResponse);
});

spyOn(DDragonDirective.prototype, 'updateElement');
expect(DDragonDirective.prototype.updateElement).not.toHaveBeenCalled();

let service = new LolApiService(routeParams, http);
let directive = new DDragonDirective(elementRef, service);
return service.getRealm().toPromise().then(() => {
expect(DDragonDirective.prototype.updateElement).toHaveBeenCalled();
});
}));

it('should update on change', inject([DDragonDirective], (directive) => {
spyOn(directive, 'updateElement');
Expand All @@ -92,6 +101,7 @@ describe('DDragonDirective', () => {
expect(directive.updateElement).toHaveBeenCalled();
}));


it('should add src attribute for <img [ddragon]="">', inject([MockImageElementRef, LolApiService], (elementRef, service) => {
let directive = new DDragonDirective(elementRef, service);
expect(directive.el.nativeElement.getAttribute('src')).toBeNull();
Expand All @@ -116,6 +126,7 @@ describe('DDragonDirective', () => {
expect(directive.el.nativeElement.getAttribute('style')).not.toBeNull();
}));


it('should create a correct style string', inject([DDragonDirective], (directive) => {
let result = directive.buildStyle('test.png', realm, 0, 0);
expect(result).toBe('background:url(http://ddragon.leagueoflegends.com/cdn/[realm-version]/img/test.png) 0px 0px;');
Expand Down
2 changes: 1 addition & 1 deletion src/app/misc/error.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {provide} from 'angular2/core';
import {it, inject} from 'angular2/testing';
import {it, inject, beforeEachProviders} from 'angular2/testing';

import {ErrorComponent} from './error.component';

Expand Down
15 changes: 15 additions & 0 deletions src/app/misc/help.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {it, inject, beforeEachProviders} from 'angular2/testing';

import {HelpComponent} from './help.component';


describe('ErrorComponent', () => {
beforeEachProviders(() => [
HelpComponent
]);


it('should be initialised', inject([HelpComponent], (component) => {
expect(component.content).not.toBeDefined();
}));
});
15 changes: 15 additions & 0 deletions src/app/misc/loading.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {it, inject, beforeEachProviders} from 'angular2/testing';

import {LoadingComponent} from './loading.component';


describe('LoadingComponent', () => {
beforeEachProviders(() => [
LoadingComponent
]);


it('should be initialised', inject([LoadingComponent], (component) => {
expect(component.loading).not.toBeDefined();
}));
});
2 changes: 1 addition & 1 deletion src/app/misc/lolapi.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('LolApiService', () => {
connection.mockRespond(mockResponse);
});

service.getItems().subscribe(res => {
service.getMasteries().subscribe(res => {
expect(res).toBeDefined();
expect(res[0].test).toBeTruthy();
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/misc/lolapi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {settings} from '../../server/settings';

@Injectable()
export class LolApiService {
public realm: Observable<Response>;
public staticServer = settings.staticServer;
public matchServer = settings.matchServer;

private realm: Observable<Response>;
private region: string;

constructor(params: RouteParams, private http: Http) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes/choose.component.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('ChooseRoute', () => {
}, () => {
//error skipped
done();
})
});
});

it('should have a title', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes/region.component.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('RegionsComponent', () => {
}, () => {
//error skipped
done();
})
});
});


Expand Down

0 comments on commit 363c4ff

Please sign in to comment.