mirror of
https://github.com/nasa/openmct.git
synced 2025-06-03 08:00:52 +00:00
[Search] Remove old specs in prep for rewrite
Remove old specs in prep for rewrite.
This commit is contained in:
parent
0f63e4dde9
commit
14094a48fc
@ -24,92 +24,9 @@
|
|||||||
/**
|
/**
|
||||||
* SearchSpec. Created by shale on 07/31/2015.
|
* SearchSpec. Created by shale on 07/31/2015.
|
||||||
*/
|
*/
|
||||||
define(
|
define([
|
||||||
["../src/ElasticSearchProvider"],
|
"../src/ElasticSearchProvider"
|
||||||
function (ElasticSearchProvider) {
|
], function (ElasticSearchProvider) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// JSLint doesn't like underscore-prefixed properties,
|
});
|
||||||
// so hide them here.
|
|
||||||
var ID = "_id",
|
|
||||||
SCORE = "_score";
|
|
||||||
|
|
||||||
describe("The ElasticSearch search provider ", function () {
|
|
||||||
var mockHttp,
|
|
||||||
mockHttpPromise,
|
|
||||||
mockObjectPromise,
|
|
||||||
mockObjectService,
|
|
||||||
mockDomainObject,
|
|
||||||
provider,
|
|
||||||
mockProviderResults;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
mockHttp = jasmine.createSpy("$http");
|
|
||||||
mockHttpPromise = jasmine.createSpyObj(
|
|
||||||
"promise",
|
|
||||||
[ "then" ]
|
|
||||||
);
|
|
||||||
mockHttp.andReturn(mockHttpPromise);
|
|
||||||
// allow chaining of promise.then().catch();
|
|
||||||
mockHttpPromise.then.andReturn(mockHttpPromise);
|
|
||||||
|
|
||||||
mockObjectService = jasmine.createSpyObj(
|
|
||||||
"objectService",
|
|
||||||
[ "getObjects" ]
|
|
||||||
);
|
|
||||||
mockObjectPromise = jasmine.createSpyObj(
|
|
||||||
"promise",
|
|
||||||
[ "then" ]
|
|
||||||
);
|
|
||||||
mockObjectService.getObjects.andReturn(mockObjectPromise);
|
|
||||||
|
|
||||||
mockDomainObject = jasmine.createSpyObj(
|
|
||||||
"domainObject",
|
|
||||||
[ "getId", "getModel" ]
|
|
||||||
);
|
|
||||||
|
|
||||||
provider = new ElasticSearchProvider(mockHttp, mockObjectService, "");
|
|
||||||
provider.query(' test "query" ', 0, undefined, 1000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("sends a query to ElasticSearch", function () {
|
|
||||||
expect(mockHttp).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("gets data from ElasticSearch", function () {
|
|
||||||
var data = {
|
|
||||||
hits: {
|
|
||||||
hits: [
|
|
||||||
{},
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
total: 0
|
|
||||||
},
|
|
||||||
timed_out: false
|
|
||||||
};
|
|
||||||
data.hits.hits[0][ID] = 1;
|
|
||||||
data.hits.hits[0][SCORE] = 1;
|
|
||||||
data.hits.hits[1][ID] = 2;
|
|
||||||
data.hits.hits[1][SCORE] = 2;
|
|
||||||
|
|
||||||
mockProviderResults = mockHttpPromise.then.mostRecentCall.args[0]({data: data});
|
|
||||||
|
|
||||||
expect(
|
|
||||||
mockObjectPromise.then.mostRecentCall.args[0]({
|
|
||||||
1: mockDomainObject,
|
|
||||||
2: mockDomainObject
|
|
||||||
}).hits.length
|
|
||||||
).toEqual(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns nothing for an empty string query", function () {
|
|
||||||
expect(provider.query("").hits).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns something when there is an ElasticSearch error", function () {
|
|
||||||
mockProviderResults = mockHttpPromise.then.mostRecentCall.args[1]();
|
|
||||||
expect(mockProviderResults).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
@ -24,270 +24,29 @@
|
|||||||
/**
|
/**
|
||||||
* SearchSpec. Created by shale on 07/31/2015.
|
* SearchSpec. Created by shale on 07/31/2015.
|
||||||
*/
|
*/
|
||||||
define(
|
define([
|
||||||
["../../src/services/GenericSearchProvider"],
|
"../../src/services/GenericSearchProvider"
|
||||||
function (GenericSearchProvider) {
|
], function (GenericSearchProvider) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The generic search provider ", function () {
|
describe('GenericSearchProvider', function () {
|
||||||
var mockQ,
|
var $q,
|
||||||
mockLog,
|
$log,
|
||||||
mockThrottle,
|
modelService,
|
||||||
mockDeferred,
|
workerService,
|
||||||
mockObjectService,
|
topic,
|
||||||
mockObjectPromise,
|
ROOTS;
|
||||||
mockChainedPromise,
|
|
||||||
mockDomainObjects,
|
|
||||||
mockCapability,
|
|
||||||
mockCapabilityPromise,
|
|
||||||
mockWorkerService,
|
|
||||||
mockWorker,
|
|
||||||
mockTopic,
|
|
||||||
mockMutationTopic,
|
|
||||||
mockRoots = ['root1', 'root2'],
|
|
||||||
mockThrottledFn,
|
|
||||||
throttledCallCount,
|
|
||||||
provider,
|
|
||||||
mockProviderResults;
|
|
||||||
|
|
||||||
function resolveObjectPromises() {
|
beforeEach(function () {
|
||||||
var i;
|
$q = jasmine.createSpyObj(
|
||||||
for (i = 0; i < mockObjectPromise.then.calls.length; i += 1) {
|
'$q',
|
||||||
mockChainedPromise.then.calls[i].args[0](
|
['defer']
|
||||||
mockObjectPromise.then.calls[i]
|
);
|
||||||
.args[0](mockDomainObjects)
|
// TODO: continue
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveThrottledFn() {
|
|
||||||
if (mockThrottledFn.calls.length > throttledCallCount) {
|
|
||||||
mockThrottle.mostRecentCall.args[0]();
|
|
||||||
throttledCallCount = mockThrottledFn.calls.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveAsyncTasks() {
|
|
||||||
resolveThrottledFn();
|
|
||||||
resolveObjectPromises();
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
mockQ = jasmine.createSpyObj(
|
|
||||||
"$q",
|
|
||||||
[ "defer" ]
|
|
||||||
);
|
|
||||||
mockLog = jasmine.createSpyObj(
|
|
||||||
"$log",
|
|
||||||
[ "error", "warn", "info", "debug" ]
|
|
||||||
);
|
|
||||||
mockDeferred = jasmine.createSpyObj(
|
|
||||||
"deferred",
|
|
||||||
[ "resolve", "reject"]
|
|
||||||
);
|
|
||||||
mockDeferred.promise = "mock promise";
|
|
||||||
mockQ.defer.andReturn(mockDeferred);
|
|
||||||
|
|
||||||
mockThrottle = jasmine.createSpy("throttle");
|
|
||||||
mockThrottledFn = jasmine.createSpy("throttledFn");
|
|
||||||
throttledCallCount = 0;
|
|
||||||
|
|
||||||
mockObjectService = jasmine.createSpyObj(
|
|
||||||
"objectService",
|
|
||||||
[ "getObjects" ]
|
|
||||||
);
|
|
||||||
mockObjectPromise = jasmine.createSpyObj(
|
|
||||||
"promise",
|
|
||||||
[ "then", "catch" ]
|
|
||||||
);
|
|
||||||
mockChainedPromise = jasmine.createSpyObj(
|
|
||||||
"chainedPromise",
|
|
||||||
[ "then" ]
|
|
||||||
);
|
|
||||||
mockObjectService.getObjects.andReturn(mockObjectPromise);
|
|
||||||
|
|
||||||
mockTopic = jasmine.createSpy('topic');
|
|
||||||
|
|
||||||
mockWorkerService = jasmine.createSpyObj(
|
|
||||||
"workerService",
|
|
||||||
[ "run" ]
|
|
||||||
);
|
|
||||||
mockWorker = jasmine.createSpyObj(
|
|
||||||
"worker",
|
|
||||||
[ "postMessage" ]
|
|
||||||
);
|
|
||||||
mockWorkerService.run.andReturn(mockWorker);
|
|
||||||
|
|
||||||
mockCapabilityPromise = jasmine.createSpyObj(
|
|
||||||
"promise",
|
|
||||||
[ "then", "catch" ]
|
|
||||||
);
|
|
||||||
|
|
||||||
mockDomainObjects = {};
|
|
||||||
['a', 'root1', 'root2'].forEach(function (id) {
|
|
||||||
mockDomainObjects[id] = (
|
|
||||||
jasmine.createSpyObj(
|
|
||||||
"domainObject",
|
|
||||||
[
|
|
||||||
"getId",
|
|
||||||
"getModel",
|
|
||||||
"hasCapability",
|
|
||||||
"getCapability",
|
|
||||||
"useCapability"
|
|
||||||
]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
mockDomainObjects[id].getId.andReturn(id);
|
|
||||||
mockDomainObjects[id].getCapability.andReturn(mockCapability);
|
|
||||||
mockDomainObjects[id].useCapability.andReturn(mockCapabilityPromise);
|
|
||||||
mockDomainObjects[id].getModel.andReturn({});
|
|
||||||
});
|
|
||||||
|
|
||||||
mockCapability = jasmine.createSpyObj(
|
|
||||||
"capability",
|
|
||||||
[ "invoke", "listen" ]
|
|
||||||
);
|
|
||||||
mockCapability.invoke.andReturn(mockCapabilityPromise);
|
|
||||||
mockDomainObjects.a.getCapability.andReturn(mockCapability);
|
|
||||||
mockMutationTopic = jasmine.createSpyObj(
|
|
||||||
'mutationTopic',
|
|
||||||
[ 'listen' ]
|
|
||||||
);
|
|
||||||
mockTopic.andCallFake(function (key) {
|
|
||||||
return key === 'mutation' && mockMutationTopic;
|
|
||||||
});
|
|
||||||
mockThrottle.andReturn(mockThrottledFn);
|
|
||||||
mockObjectPromise.then.andReturn(mockChainedPromise);
|
|
||||||
|
|
||||||
provider = new GenericSearchProvider(
|
|
||||||
mockQ,
|
|
||||||
mockLog,
|
|
||||||
mockThrottle,
|
|
||||||
mockObjectService,
|
|
||||||
mockWorkerService,
|
|
||||||
mockTopic,
|
|
||||||
mockRoots
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("indexes tree on initialization", function () {
|
|
||||||
var i;
|
|
||||||
|
|
||||||
resolveThrottledFn();
|
|
||||||
|
|
||||||
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
|
||||||
expect(mockObjectPromise.then).toHaveBeenCalled();
|
|
||||||
|
|
||||||
// Call through the root-getting part
|
|
||||||
resolveObjectPromises();
|
|
||||||
|
|
||||||
mockRoots.forEach(function (id) {
|
|
||||||
expect(mockWorker.postMessage).toHaveBeenCalledWith({
|
|
||||||
request: 'index',
|
|
||||||
model: mockDomainObjects[id].getModel(),
|
|
||||||
id: id
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("indexes members of composition", function () {
|
|
||||||
mockDomainObjects.root1.getModel.andReturn({
|
|
||||||
composition: ['a']
|
|
||||||
});
|
|
||||||
|
|
||||||
resolveAsyncTasks();
|
|
||||||
resolveAsyncTasks();
|
|
||||||
|
|
||||||
expect(mockWorker.postMessage).toHaveBeenCalledWith({
|
|
||||||
request: 'index',
|
|
||||||
model: mockDomainObjects.a.getModel(),
|
|
||||||
id: 'a'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("listens for changes to mutation", function () {
|
|
||||||
expect(mockMutationTopic.listen)
|
|
||||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
|
||||||
mockMutationTopic.listen.mostRecentCall
|
|
||||||
.args[0](mockDomainObjects.a);
|
|
||||||
|
|
||||||
resolveAsyncTasks();
|
|
||||||
|
|
||||||
expect(mockWorker.postMessage).toHaveBeenCalledWith({
|
|
||||||
request: 'index',
|
|
||||||
model: mockDomainObjects.a.getModel(),
|
|
||||||
id: mockDomainObjects.a.getId()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("sends search queries to the worker", function () {
|
|
||||||
var timestamp = Date.now();
|
|
||||||
provider.query(' test "query" ', timestamp, 1, 2);
|
|
||||||
expect(mockWorker.postMessage).toHaveBeenCalledWith({
|
|
||||||
request: "search",
|
|
||||||
input: ' test "query" ',
|
|
||||||
timestamp: timestamp,
|
|
||||||
maxNumber: 1,
|
|
||||||
timeout: 2
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("gives an empty result for an empty query", function () {
|
|
||||||
var timestamp = Date.now(),
|
|
||||||
queryOutput;
|
|
||||||
|
|
||||||
queryOutput = provider.query('', timestamp, 1, 2);
|
|
||||||
expect(queryOutput.hits).toEqual([]);
|
|
||||||
expect(queryOutput.total).toEqual(0);
|
|
||||||
|
|
||||||
queryOutput = provider.query();
|
|
||||||
expect(queryOutput.hits).toEqual([]);
|
|
||||||
expect(queryOutput.total).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("handles responses from the worker", function () {
|
|
||||||
var timestamp = Date.now(),
|
|
||||||
event = {
|
|
||||||
data: {
|
|
||||||
request: "search",
|
|
||||||
results: {
|
|
||||||
1: 1,
|
|
||||||
2: 2
|
|
||||||
},
|
|
||||||
total: 2,
|
|
||||||
timedOut: false,
|
|
||||||
timestamp: timestamp
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
provider.query(' test "query" ', timestamp);
|
|
||||||
mockWorker.onmessage(event);
|
|
||||||
mockObjectPromise.then.mostRecentCall.args[0](mockDomainObjects);
|
|
||||||
expect(mockDeferred.resolve).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("warns when objects are unavailable", function () {
|
|
||||||
resolveAsyncTasks();
|
|
||||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
|
||||||
mockChainedPromise.then.mostRecentCall.args[0](
|
|
||||||
mockObjectPromise.then.mostRecentCall.args[1]()
|
|
||||||
);
|
|
||||||
expect(mockLog.warn).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("throttles the loading of objects to index", function () {
|
|
||||||
expect(mockObjectService.getObjects).not.toHaveBeenCalled();
|
|
||||||
resolveThrottledFn();
|
|
||||||
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("logs when all objects have been processed", function () {
|
|
||||||
expect(mockLog.info).not.toHaveBeenCalled();
|
|
||||||
resolveAsyncTasks();
|
|
||||||
resolveThrottledFn();
|
|
||||||
expect(mockLog.info).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
);
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
@ -33,7 +33,7 @@ define(
|
|||||||
// If this test fails, make sure this path is correct
|
// If this test fails, make sure this path is correct
|
||||||
var worker = new Worker(require.toUrl('platform/search/src/services/GenericSearchWorker.js')),
|
var worker = new Worker(require.toUrl('platform/search/src/services/GenericSearchWorker.js')),
|
||||||
numObjects = 5;
|
numObjects = 5;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
var i;
|
var i;
|
||||||
for (i = 0; i < numObjects; i += 1) {
|
for (i = 0; i < numObjects; i += 1) {
|
||||||
@ -50,77 +50,77 @@ define(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("searches can reach all objects", function () {
|
it("searches can reach all objects", function () {
|
||||||
var flag = false,
|
var flag = false,
|
||||||
workerOutput,
|
workerOutput,
|
||||||
resultsLength = 0;
|
resultsLength = 0;
|
||||||
|
|
||||||
// Search something that should return all objects
|
// Search something that should return all objects
|
||||||
runs(function () {
|
runs(function () {
|
||||||
worker.postMessage(
|
worker.postMessage(
|
||||||
{
|
{
|
||||||
request: "search",
|
request: "search",
|
||||||
input: "object",
|
input: "object",
|
||||||
maxNumber: 100,
|
maxResults: 100,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
timeout: 1000
|
timeout: 1000
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
worker.onmessage = function (event) {
|
worker.onmessage = function (event) {
|
||||||
var id;
|
var id;
|
||||||
|
|
||||||
workerOutput = event.data;
|
workerOutput = event.data;
|
||||||
for (id in workerOutput.results) {
|
for (id in workerOutput.results) {
|
||||||
resultsLength += 1;
|
resultsLength += 1;
|
||||||
}
|
}
|
||||||
flag = true;
|
flag = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
waitsFor(function () {
|
waitsFor(function () {
|
||||||
return flag;
|
return flag;
|
||||||
}, "The worker should be searching", 1000);
|
}, "The worker should be searching", 1000);
|
||||||
|
|
||||||
runs(function () {
|
runs(function () {
|
||||||
expect(workerOutput).toBeDefined();
|
expect(workerOutput).toBeDefined();
|
||||||
expect(resultsLength).toEqual(numObjects);
|
expect(resultsLength).toEqual(numObjects);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("searches return only matches", function () {
|
it("searches return only matches", function () {
|
||||||
var flag = false,
|
var flag = false,
|
||||||
workerOutput,
|
workerOutput,
|
||||||
resultsLength = 0;
|
resultsLength = 0;
|
||||||
|
|
||||||
// Search something that should return 1 object
|
// Search something that should return 1 object
|
||||||
runs(function () {
|
runs(function () {
|
||||||
worker.postMessage(
|
worker.postMessage(
|
||||||
{
|
{
|
||||||
request: "search",
|
request: "search",
|
||||||
input: "2",
|
input: "2",
|
||||||
maxNumber: 100,
|
maxResults: 100,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
timeout: 1000
|
timeout: 1000
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
worker.onmessage = function (event) {
|
worker.onmessage = function (event) {
|
||||||
var id;
|
var id;
|
||||||
|
|
||||||
workerOutput = event.data;
|
workerOutput = event.data;
|
||||||
for (id in workerOutput.results) {
|
for (id in workerOutput.results) {
|
||||||
resultsLength += 1;
|
resultsLength += 1;
|
||||||
}
|
}
|
||||||
flag = true;
|
flag = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
waitsFor(function () {
|
waitsFor(function () {
|
||||||
return flag;
|
return flag;
|
||||||
}, "The worker should be searching", 1000);
|
}, "The worker should be searching", 1000);
|
||||||
|
|
||||||
runs(function () {
|
runs(function () {
|
||||||
expect(workerOutput).toBeDefined();
|
expect(workerOutput).toBeDefined();
|
||||||
expect(resultsLength).toEqual(1);
|
expect(resultsLength).toEqual(1);
|
||||||
@ -129,4 +129,4 @@ define(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user