diff --git a/platform/search/src/SearchAggregator.js b/platform/search/src/SearchAggregator.js index 087f992fe3..def3d13822 100644 --- a/platform/search/src/SearchAggregator.js +++ b/platform/search/src/SearchAggregator.js @@ -42,7 +42,6 @@ define( * aggregated */ function SearchAggregator($q, providers) { - var loading; // Remove duplicate objects that have the same ID. Modifies the passed // array, and returns the number that were removed. @@ -89,9 +88,6 @@ define( timestamp = Date.now(), resultPromises = []; - // We are loading - loading = true; - // Send the query to all the providers for (i = 0; i < providers.length; i += 1) { resultPromises.push( @@ -114,9 +110,6 @@ define( orderByScore(results); totalSum -= filterDuplicates(results, totalSum); - // We are done loading - loading = false; - return { hits: results, total: totalSum, @@ -135,15 +128,7 @@ define( * * @param inputText The text input that is the query. */ - query: queryAll, - - /** - * Checks to see if we are still waiting for the results to be - * fully updated. - */ - isLoading: function () { - return loading; - } + query: queryAll }; } diff --git a/platform/search/src/controllers/SearchController.js b/platform/search/src/controllers/SearchController.js index 23f0efc12f..edfeb3789e 100644 --- a/platform/search/src/controllers/SearchController.js +++ b/platform/search/src/controllers/SearchController.js @@ -33,11 +33,15 @@ define(function () { function SearchController($scope, searchService) { // Starting amount of results to load. Will get increased. var numResults = INITIAL_LOAD_NUMBER, + loading = false, fullResults = []; function search() { var inputText = $scope.ngModel.input; + // We are starting to load. + loading = true; + // Update whether the file tree should be displayed if (inputText === '' || inputText === undefined) { $scope.ngModel.search = false; @@ -52,6 +56,9 @@ define(function () { searchService.query(inputText).then(function (result) { fullResults = result.hits; $scope.results = result.hits.slice(0, numResults); + + // Now we are done loading. + loading = false; }); } @@ -67,7 +74,7 @@ define(function () { * fully updated. */ isLoading: function () { - return searchService.isLoading(); + return loading; }, /** diff --git a/platform/search/test/SearchAggregatorSpec.js b/platform/search/test/SearchAggregatorSpec.js index 148d149652..cf35e2928e 100644 --- a/platform/search/test/SearchAggregatorSpec.js +++ b/platform/search/test/SearchAggregatorSpec.js @@ -96,18 +96,6 @@ define( } }); - it("is loading until all the providers' promises fufill", function () { - expect(aggregator.isLoading()).toBeFalsy(); - - // Send query - aggregator.query(); - expect(aggregator.isLoading()).toBeTruthy(); - - // Then resolve the promises - mockAggregatorResults = mockPromise.then.mostRecentCall.args[0]([]); - expect(aggregator.isLoading()).toBeFalsy(); - }); - }); } ); \ No newline at end of file diff --git a/platform/search/test/controllers/SearchControllerSpec.js b/platform/search/test/controllers/SearchControllerSpec.js index 1fe5e631e1..b53ac41b5d 100644 --- a/platform/search/test/controllers/SearchControllerSpec.js +++ b/platform/search/test/controllers/SearchControllerSpec.js @@ -55,7 +55,7 @@ define( mockSearchService = jasmine.createSpyObj( "searchService", - [ "query", "isLoading" ] + [ "query" ] ); mockPromise = jasmine.createSpyObj( "promise", @@ -78,10 +78,16 @@ define( expect(mockScope.results).toBeDefined(); }); - it("checks if the search service is loading", function () { - controller.isLoading(); - expect(mockSearchService.isLoading).toHaveBeenCalled(); + it("is loading until the service's promise fufills", function () { + // Send query + controller.search(); + expect(controller.isLoading()).toBeTruthy(); + + // Then resolve the promises + mockPromise.then.mostRecentCall.args[0]({hits: []}); + expect(controller.isLoading()).toBeFalsy(); }); + it("displays only some results when there are many", function () { expect(mockPromise.then).toHaveBeenCalledWith(jasmine.any(Function));