mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 06:38:17 +00:00
[Search] Update tests
Updated the SearchController tests for more coverage, due to additions to the controller. Fixed a small logic error in controller.areMore()
This commit is contained in:
@ -141,14 +141,14 @@ define(function () {
|
|||||||
|
|
||||||
// Check to see if any of the not displayed results are of an allowed type
|
// Check to see if any of the not displayed results are of an allowed type
|
||||||
for (i = numResults; i < fullResults.hits.length; i += 1) {
|
for (i = numResults; i < fullResults.hits.length; i += 1) {
|
||||||
if ($scope.ngModel.checked[fullResults.hits[i].object.getModel().type.key]) {
|
if ($scope.ngModel.checkAll || $scope.ngModel.checked[fullResults.hits[i].object.getModel().type]) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If none of the ones at hand are correct, there still may be more if we
|
// If none of the ones at hand are correct, there still may be more if we
|
||||||
// re-search with a larger maxResults
|
// re-search with a larger maxResults
|
||||||
return numResults < fullResults.total;
|
return fullResults.hits.length < fullResults.total;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,10 @@ define(
|
|||||||
function (SearchController) {
|
function (SearchController) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// These should be the same as the ones on the top of the search controller
|
||||||
|
var INITIAL_LOAD_NUMBER = 20,
|
||||||
|
LOAD_INCREMENT = 20;
|
||||||
|
|
||||||
describe("The search controller", function () {
|
describe("The search controller", function () {
|
||||||
var mockScope,
|
var mockScope,
|
||||||
mockSearchService,
|
mockSearchService,
|
||||||
@ -57,6 +61,7 @@ define(
|
|||||||
mockScope.ngModel.input = "test input";
|
mockScope.ngModel.input = "test input";
|
||||||
mockScope.ngModel.checked = {};
|
mockScope.ngModel.checked = {};
|
||||||
mockScope.ngModel.checked['mock.type'] = true;
|
mockScope.ngModel.checked['mock.type'] = true;
|
||||||
|
mockScope.ngModel.checkAll = true;
|
||||||
|
|
||||||
mockSearchService = jasmine.createSpyObj(
|
mockSearchService = jasmine.createSpyObj(
|
||||||
"searchService",
|
"searchService",
|
||||||
@ -115,11 +120,35 @@ define(
|
|||||||
expect(mockScope.results.length).toBeLessThan(100);
|
expect(mockScope.results.length).toBeLessThan(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("detects when there are more results", function () {
|
||||||
|
mockScope.ngModel.checkAll = false;
|
||||||
|
|
||||||
|
expect(mockPromise.then).toHaveBeenCalledWith(jasmine.any(Function));
|
||||||
|
mockPromise.then.mostRecentCall.args[0]({
|
||||||
|
hits: bigArray(INITIAL_LOAD_NUMBER + 5),
|
||||||
|
total: INITIAL_LOAD_NUMBER + 5
|
||||||
|
});
|
||||||
|
// bigArray gives searchResults of type 'mock.type'
|
||||||
|
mockScope.ngModel.checked['mock.type'] = false;
|
||||||
|
mockScope.ngModel.checked['mock.type.2'] = true;
|
||||||
|
|
||||||
|
expect(controller.areMore()).toBeFalsy();
|
||||||
|
|
||||||
|
mockScope.ngModel.checked['mock.type'] = true;
|
||||||
|
|
||||||
|
expect(controller.areMore()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
it("can load more results", function () {
|
it("can load more results", function () {
|
||||||
var oldSize;
|
var oldSize;
|
||||||
|
|
||||||
expect(mockPromise.then).toHaveBeenCalled();
|
expect(mockPromise.then).toHaveBeenCalled();
|
||||||
mockPromise.then.mostRecentCall.args[0]({hits: bigArray(100), total: 1000});
|
mockPromise.then.mostRecentCall.args[0]({
|
||||||
|
hits: bigArray(INITIAL_LOAD_NUMBER + LOAD_INCREMENT + 1),
|
||||||
|
total: INITIAL_LOAD_NUMBER + LOAD_INCREMENT + 1
|
||||||
|
});
|
||||||
|
// These hits and total lengths are the case where the controller
|
||||||
|
// DOES NOT have to re-search to load more results
|
||||||
oldSize = mockScope.results.length;
|
oldSize = mockScope.results.length;
|
||||||
|
|
||||||
expect(controller.areMore()).toBeTruthy();
|
expect(controller.areMore()).toBeTruthy();
|
||||||
@ -128,6 +157,32 @@ define(
|
|||||||
expect(mockScope.results.length).toBeGreaterThan(oldSize);
|
expect(mockScope.results.length).toBeGreaterThan(oldSize);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("can re-search to load more results", function () {
|
||||||
|
var oldSize,
|
||||||
|
oldCallCount;
|
||||||
|
|
||||||
|
expect(mockPromise.then).toHaveBeenCalled();
|
||||||
|
mockPromise.then.mostRecentCall.args[0]({
|
||||||
|
hits: bigArray(INITIAL_LOAD_NUMBER + LOAD_INCREMENT - 1),
|
||||||
|
total: INITIAL_LOAD_NUMBER + LOAD_INCREMENT + 1
|
||||||
|
});
|
||||||
|
// These hits and total lengths are the case where the controller
|
||||||
|
// DOES have to re-search to load more results
|
||||||
|
oldSize = mockScope.results.length;
|
||||||
|
oldCallCount = mockPromise.then.callCount;
|
||||||
|
expect(controller.areMore()).toBeTruthy();
|
||||||
|
|
||||||
|
controller.loadMore();
|
||||||
|
expect(mockPromise.then).toHaveBeenCalled();
|
||||||
|
// Make sure that a NEW call to search has been made
|
||||||
|
expect(oldCallCount).toBeLessThan(mockPromise.then.callCount);
|
||||||
|
mockPromise.then.mostRecentCall.args[0]({
|
||||||
|
hits: bigArray(INITIAL_LOAD_NUMBER + LOAD_INCREMENT + 1),
|
||||||
|
total: INITIAL_LOAD_NUMBER + LOAD_INCREMENT + 1
|
||||||
|
});
|
||||||
|
expect(mockScope.results.length).toBeGreaterThan(oldSize);
|
||||||
|
});
|
||||||
|
|
||||||
it("sets the ngModel.search flag", function () {
|
it("sets the ngModel.search flag", function () {
|
||||||
// Flag should be true with nonempty input
|
// Flag should be true with nonempty input
|
||||||
expect(mockScope.ngModel.search).toEqual(true);
|
expect(mockScope.ngModel.search).toEqual(true);
|
||||||
@ -137,6 +192,12 @@ define(
|
|||||||
controller.search();
|
controller.search();
|
||||||
mockPromise.then.mostRecentCall.args[0]({hits: [], total: 0});
|
mockPromise.then.mostRecentCall.args[0]({hits: [], total: 0});
|
||||||
expect(mockScope.ngModel.search).toEqual(false);
|
expect(mockScope.ngModel.search).toEqual(false);
|
||||||
|
|
||||||
|
// Both the empty string and undefined should be 'empty input'
|
||||||
|
mockScope.ngModel.input = undefined;
|
||||||
|
controller.search();
|
||||||
|
mockPromise.then.mostRecentCall.args[0]({hits: [], total: 0});
|
||||||
|
expect(mockScope.ngModel.search).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user