OLD | NEW |
(Empty) | |
| 1 'use strict'; |
| 2 |
| 3 describe('filter widget', function() { |
| 4 var container, handle, instance, Y; |
| 5 |
| 6 before(function(done) { |
| 7 Y = YUI(GlobalConfig).use( |
| 8 ['browser-filter-widget', 'node-event-simulate'], function(Y) { |
| 9 done(); |
| 10 }); |
| 11 }); |
| 12 |
| 13 beforeEach(function() { |
| 14 container = Y.Node.create('<div></div>'); |
| 15 Y.one(document.body).prepend(container); |
| 16 instance = new Y.juju.widgets.browser.Filter({ |
| 17 filters: { |
| 18 text: 'foo', |
| 19 type: ['approved'], |
| 20 category: ['databases', 'app_servers'] |
| 21 } |
| 22 }); |
| 23 }); |
| 24 |
| 25 afterEach(function() { |
| 26 container.remove(true); |
| 27 if (handle) { |
| 28 handle.detach(); |
| 29 } |
| 30 if (instance) { |
| 31 instance.destroy(); |
| 32 } |
| 33 }); |
| 34 |
| 35 it('initializes correctly', function() { |
| 36 assert.isObject(instance.get('filters')); |
| 37 var categories = instance.get('category'); |
| 38 |
| 39 instance.get('category')[0].value.should.eql('databases'); |
| 40 instance.get('category')[0].name.should.eql('Databases'); |
| 41 instance.get('category')[0].checked.should.eql(true); |
| 42 |
| 43 instance.get('type')[0].name.should.eql('Reviewed Charms'); |
| 44 instance.get('type')[0].value.should.eql('approved'); |
| 45 instance.get('type')[0].checked.should.eql(true); |
| 46 }); |
| 47 |
| 48 it('renders provided filters', function() { |
| 49 instance.render(container); |
| 50 |
| 51 var checked = container.all('input[checked="checked"]'); |
| 52 assert(checked.size() === 3); |
| 53 }); |
| 54 |
| 55 it('checking an input fires a search changed event', function(done) { |
| 56 |
| 57 instance.render(container); |
| 58 |
| 59 handle = instance.on(instance.EV_FILTER_CHANGED, function(ev) { |
| 60 assert.isObject(ev.change); |
| 61 ev.change.field.should.eql('type'); |
| 62 ev.change.value.should.eql([]); |
| 63 done(); |
| 64 }); |
| 65 |
| 66 var ftype = container.one('input[value="approved"]'); |
| 67 ftype.simulate('click'); |
| 68 }); |
| 69 |
| 70 it('checking input not in current filters fires correctly', function(done) { |
| 71 |
| 72 instance.render(container); |
| 73 |
| 74 handle = instance.on(instance.EV_FILTER_CHANGED, function(ev) { |
| 75 assert.isObject(ev.change); |
| 76 ev.change.field.should.eql('series'); |
| 77 ev.change.value.should.eql(['precise']); |
| 78 done(); |
| 79 }); |
| 80 |
| 81 var ftype = container.one('input[value="precise"]'); |
| 82 ftype.simulate('click'); |
| 83 }); |
| 84 |
| 85 it('unchecking an input fires a search changed event', function(done) { |
| 86 instance.render(container); |
| 87 |
| 88 handle = instance.on(instance.EV_FILTER_CHANGED, function(ev) { |
| 89 assert.isObject(ev.change); |
| 90 ev.change.field.should.eql('category'); |
| 91 ev.change.value.should.eql(['app_servers']); |
| 92 done(); |
| 93 }); |
| 94 |
| 95 var ftype = container.one('input[value="databases"]'); |
| 96 ftype.simulate('click'); |
| 97 }); |
| 98 |
| 99 }); |
OLD | NEW |