mirror of
https://github.com/nasa/openmct.git
synced 2025-04-09 20:31:26 +00:00
[Search] Wrote controller tests
Completed tests for SearchController and SearchItemController.
This commit is contained in:
parent
4bb000dd93
commit
5b3f78287e
@ -62,17 +62,6 @@ define(function () {
|
||||
*/
|
||||
search: search,
|
||||
|
||||
/**
|
||||
* Checks to see if there are any search results to display.
|
||||
*/
|
||||
areResults: function () {
|
||||
if ($scope.results) {
|
||||
return $scope.results.length > 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks to see if we are still waiting for the results to be
|
||||
* fully updated.
|
||||
|
@ -19,7 +19,7 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
/*global define,describe,it,expect,beforeEach,jasmine*/
|
||||
|
||||
/**
|
||||
* SearchSpec. Created by shale on 07/31/2015.
|
||||
@ -32,34 +32,88 @@ define(
|
||||
describe("The search controller", function () {
|
||||
var mockScope,
|
||||
mockSearchService,
|
||||
mockPromise,
|
||||
controller;
|
||||
|
||||
function bigArray(size) {
|
||||
var array = [],
|
||||
i;
|
||||
for (i = 0; i < size; i += 1) {
|
||||
array.push(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
[ "$on", "$watch" ]
|
||||
[ "" ]
|
||||
);
|
||||
mockScope.ngModel = {};
|
||||
mockScope.ngModel.input = "test input";
|
||||
|
||||
mockSearchService = jasmine.createSpyObj(
|
||||
"searchService",
|
||||
[ "query", "isLoading" ]
|
||||
);
|
||||
mockPromise = jasmine.createSpyObj(
|
||||
"promise",
|
||||
[ "then" ]
|
||||
);
|
||||
mockSearchService.query.andReturn(mockPromise);
|
||||
|
||||
controller = new SearchController(mockScope, mockSearchService);
|
||||
controller.search();
|
||||
});
|
||||
|
||||
it("sends queries to the search service", function () {
|
||||
expect(mockSearchService.query).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("populates the results with results from the search service", function () {
|
||||
expect(mockPromise.then).toHaveBeenCalledWith(jasmine.any(Function));
|
||||
mockPromise.then.mostRecentCall.args[0]({hits: []});
|
||||
|
||||
expect(mockScope.results).toBeDefined();
|
||||
});
|
||||
|
||||
it("checks if the search service is loading", function () {
|
||||
controller.isLoading();
|
||||
expect(mockSearchService.isLoading).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("displays only some results when there are many", function () {
|
||||
expect(mockPromise.then).toHaveBeenCalledWith(jasmine.any(Function));
|
||||
mockPromise.then.mostRecentCall.args[0]({hits: bigArray(100)});
|
||||
|
||||
expect(mockScope.results).toBeDefined();
|
||||
expect(mockScope.results.length).toBeLessThan(100);
|
||||
});
|
||||
|
||||
it("can load more results", function () {
|
||||
var oldSize;
|
||||
|
||||
expect(mockPromise.then).toHaveBeenCalledWith(jasmine.any(Function));
|
||||
mockPromise.then.mostRecentCall.args[0]({hits: bigArray(100)});
|
||||
oldSize = mockScope.results.length;
|
||||
|
||||
// If this doesn't pass, need to make the big array bigger
|
||||
expect(controller.areMore()).toBeTruthy();
|
||||
|
||||
controller.loadMore();
|
||||
expect(mockScope.results.length).toBeGreaterThan(oldSize);
|
||||
});
|
||||
|
||||
|
||||
it("sets the ngModel.search flag", function () {
|
||||
// Flag should be true with nonempty input
|
||||
expect(mockScope.ngModel.search).toEqual(true);
|
||||
|
||||
// Flag should be flase with empty input
|
||||
mockScope.ngModel.input = "";
|
||||
controller.search();
|
||||
expect(mockScope.ngModel.search).toEqual(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
@ -19,7 +19,7 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
/*global define,describe,it,expect,beforeEach,jasmine*/
|
||||
|
||||
/**
|
||||
* SearchSpec. Created by shale on 07/31/2015.
|
||||
@ -31,19 +31,40 @@ define(
|
||||
|
||||
describe("The search item controller", function () {
|
||||
var mockScope,
|
||||
mockDomainObject1,
|
||||
mockDomainObject2,
|
||||
controller;
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
[ "$on", "$watch" ]
|
||||
[ "$watch" ]
|
||||
);
|
||||
mockDomainObject1 = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId" ]
|
||||
);
|
||||
mockDomainObject1.getId.andReturn("1");
|
||||
mockDomainObject2 = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId" ]
|
||||
);
|
||||
mockDomainObject2.getId.andReturn("2");
|
||||
|
||||
mockScope.ngModel = {};
|
||||
mockScope.ngModel.selectedObject = mockDomainObject1;
|
||||
mockScope.domainObject = mockDomainObject1;
|
||||
|
||||
controller = new SearchItemController(mockScope);
|
||||
});
|
||||
|
||||
it("keeps track of object selection", function () {
|
||||
expect(controller.isSelected()).toBeTruthy();
|
||||
|
||||
mockScope.ngModel.selectedObject = mockDomainObject2;
|
||||
expect(mockScope.$watch).toHaveBeenCalled();
|
||||
mockScope.$watch.mostRecentCall.args[1](mockDomainObject2);
|
||||
expect(controller.isSelected()).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user