mirror of
https://github.com/nasa/openmct.git
synced 2025-01-31 08:25:31 +00:00
[Search] Add test cases
Add test cases related to throttled loading of domain objects to index, nasa/openmctweb#141.
This commit is contained in:
parent
d04c5e6858
commit
bea5002752
@ -45,6 +45,8 @@ define(
|
|||||||
mockTopic,
|
mockTopic,
|
||||||
mockMutationTopic,
|
mockMutationTopic,
|
||||||
mockRoots = ['root1', 'root2'],
|
mockRoots = ['root1', 'root2'],
|
||||||
|
mockThrottledFn,
|
||||||
|
throttledCallCount,
|
||||||
provider,
|
provider,
|
||||||
mockProviderResults;
|
mockProviderResults;
|
||||||
|
|
||||||
@ -58,6 +60,18 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveThrottledFn() {
|
||||||
|
if (mockThrottledFn.calls.length > throttledCallCount) {
|
||||||
|
mockThrottle.mostRecentCall.args[0]();
|
||||||
|
throttledCallCount = mockThrottledFn.calls.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveAsyncTasks() {
|
||||||
|
resolveThrottledFn();
|
||||||
|
resolveObjectPromises();
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockQ = jasmine.createSpyObj(
|
mockQ = jasmine.createSpyObj(
|
||||||
"$q",
|
"$q",
|
||||||
@ -75,6 +89,8 @@ define(
|
|||||||
mockQ.defer.andReturn(mockDeferred);
|
mockQ.defer.andReturn(mockDeferred);
|
||||||
|
|
||||||
mockThrottle = jasmine.createSpy("throttle");
|
mockThrottle = jasmine.createSpy("throttle");
|
||||||
|
mockThrottledFn = jasmine.createSpy("throttledFn");
|
||||||
|
throttledCallCount = 0;
|
||||||
|
|
||||||
mockObjectService = jasmine.createSpyObj(
|
mockObjectService = jasmine.createSpyObj(
|
||||||
"objectService",
|
"objectService",
|
||||||
@ -112,7 +128,13 @@ define(
|
|||||||
mockDomainObjects[id] = (
|
mockDomainObjects[id] = (
|
||||||
jasmine.createSpyObj(
|
jasmine.createSpyObj(
|
||||||
"domainObject",
|
"domainObject",
|
||||||
[ "getId", "getModel", "hasCapability", "getCapability", "useCapability" ]
|
[
|
||||||
|
"getId",
|
||||||
|
"getModel",
|
||||||
|
"hasCapability",
|
||||||
|
"getCapability",
|
||||||
|
"useCapability"
|
||||||
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
mockDomainObjects[id].getId.andReturn(id);
|
mockDomainObjects[id].getId.andReturn(id);
|
||||||
@ -134,12 +156,9 @@ define(
|
|||||||
mockTopic.andCallFake(function (key) {
|
mockTopic.andCallFake(function (key) {
|
||||||
return key === 'mutation' && mockMutationTopic;
|
return key === 'mutation' && mockMutationTopic;
|
||||||
});
|
});
|
||||||
mockThrottle.andCallFake(function (fn) {
|
mockThrottle.andReturn(mockThrottledFn);
|
||||||
return fn;
|
|
||||||
});
|
|
||||||
mockObjectPromise.then.andReturn(mockChainedPromise);
|
mockObjectPromise.then.andReturn(mockChainedPromise);
|
||||||
|
|
||||||
|
|
||||||
provider = new GenericSearchProvider(
|
provider = new GenericSearchProvider(
|
||||||
mockQ,
|
mockQ,
|
||||||
mockLog,
|
mockLog,
|
||||||
@ -154,6 +173,8 @@ define(
|
|||||||
it("indexes tree on initialization", function () {
|
it("indexes tree on initialization", function () {
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
|
resolveThrottledFn();
|
||||||
|
|
||||||
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
||||||
expect(mockObjectPromise.then).toHaveBeenCalled();
|
expect(mockObjectPromise.then).toHaveBeenCalled();
|
||||||
|
|
||||||
@ -174,8 +195,8 @@ define(
|
|||||||
composition: ['a']
|
composition: ['a']
|
||||||
});
|
});
|
||||||
|
|
||||||
resolveObjectPromises();
|
resolveAsyncTasks();
|
||||||
resolveObjectPromises();
|
resolveAsyncTasks();
|
||||||
|
|
||||||
expect(mockWorker.postMessage).toHaveBeenCalledWith({
|
expect(mockWorker.postMessage).toHaveBeenCalledWith({
|
||||||
request: 'index',
|
request: 'index',
|
||||||
@ -190,7 +211,7 @@ define(
|
|||||||
mockMutationTopic.listen.mostRecentCall
|
mockMutationTopic.listen.mostRecentCall
|
||||||
.args[0](mockDomainObjects.a);
|
.args[0](mockDomainObjects.a);
|
||||||
|
|
||||||
resolveObjectPromises();
|
resolveAsyncTasks();
|
||||||
|
|
||||||
expect(mockWorker.postMessage).toHaveBeenCalledWith({
|
expect(mockWorker.postMessage).toHaveBeenCalledWith({
|
||||||
request: 'index',
|
request: 'index',
|
||||||
@ -246,7 +267,7 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("warns when objects are unavailable", function () {
|
it("warns when objects are unavailable", function () {
|
||||||
resolveObjectPromises();
|
resolveAsyncTasks();
|
||||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||||
mockChainedPromise.then.mostRecentCall.args[0](
|
mockChainedPromise.then.mostRecentCall.args[0](
|
||||||
mockObjectPromise.then.mostRecentCall.args[1]()
|
mockObjectPromise.then.mostRecentCall.args[1]()
|
||||||
@ -254,6 +275,19 @@ define(
|
|||||||
expect(mockLog.warn).toHaveBeenCalled();
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user