From eb767ac0bbfdb4b8f01dbca9abe1713e643463c4 Mon Sep 17 00:00:00 2001 From: exane Date: Tue, 23 Jun 2015 15:00:49 +0200 Subject: [PATCH] extend filter --- server/Battleside.js | 12 ++++++++++++ test/src/filterSpec.js | 27 ++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/server/Battleside.js b/server/Battleside.js index 1085d22..47dd57c 100644 --- a/server/Battleside.js +++ b/server/Battleside.js @@ -586,6 +586,18 @@ Battleside = (function(){ res.push(card); } } + else if(_.isArray(val)) { + var _f = false; + for(var i = 0; i < val.length; i++) { + if(property === val[i]){ + _f = true; + break; + } + } + if(!_f){ + res.push(card); + } + } else if(card.getProperty(prop) !== val){ res.push(card); } diff --git a/test/src/filterSpec.js b/test/src/filterSpec.js index 8ca5273..9f40c10 100644 --- a/test/src/filterSpec.js +++ b/test/src/filterSpec.js @@ -5,20 +5,22 @@ var data = require("../../assets/data/abilities"); describe("filter", function(){ var card, side, filter, cards; + beforeEach(function(){ filter = Battleside.prototype.filter; cards = []; - cards.push(Card("iorveth")); - cards.push(Card("toruviel")); - cards.push(Card("isengrim_faoiltiarnah")); - cards.push(Card("decoy")); + cards.push(Card("iorveth")); //hero + cards.push(Card("toruviel")); //normal + cards.push(Card("isengrim_faoiltiarnah")); //hero + cards.push(Card("decoy")); //special + cards.push(Card("impenetrable_fog")); //special }) it("it should filter heroes out", function(){ var res = filter(cards, { "ability": "hero" }) - expect(res.length).toBe(2); + expect(res.length).toBe(3); }) it("it should filter hero and special cards out", function(){ @@ -26,6 +28,21 @@ describe("filter", function(){ "ability": "hero", "type": Card.TYPE.SPECIAL }) + expect(res.length).toBe(2); + }) + + it("it should filter 2 types out", function(){ + var res = filter(cards, { + "type": [Card.TYPE.SPECIAL, Card.TYPE.WEATHER] + }) + expect(res.length).toBe(3); + }) + + it("it should filter 2 types and hero out", function(){ + var res = filter(cards, { + "ability": "hero", + "type": [Card.TYPE.SPECIAL, Card.TYPE.WEATHER] + }) expect(res.length).toBe(1); })