feat(ui): track version changes and mark it with upgradeNeeded

This commit is contained in:
Łukasz Mierzwa
2018-09-16 21:21:06 +01:00
parent f225292dad
commit 66d64081c0
2 changed files with 22 additions and 1 deletions

View File

@@ -142,7 +142,8 @@ class AlertStore {
info = observable(
{
totalAlerts: 0,
version: "unknown"
version: "unknown",
upgradeNeeded: false
},
{},
{ name: "API response info" }
@@ -272,6 +273,13 @@ class AlertStore {
this.data = Object.assign(this.data, updates);
}
// before storing new version check if we need to reload
if (
this.info.version !== "unknown" &&
this.info.version !== result.version
) {
this.info.upgradeNeeded = true;
}
// update extra root level keys that are stored under 'info'
for (const key of ["totalAlerts", "version"]) {
if (this.info[key] !== result[key]) {

View File

@@ -304,4 +304,17 @@ describe("AlertStore.fetch", () => {
annotationsVisible: []
});
});
it("wants to reload page after new version is returned in the API", async () => {
const response = EmptyAPIResponse();
fetch.mockResponse(JSON.stringify(response));
const store = new AlertStore(["label=value"]);
await expect(store.fetch()).resolves.toBeUndefined();
expect(store.info.upgradeNeeded).toBe(false);
response.version = "newFakeVersion";
fetch.mockResponse(JSON.stringify(response));
await expect(store.fetch()).resolves.toBeUndefined();
expect(store.info.upgradeNeeded).toBe(true);
});
});