diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml index f01484c653df72f2090afdc7f7c02527a12cddde..277c0629cb3ad71b662a03a302469084818a7145 100644 --- a/app/views/people/index.html.haml +++ b/app/views/people/index.html.haml @@ -22,7 +22,7 @@ %p =t('.searching') :javascript - $(document).ready(function() { setTimeout("runDelayedSearch('#{@background_query}')", 10000); }); + $(document).ready(function() { List.startSearchDelay('#{@background_query}') } ); - else %p =t('.no_one_found') diff --git a/public/javascripts/contact-list.js b/public/javascripts/contact-list.js index 17472e762337a3ebb0eb5b76851b27a19cc04dc3..9321dc4b098c74257498e0c4b8ed8bf8d3fbc74d 100644 --- a/public/javascripts/contact-list.js +++ b/public/javascripts/contact-list.js @@ -32,7 +32,26 @@ var List = { }; } }); + }, + runDelayedSearch: function( searchTerm ) { + $.ajax({ + dataType: 'json', + url: '/people/refresh_search', + data: { q: searchTerm }, + success: List.handleSearchRefresh + }); + }, + handleSearchRefresh: function( data ) { + if ( data.search_count > 0 ) { + $("#people_stream.stream").html( data.search_html ); + } else { + $("#people_stream.stream").html( "<p>" + Diaspora.I18n.t("people.not_found") + "</p>" ); + } + }, + startSearchDelay: function ( theSearch ) { + setTimeout( "List.runDelayedSearch('" + theSearch + "')", 10000); } + }; $(document).ready(function() { diff --git a/public/javascripts/pages/contacts-index.js b/public/javascripts/pages/contacts-index.js index d75ac9b662ff593ed5c314925c457d43655a3291..ac2e37eeb06c58ac3166fc08e29c1c448cb29c30 100644 --- a/public/javascripts/pages/contacts-index.js +++ b/public/javascripts/pages/contacts-index.js @@ -5,21 +5,5 @@ Diaspora.Pages.ContactsIndex = function() { self.infiniteScroll = self.instantiate("InfiniteScroll"); $('.conversation_button').twipsy({position: 'below'}); }); -}; - -function runDelayedSearch( searchTerm ) { - $.ajax({ - dataType: 'json', - url: '/people/refresh_search', - data: { q: searchTerm }, - success: handleSearchRefresh - }); -} -function handleSearchRefresh(data) { - if ( data.search_count > 0 ) { - $("#people_stream.stream").html( data.search_html ); - } else { - $("#people_stream.stream").html( "<p>" + Diaspora.I18n.t("people.not_found") + "</p>" ); - } -} \ No newline at end of file +}; diff --git a/spec/controllers/jasmine_fixtures/people.spec.rb b/spec/controllers/jasmine_fixtures/people_spec.rb similarity index 69% rename from spec/controllers/jasmine_fixtures/people.spec.rb rename to spec/controllers/jasmine_fixtures/people_spec.rb index bdcaebba6e3f82ed08465ff96b3cace862126ab6..8216656ff0b385c0fea62cb5658f417333a1941e 100644 --- a/spec/controllers/jasmine_fixtures/people.spec.rb +++ b/spec/controllers/jasmine_fixtures/people_spec.rb @@ -10,12 +10,12 @@ describe PeopleController do sign_in :user, bob end - it "generates a jasmine fixture", :fixture => true do + it "generates a jasmine fixture with no query", :fixture => true do get :index save_fixture(html_for("body"), "empty_people_search") end - it "generates a jasmine fixture", :fixture => true do - get :index, :id => "sample@diaspor.us" + it "generates a jasmine fixture trying an external search", :fixture => true do + get :index, :q => "sample@diaspor.us" save_fixture(html_for("body"), "pending_external_people_search") end end diff --git a/spec/javascripts/search-spec.js b/spec/javascripts/search-spec.js index 309ce8309d199d73f684707ac3785ddbbe0cc6e1..7a6f9751f81346a508e9f126b27d6f481b192043 100644 --- a/spec/javascripts/search-spec.js +++ b/spec/javascripts/search-spec.js @@ -3,30 +3,27 @@ * the COPYRIGHT file. */ -describe("Publisher", function() { +describe("List", function() { describe("runDelayedSearch", function() { beforeEach( function(){ - spec.loadFixture('pending_external_people_search'); - Publisher.open(); }); it('gets called on initialize', function(){ - spyOn(Publisher, 'runDelayedSearch'); - Publisher.initialize(); - expect(Publisher.runDelayedSearch).toHaveBeenCalled(); + spyOn( List, 'startSearchDelay'); + spec.loadFixture('pending_external_people_search'); + expect(List.startSearchDelay).toHaveBeenCalled(); }); }); describe("runDelayedSearch", function() { beforeEach( function(){ spec.loadFixture('empty_people_search'); - Publisher.open(); + List.initialize(); }); it('inserts contact html', function(){ - Publisher.initialize(); - Publisher.handleSearchRefresh( "<div class='testing_insert_div'>hello</div>"); + List.handleSearchRefresh( { count:1,search_html: '<div class='testing_insert_div'>hello</div>' } ); expect($(".testing_insert_div").text().toEqual( "hello" )); });