From 1bb3991ebad543b584bb10c37d4e10d7906e309b Mon Sep 17 00:00:00 2001 From: sirzach Date: Mon, 3 Nov 2014 09:03:47 -0500 Subject: [PATCH] initial work for getting testing around the filterable mixin --- app/controllers/cards.js | 2 +- ...ilterable_mixin.js => filterable-mixin.js} | 0 tests/unit/mixins/filterable-mixin-test.js | 44 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) rename app/mixins/{filterable_mixin.js => filterable-mixin.js} (100%) create mode 100644 tests/unit/mixins/filterable-mixin-test.js diff --git a/app/controllers/cards.js b/app/controllers/cards.js index 0129127..c178cee 100644 --- a/app/controllers/cards.js +++ b/app/controllers/cards.js @@ -1,5 +1,5 @@ import Ember from 'ember'; -import filterableMixin from '../mixins/filterable_mixin'; +import filterableMixin from '../mixins/filterable-mixin'; export default Ember.ArrayController.extend(filterableMixin, { diff --git a/app/mixins/filterable_mixin.js b/app/mixins/filterable-mixin.js similarity index 100% rename from app/mixins/filterable_mixin.js rename to app/mixins/filterable-mixin.js diff --git a/tests/unit/mixins/filterable-mixin-test.js b/tests/unit/mixins/filterable-mixin-test.js new file mode 100644 index 0000000..ce922f3 --- /dev/null +++ b/tests/unit/mixins/filterable-mixin-test.js @@ -0,0 +1,44 @@ +import { test, moduleFor } from 'ember-qunit'; +import Ember from 'ember'; +import FilterableMixin from 'webatrice/mixins/filterable-mixin'; + +module('FilterableMixin'); + +var arrayController = Ember.ArrayController.extend(FilterableMixin); +var filterProperties = [ + Ember.Object.create({ + propertyName: 'color', + values: ['red'], + and: false + }) + ]; + +test('it exists', function () { + var obj = Ember.Object.extend(FilterableMixin); + var subject = obj.create(); + ok(subject); +}); + +test('it can filter out all blue colors', function () { + var subject = arrayController.create({ + model: [{color: 'blue'}, + {color: 'red'}, + {color: 'blue'}], + filterProperties: filterProperties + }); + + equal(subject.get('arrangedContent.length'), 1); +}); + +test('it doesn\'t try to filters on objects that have already been filtered out', function () { + var subject = arrayController.create({ + model: [{color: 'blue'}, {color: 'blue'}, + {color: 'blue'}, {color: 'red'}, + {color: 'red'}, {color: 'green'}], + filterProperties: filterProperties + }); + + equal(subject.get('arrangedContent.length'), 2); + subject.get('filterProperties')[0].set('values', ['red', 'green']); + equal(subject.get('arrangedContent.length'), 3); +}); \ No newline at end of file