mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 09:26:45 +00:00
[Search] Update tests and remove redundancy
Updated the generic provider test. Removed index checking from the generic search worker, because that checking is already done (more efficiently) in the generic search provider.
This commit is contained in:
parent
158f549df2
commit
17f2bb966b
@ -31,36 +31,6 @@
|
||||
// {id: domainObject's ID, model: domainObject's model}
|
||||
var indexedItems = [];
|
||||
|
||||
// Helper function for index()
|
||||
// Checks whether an item with this ID is already indexed
|
||||
function conainsItem(id) {
|
||||
var i;
|
||||
for (i = 0; i < indexedItems.length; i += 1) {
|
||||
if (indexedItems[i].id === id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexes an item to indexedItems.
|
||||
*
|
||||
* @param data An object which contains:
|
||||
* * model: The model of the domain object
|
||||
* * id: The ID of the domain object
|
||||
*/
|
||||
function index(data) {
|
||||
var message;
|
||||
|
||||
if (!conainsItem(data.id)) {
|
||||
indexedItems.push({
|
||||
id: data.id,
|
||||
model: data.model
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function for serach()
|
||||
function convertToTerms(input) {
|
||||
var terms = input;
|
||||
@ -177,7 +147,10 @@
|
||||
|
||||
self.onmessage = function (event) {
|
||||
if (event.data.request === 'index') {
|
||||
index(event.data);
|
||||
indexedItems.push({
|
||||
id: event.data.id,
|
||||
model: event.data.model
|
||||
});
|
||||
} else if (event.data.request === 'search') {
|
||||
self.postMessage(search(event.data));
|
||||
}
|
||||
|
@ -81,6 +81,11 @@ define(
|
||||
);
|
||||
mockWorkerService.run.andReturn(mockWorker);
|
||||
|
||||
mockCapabilityPromise = jasmine.createSpyObj(
|
||||
"promise",
|
||||
[ "then", "catch" ]
|
||||
);
|
||||
|
||||
mockDomainObjects = {};
|
||||
for (i = 0; i < 4; i += 1) {
|
||||
mockDomainObjects[i] = (
|
||||
@ -91,6 +96,7 @@ define(
|
||||
);
|
||||
mockDomainObjects[i].getId.andReturn(i);
|
||||
mockDomainObjects[i].getCapability.andReturn(mockCapability);
|
||||
mockDomainObjects[i].useCapability.andReturn(mockCapabilityPromise);
|
||||
}
|
||||
// Give the first object children
|
||||
mockDomainObjects[0].hasCapability.andReturn(true);
|
||||
@ -98,10 +104,6 @@ define(
|
||||
"capability",
|
||||
[ "invoke", "listen" ]
|
||||
);
|
||||
mockCapabilityPromise = jasmine.createSpyObj(
|
||||
"promise",
|
||||
[ "then", "catch" ]
|
||||
);
|
||||
mockCapability.invoke.andReturn(mockCapabilityPromise);
|
||||
mockDomainObjects[0].getCapability.andReturn(mockCapability);
|
||||
|
||||
@ -112,13 +114,30 @@ define(
|
||||
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
||||
expect(mockObjectPromise.then).toHaveBeenCalled();
|
||||
|
||||
// Call through the root-getting part
|
||||
mockObjectPromise.then.mostRecentCall.args[0](mockDomainObjects);
|
||||
|
||||
//mockCapabilityPromise.then.mostRecentCall.args[0](mockDomainObjects[1]);
|
||||
// Call through the children-getting part
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockCapabilityPromise.then.mostRecentCall.args[0]([]);
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
|
||||
expect(mockWorker.postMessage).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("when indexing, listens for composition changes", function () {
|
||||
var mockListener = {composition: {}};
|
||||
|
||||
// Call indexItems
|
||||
mockObjectPromise.then.mostRecentCall.args[0](mockDomainObjects);
|
||||
|
||||
// Call through listening for changes
|
||||
expect(mockCapability.listen).toHaveBeenCalled();
|
||||
mockCapability.listen.mostRecentCall.args[0](mockListener);
|
||||
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
||||
mockObjectPromise.then.mostRecentCall.args[0](mockDomainObjects);
|
||||
});
|
||||
|
||||
it("sends search queries to the worker", function () {
|
||||
var timestamp = Date.now();
|
||||
provider.query(' test "query" ', timestamp, 1, 2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user