Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(272)

Unified Diff: test/test_browser_search_view.js

Issue 8910043: Adds search functionality
Patch Set: Adds search functionality Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/test_browser_charm_details.js ('k') | test/test_browser_search_widget.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/test_browser_search_view.js
=== added file 'test/test_browser_search_view.js'
--- test/test_browser_search_view.js 1970-01-01 00:00:00 +0000
+++ test/test_browser_search_view.js 2013-04-22 21:04:27 +0000
@@ -0,0 +1,78 @@
+'use strict';
+
+
+describe('search view', function() {
+ var apiURL,
+ container,
+ view,
+ Y;
+
+ before(function(done) {
+ Y = YUI(GlobalConfig).use(
+ 'json',
+ 'juju-charm-store',
+ 'node',
+ 'subapp-browser-searchview',
+ function(Y) {
+ done();
+ });
+ });
+
+ beforeEach(function() {
+ // Mock out a dummy location for the Store used in view instances.
+ window.juju_config = {charmworldURL: 'http://localhost'};
+ container = Y.Node.create('<div id="container"></div>');
+ Y.one('body').append(container);
+ view = new Y.juju.browser.views.BrowserSearchView({text: 'foo'});
+ //
+ // Create monkeypatched store to verify right method is called.
+ apiURL = '';
+ var fakeStore = new Y.juju.Charmworld0({});
+ var sampleData = {
+ result: [{
+ id: 'foo/bar-2',
+ name: 'bar',
+ description: 'some charm named bar'
+ }]
+ };
+ fakeStore.set('datasource', {
+ sendRequest: function(params) {
+ // Stubbing the server callback value
+ apiURL = params.request;
+ params.callback.success({
+ response: {
+ results: [{
+ responseText: Y.JSON.stringify(sampleData)
+ }]
+ }
+ });
+ }
+ });
+ view.set('store', fakeStore);
+ view.set('renderTo', container);
+ });
+
+ afterEach(function() {
+ delete window.juju_config;
+ view.destroy();
+ container.remove(true);
+ });
+
+ it('exists', function() {
+ assert.isObject(view);
+ });
+
+ it('renders correctly', function() {
+ view.render();
+ assert.equal('charms?text=foo', apiURL);
+ assert.equal(1, Y.all('.yui3-charmtoken').size());
+ var charmText = Y.one('.yui3-charmtoken').one('.title').get('text');
+ assert.equal(charmText.replace(/\s+/g, ''), 'bar');
+ });
+
+ it('handles empty text for search', function() {
+ view.set('text', '');
+ view.render();
+ assert.equal('charms?text=', apiURL);
+ });
+});
« no previous file with comments | « test/test_browser_charm_details.js ('k') | test/test_browser_search_widget.js » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b