mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 21:58:13 +00:00
[Persistence] Add tests for indicator
Add tests for indicator for connection to ElasticSearch persistence, WTD-1033.
This commit is contained in:
@ -9,7 +9,6 @@ define(
|
|||||||
// reflected in the indicator's appearance.
|
// reflected in the indicator's appearance.
|
||||||
// CONNECTED: Everything nominal, expect to be able to read/write.
|
// CONNECTED: Everything nominal, expect to be able to read/write.
|
||||||
// DISCONNECTED: HTTP failed; maybe misconfigured, disconnected.
|
// 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.
|
// PENDING: Still trying to connect, and haven't failed yet.
|
||||||
var CONNECTED = {
|
var CONNECTED = {
|
||||||
text: "Connected",
|
text: "Connected",
|
||||||
@ -21,11 +20,6 @@ define(
|
|||||||
glyphClass: "err",
|
glyphClass: "err",
|
||||||
description: "Unable to connect to the domain object database."
|
description: "Unable to connect to the domain object database."
|
||||||
},
|
},
|
||||||
SEMICONNECTED = {
|
|
||||||
text: "Unavailable",
|
|
||||||
glyphClass: "caution",
|
|
||||||
description: "Database does not exist or is unavailable."
|
|
||||||
},
|
|
||||||
PENDING = {
|
PENDING = {
|
||||||
text: "Checking connection..."
|
text: "Checking connection..."
|
||||||
};
|
};
|
||||||
@ -35,7 +29,7 @@ define(
|
|||||||
* at a regular interval (defined by bundle constants) to ensure
|
* at a regular interval (defined by bundle constants) to ensure
|
||||||
* that the database is available.
|
* that the database is available.
|
||||||
*/
|
*/
|
||||||
function CouchIndicator($http, $interval, PATH, INTERVAL) {
|
function ElasticIndicator($http, $interval, PATH, INTERVAL) {
|
||||||
// Track the current connection state
|
// Track the current connection state
|
||||||
var state = PENDING;
|
var state = PENDING;
|
||||||
|
|
||||||
@ -44,11 +38,9 @@ define(
|
|||||||
state = DISCONNECTED;
|
state = DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback if the HTTP request succeeds. CouchDB may
|
// Callback if the HTTP request succeeds.
|
||||||
// report an error, so check for that.
|
|
||||||
function handleResponse(response) {
|
function handleResponse(response) {
|
||||||
var data = response.data;
|
state = CONNECTED;
|
||||||
state = data.error ? SEMICONNECTED : CONNECTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to connect to CouchDB, and update the indicator.
|
// Try to connect to CouchDB, and update the indicator.
|
||||||
@ -58,7 +50,7 @@ define(
|
|||||||
|
|
||||||
// Update the indicator initially, and start polling.
|
// Update the indicator initially, and start polling.
|
||||||
updateIndicator();
|
updateIndicator();
|
||||||
$interval(updateIndicator, INTERVAL);
|
$interval(updateIndicator, INTERVAL, false);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
@ -98,6 +90,6 @@ define(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return CouchIndicator;
|
return ElasticIndicator;
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -13,6 +13,76 @@ define(
|
|||||||
mockPromise,
|
mockPromise,
|
||||||
indicator;
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user