mirror of
https://github.com/nasa/openmct.git
synced 2025-01-06 21:28:42 +00:00
[Search] Wrote provider test
Completed tests for GenericSearchProvider. Also fixed style in other tests.
This commit is contained in:
parent
7678289ead
commit
164d5485e9
@ -29,6 +29,11 @@ define(
|
|||||||
function (ElasticsearchSearchProvider) {
|
function (ElasticsearchSearchProvider) {
|
||||||
"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 () {
|
describe("The ElasticSearch search provider ", function () {
|
||||||
var mockHttp,
|
var mockHttp,
|
||||||
mockHttpPromise,
|
mockHttpPromise,
|
||||||
@ -72,25 +77,22 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("gets data from ElasticSearch", function () {
|
it("gets data from ElasticSearch", function () {
|
||||||
mockProviderResults = mockHttpPromise.then.mostRecentCall.args[0](
|
var data = {
|
||||||
{
|
|
||||||
data: {
|
|
||||||
hits: {
|
hits: {
|
||||||
hits: [
|
hits: [
|
||||||
{
|
{},
|
||||||
_id: 1,
|
{}
|
||||||
_score: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
_id: 2,
|
|
||||||
_score: 2
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
total: 0
|
total: 0
|
||||||
},
|
},
|
||||||
timed_out: false
|
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(
|
expect(
|
||||||
mockObjectPromise.then.mostRecentCall.args[0]({
|
mockObjectPromise.then.mostRecentCall.args[0]({
|
||||||
@ -105,7 +107,7 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("returns something when there is an ElasticSearch error", function () {
|
it("returns something when there is an ElasticSearch error", function () {
|
||||||
mockProviderResults = mockHttpPromise.catch.mostRecentCall.args[0]();
|
mockProviderResults = mockHttpPromise['catch'].mostRecentCall.args[0]();
|
||||||
expect(mockProviderResults).toBeDefined();
|
expect(mockProviderResults).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,150 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* 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,jasmine*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchSpec. Created by shale on 07/31/2015.
|
||||||
|
*/
|
||||||
|
define(
|
||||||
|
["../../src/providers/GenericSearchProvider"],
|
||||||
|
function (GenericSearchProvider) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("The generic search provider ", function () {
|
||||||
|
var mockQ,
|
||||||
|
mockDeferred,
|
||||||
|
mockObjectService,
|
||||||
|
mockObjectPromise,
|
||||||
|
mockDomainObjects,
|
||||||
|
mockComposition,
|
||||||
|
mockCompositionPromise,
|
||||||
|
mockWorkerService,
|
||||||
|
mockWorker,
|
||||||
|
mockRoots = ['root1', 'root2'],
|
||||||
|
provider,
|
||||||
|
mockProviderResults;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
var i;
|
||||||
|
|
||||||
|
mockQ = jasmine.createSpyObj(
|
||||||
|
"$q",
|
||||||
|
[ "defer" ]
|
||||||
|
);
|
||||||
|
mockDeferred = jasmine.createSpyObj(
|
||||||
|
"deferred",
|
||||||
|
[ "resolve", "reject"]
|
||||||
|
);
|
||||||
|
mockDeferred.promise = "mock promise";
|
||||||
|
mockQ.defer.andReturn(mockDeferred);
|
||||||
|
|
||||||
|
mockObjectService = jasmine.createSpyObj(
|
||||||
|
"objectService",
|
||||||
|
[ "getObjects" ]
|
||||||
|
);
|
||||||
|
mockObjectPromise = jasmine.createSpyObj(
|
||||||
|
"promise",
|
||||||
|
[ "then", "catch" ]
|
||||||
|
);
|
||||||
|
mockObjectService.getObjects.andReturn(mockObjectPromise);
|
||||||
|
|
||||||
|
|
||||||
|
mockWorkerService = jasmine.createSpyObj(
|
||||||
|
"workerService",
|
||||||
|
[ "run" ]
|
||||||
|
);
|
||||||
|
mockWorker = jasmine.createSpyObj(
|
||||||
|
"worker",
|
||||||
|
[ "postMessage" ]
|
||||||
|
);
|
||||||
|
mockWorkerService.run.andReturn(mockWorker);
|
||||||
|
|
||||||
|
mockDomainObjects = {};
|
||||||
|
for (i = 0; i < 4; i += 1) {
|
||||||
|
mockDomainObjects[i] = (
|
||||||
|
jasmine.createSpyObj(
|
||||||
|
"domainObject",
|
||||||
|
[ "getId", "getModel", "hasCapability", "getCapability"]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
mockDomainObjects[i].getId.andReturn(i);
|
||||||
|
}
|
||||||
|
// Give the first object children
|
||||||
|
mockDomainObjects[0].hasCapability.andReturn(true);
|
||||||
|
mockComposition = jasmine.createSpyObj(
|
||||||
|
"composition",
|
||||||
|
[ "invoke" ]
|
||||||
|
);
|
||||||
|
mockCompositionPromise = jasmine.createSpyObj(
|
||||||
|
"promise",
|
||||||
|
[ "then", "catch" ]
|
||||||
|
);
|
||||||
|
mockComposition.invoke.andReturn(mockCompositionPromise);
|
||||||
|
mockDomainObjects[0].getCapability.andReturn(mockComposition);
|
||||||
|
|
||||||
|
provider = new GenericSearchProvider(mockQ, mockObjectService, mockWorkerService, mockRoots);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("indexes tree on initialization", function () {
|
||||||
|
mockObjectPromise.then.mostRecentCall.args[0](mockDomainObjects);
|
||||||
|
mockCompositionPromise.then.mostRecentCall.args[0](mockDomainObjects[1]);
|
||||||
|
|
||||||
|
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
||||||
|
expect(mockWorker.postMessage).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
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("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();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
@ -19,7 +19,7 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*global define,describe,it,expect,beforeEach,jasmine*/
|
/*global define,describe,it,expect,runs,waitsFor,beforeEach,jasmine,Worker*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SearchSpec. Created by shale on 07/31/2015.
|
* SearchSpec. Created by shale on 07/31/2015.
|
||||||
@ -99,7 +99,7 @@ define(
|
|||||||
worker.postMessage(
|
worker.postMessage(
|
||||||
{
|
{
|
||||||
request: "search",
|
request: "search",
|
||||||
input: "0",
|
input: "2",
|
||||||
maxNumber: 100,
|
maxNumber: 100,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
timeout: 1000
|
timeout: 1000
|
||||||
@ -124,7 +124,7 @@ define(
|
|||||||
runs(function () {
|
runs(function () {
|
||||||
expect(workerOutput).toBeDefined();
|
expect(workerOutput).toBeDefined();
|
||||||
expect(resultsLength).toEqual(1);
|
expect(resultsLength).toEqual(1);
|
||||||
expect(workerOutput.results[0]).toBeDefined();
|
expect(workerOutput.results[2]).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user