diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml index f01484c65..277c0629c 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 17472e762..9321dc4b0 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( "

" + Diaspora.I18n.t("people.not_found") + "

" ); + } + }, + 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 d75ac9b66..ac2e37eeb 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( "

" + Diaspora.I18n.t("people.not_found") + "

" ); - } -} \ 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 bdcaebba6..8216656ff 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 309ce8309..7a6f9751f 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( "
hello
"); + List.handleSearchRefresh( { count:1,search_html: '
hello
' } ); expect($(".testing_insert_div").text().toEqual( "hello" )); });