Skip to content

Commit

Permalink
feat(shop): add tag filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveVanOpstal committed Mar 31, 2016
1 parent 18b9ade commit d388f44
Show file tree
Hide file tree
Showing 18 changed files with 601 additions and 145 deletions.
144 changes: 0 additions & 144 deletions src/app/build/shop.component.ts

This file was deleted.

39 changes: 39 additions & 0 deletions src/app/build/shop/champion.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {it, inject, beforeEach, beforeEachProviders} from 'angular2/testing';

import {ChampionPipe} from './champion.pipe';


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

let items = [];
let item1 = {};
let item2 = {};
let item3 = {};

beforeEach(() => {
item1 = {
id: 1,
requiredChampion: 5
};
item2 = {
id: 2,
requiredChampion: 3
};
item3 = {
id: 3
};
items = [item1, item2, item3];
});

it('should filter', inject([ChampionPipe], (pipe) => {
expect(pipe.transform(items, [3])).toHaveEqualContent([item2, item3]);
}));

it('should not filter null', inject([ChampionPipe], (pipe) => {
expect(pipe.transform(null, [3])).toBe(null);
expect(pipe.transform(items, [null])).toBe(items);
}));
});
20 changes: 20 additions & 0 deletions src/app/build/shop/champion.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Pipe, PipeTransform} from 'angular2/core';

@Pipe({
name: 'champion',
pure: false
})

export class ChampionPipe implements PipeTransform {
transform(items: Array<any>, [champion]) {
if (!items || !champion) {
return items;
}
return items.filter((item) => {
if (!item.requiredChampion) {
return true;
}
return item.requiredChampion === champion;
});
}
}
38 changes: 38 additions & 0 deletions src/app/build/shop/hide.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {it, inject, beforeEach, beforeEachProviders} from 'angular2/testing';

import {HidePipe} from './hide.pipe';


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

let items = [];
let item1 = {};
let item2 = {};
let item3 = {};

beforeEach(() => {
item1 = {
id: 1,
hideFromAll: true
};
item2 = {
id: 2,
hideFromAll: false
};
item3 = {
id: 3
};
items = [item1, item2, item3];
});

it('should filter', inject([HidePipe], (pipe) => {
expect(pipe.transform(items)).toHaveEqualContent([item2, item3]);
}));

it('should not filter null', inject([HidePipe], (pipe) => {
expect(pipe.transform(null)).toBe(null);
}));
});
17 changes: 17 additions & 0 deletions src/app/build/shop/hide.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Pipe, PipeTransform} from 'angular2/core';

@Pipe({
name: 'hide',
pure: false
})

export class HidePipe implements PipeTransform {
transform(items: Array<any>) {
if (!items) {
return items;
}
return items.filter((item) => {
return !item.hideFromAll;
});
}
}
45 changes: 45 additions & 0 deletions src/app/build/shop/map.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {it, inject, beforeEach, beforeEachProviders} from 'angular2/testing';

import {MapPipe} from './map.pipe';


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

let items = [];
let item1 = {};
let item2 = {};
let item3 = {};
let item4 = {};

beforeEach(() => {
item1 = {
id: 1,
maps: {1: true}
};
item2 = {
id: 2,
maps: {1: true, 2: true}
};
item3 = {
id: 3,
maps: {1: false}
};
item4 = {
id: 4
};
items = [item1, item2, item3, item4];
});

it('should filter', inject([MapPipe], (pipe) => {
expect(pipe.transform(items, [2])).toHaveEqualContent([item2]);
expect(pipe.transform(items, [1])).toHaveEqualContent([item1, item2]);
}));

it('should not filter null', inject([MapPipe], (pipe) => {
expect(pipe.transform(null, [1])).toBe(null);
expect(pipe.transform(items, [null])).toBe(items);
}));
});
20 changes: 20 additions & 0 deletions src/app/build/shop/map.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Pipe, PipeTransform} from 'angular2/core';

@Pipe({
name: 'map',
pure: false
})

export class MapPipe implements PipeTransform {
transform(items: Array<any>, [map]) {
if (!items || !map) {
return items;
}
return items.filter((item) => {
if (!item.maps || item.maps.length <= 0) {
return false;
}
return item.maps[map];
});
}
}
Loading

0 comments on commit d388f44

Please sign in to comment.