mirror of
https://github.com/nasa/openmct.git
synced 2025-03-21 11:35:59 +00:00
[Persistence] Add tests for indicator
Add tests for indicator for connection to ElasticSearch persistence, WTD-1033.
This commit is contained in:
parent
29584f2a7e
commit
5e20c2199d
@ -9,7 +9,6 @@ define(
|
||||
// reflected in the indicator's appearance.
|
||||
// CONNECTED: Everything nominal, expect to be able to read/write.
|
||||
// DISCONNECTED: HTTP failed; maybe misconfigured, disconnected.
|
||||
// SEMICONNECTED: Connected to the database, but it reported an error.
|
||||
// PENDING: Still trying to connect, and haven't failed yet.
|
||||
var CONNECTED = {
|
||||
text: "Connected",
|
||||
@ -21,11 +20,6 @@ define(
|
||||
glyphClass: "err",
|
||||
description: "Unable to connect to the domain object database."
|
||||
},
|
||||
SEMICONNECTED = {
|
||||
text: "Unavailable",
|
||||
glyphClass: "caution",
|
||||
description: "Database does not exist or is unavailable."
|
||||
},
|
||||
PENDING = {
|
||||
text: "Checking connection..."
|
||||
};
|
||||
@ -35,7 +29,7 @@ define(
|
||||
* at a regular interval (defined by bundle constants) to ensure
|
||||
* that the database is available.
|
||||
*/
|
||||
function CouchIndicator($http, $interval, PATH, INTERVAL) {
|
||||
function ElasticIndicator($http, $interval, PATH, INTERVAL) {
|
||||
// Track the current connection state
|
||||
var state = PENDING;
|
||||
|
||||
@ -44,11 +38,9 @@ define(
|
||||
state = DISCONNECTED;
|
||||
}
|
||||
|
||||
// Callback if the HTTP request succeeds. CouchDB may
|
||||
// report an error, so check for that.
|
||||
// Callback if the HTTP request succeeds.
|
||||
function handleResponse(response) {
|
||||
var data = response.data;
|
||||
state = data.error ? SEMICONNECTED : CONNECTED;
|
||||
state = CONNECTED;
|
||||
}
|
||||
|
||||
// Try to connect to CouchDB, and update the indicator.
|
||||
@ -58,7 +50,7 @@ define(
|
||||
|
||||
// Update the indicator initially, and start polling.
|
||||
updateIndicator();
|
||||
$interval(updateIndicator, INTERVAL);
|
||||
$interval(updateIndicator, INTERVAL, false);
|
||||
|
||||
return {
|
||||
/**
|
||||
@ -98,6 +90,6 @@ define(
|
||||
|
||||
}
|
||||
|
||||
return CouchIndicator;
|
||||
return ElasticIndicator;
|
||||
}
|
||||
);
|
@ -13,6 +13,76 @@ define(
|
||||
mockPromise,
|
||||
indicator;
|
||||
|
||||
beforeEach(function () {
|
||||
mockHttp = jasmine.createSpyObj("$http", [ "get" ]);
|
||||
mockInterval = jasmine.createSpy("$interval");
|
||||
mockPromise = jasmine.createSpyObj("promise", [ "then" ]);
|
||||
testPath = "/test/path";
|
||||
testInterval = 12321; // Some number
|
||||
|
||||
mockHttp.get.andReturn(mockPromise);
|
||||
|
||||
indicator = new ElasticIndicator(
|
||||
mockHttp,
|
||||
mockInterval,
|
||||
testPath,
|
||||
testInterval
|
||||
);
|
||||
});
|
||||
|
||||
it("polls for changes", function () {
|
||||
expect(mockInterval).toHaveBeenCalledWith(
|
||||
jasmine.any(Function),
|
||||
testInterval,
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("has a database icon", function () {
|
||||
expect(indicator.getGlyph()).toEqual("D");
|
||||
});
|
||||
|
||||
it("consults the database at the configured path", function () {
|
||||
expect(mockHttp.get).toHaveBeenCalledWith(testPath);
|
||||
});
|
||||
|
||||
it("changes when the database connection is nominal", function () {
|
||||
var initialText = indicator.getText(),
|
||||
initialDescrption = indicator.getDescription(),
|
||||
initialGlyphClass = indicator.getGlyphClass();
|
||||
|
||||
// Nominal just means getting back an objeect, without
|
||||
// an error field.
|
||||
mockPromise.then.mostRecentCall.args[0]({ data: {} });
|
||||
|
||||
// Verify that these values changed;
|
||||
// don't test for specific text.
|
||||
expect(indicator.getText()).not.toEqual(initialText);
|
||||
expect(indicator.getGlyphClass()).not.toEqual(initialGlyphClass);
|
||||
expect(indicator.getDescription()).not.toEqual(initialDescrption);
|
||||
|
||||
// Do check for specific class
|
||||
expect(indicator.getGlyphClass()).toEqual("ok");
|
||||
});
|
||||
|
||||
it("changes when the server cannot be reached", function () {
|
||||
var initialText = indicator.getText(),
|
||||
initialDescrption = indicator.getDescription(),
|
||||
initialGlyphClass = indicator.getGlyphClass();
|
||||
|
||||
// Nominal just means getting back an objeect, without
|
||||
// an error field.
|
||||
mockPromise.then.mostRecentCall.args[1]({ data: {} });
|
||||
|
||||
// Verify that these values changed;
|
||||
// don't test for specific text.
|
||||
expect(indicator.getText()).not.toEqual(initialText);
|
||||
expect(indicator.getGlyphClass()).not.toEqual(initialGlyphClass);
|
||||
expect(indicator.getDescription()).not.toEqual(initialDescrption);
|
||||
|
||||
// Do check for specific class
|
||||
expect(indicator.getGlyphClass()).toEqual("err");
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user