LEFT | RIGHT |
| 1 'use strict'; |
| 2 |
| 3 (function() { |
| 4 |
| 5 describe('browser filter model', function() { |
| 6 var browser, Filter, models, Y; |
| 7 |
| 8 before(function(done) { |
| 9 Y = YUI(GlobalConfig).use([ |
| 10 'juju-models', 'juju-browser-models'], function(Y) { |
| 11 models = Y.namespace('juju.models'); |
| 12 browser = models.browser; |
| 13 Filter = browser.Filter; |
| 14 done(); |
| 15 }); |
| 16 }); |
| 17 |
1 // Ensure the search results are rendered inside the container. | 18 // Ensure the search results are rendered inside the container. |
2 it('defaults to an initial filter set', function() { | 19 it('defaults to an initial filter set', function() { |
3 var filter = new Filter(); | 20 var filter = new Filter(); |
4 filter.get('category').should.eql([ | |
5 'databases', 'file_servers', 'app_servers', 'cache_proxy', | |
6 'applications', 'miscellaneous']); | |
7 filter.get('provider').should.eql(['aws', 'openstack']); | |
8 filter.get('scope').should.eql(['public']); | |
9 filter.get('series').should.eql(['precise']); | 21 filter.get('series').should.eql(['precise']); |
10 filter.get('type').should.eql(['approved']); | 22 filter.get('type').should.eql(['approved']); |
11 }); | 23 }); |
12 | 24 |
13 it('constructs a valid query string based on settings.', function() { | 25 it('constructs a valid query string based on settings.', function() { |
14 var filter = new Filter(); | 26 var filter = new Filter(); |
15 filter.genQueryString().should.equal([ | 27 filter.genQueryString().should.equal( |
16 'category=databases&category=file_servers&category=app_servers&', | 28 'series=precise&text=&type=approved'); |
17 'category=cache_proxy&category=applications&category=miscellaneous', | |
18 '&provider=aws&provider=openstack&scope=public&series=precise&', | |
19 'type=approved' | |
20 ].join('')); | |
21 | 29 |
22 filter.set('category', []); | 30 filter.set('series', []); |
23 // Google and Firefox think that the string should start with the first | 31 // Google and Firefox think that the string should start with the first |
24 // param. PhantomJS thinks it starts with a &. Removing the & if it's at | 32 // param. PhantomJS thinks it starts with a &. Removing the & if it's at |
25 // the start of the string and checking the rest of it for validity. | 33 // the start of the string and checking the rest of it for validity. |
| 34 var qstring = filter.genQueryString(); |
| 35 if (qstring.charAt(0) === '&') { |
| 36 qstring = qstring.slice(1); |
| 37 } |
| 38 |
| 39 qstring.should.equal('text=&type=approved'); |
| 40 }); |
| 41 |
| 42 it('updates string values into an array', function() { |
| 43 var filter = new Filter({ |
| 44 text: 'one' |
| 45 }); |
| 46 |
| 47 filter.update({category: 'databases'}); |
| 48 filter.get('category').should.eql(['databases']); |
| 49 // While the text is left along |
| 50 filter.get('text').should.eql('one'); |
| 51 }); |
| 52 |
| 53 it('updates text when empty', function() { |
| 54 var filter = new Filter({ |
| 55 text: 'one' |
| 56 }); |
| 57 |
| 58 filter.get('text').should.eql('one'); |
| 59 filter.update({text: ''}); |
| 60 filter.get('text').should.equal(''); |
| 61 }); |
| 62 }); |
| 63 |
| 64 })(); |
LEFT | RIGHT |