+
90
+ ? "progress-bar bg-danger"
+ : progress.value > 75
+ ? "progress-bar bg-warning"
+ : "progress-bar bg-success"
+ }
+ role="progressbar"
+ style={{ width: progress.value + "%" }}
+ aria-valuenow={progress.value}
+ aria-valuemin="0"
+ aria-valuemax="100"
+ />
+
+
+ )
+ );
+};
+SilenceProgress.propTypes = {
+ silence: APISilence.isRequired,
+};
export { SilenceProgress };
diff --git a/ui/src/Components/ManagedSilence/SilenceProgress.test.js b/ui/src/Components/ManagedSilence/SilenceProgress.test.js
index f305a6cb2..b41b738ea 100644
--- a/ui/src/Components/ManagedSilence/SilenceProgress.test.js
+++ b/ui/src/Components/ManagedSilence/SilenceProgress.test.js
@@ -2,8 +2,6 @@ import React from "react";
import { mount } from "enzyme";
-import { toJS } from "mobx";
-
import toDiffableHtml from "diffable-html";
import moment from "moment";
@@ -14,6 +12,10 @@ import { SilenceProgress } from "./SilenceProgress";
let silence;
+beforeAll(() => {
+ jest.useFakeTimers();
+});
+
beforeEach(() => {
silence = MockSilence();
@@ -57,24 +59,22 @@ describe("
", () => {
expect(toDiffableHtml(tree.html())).toMatch(/progress-bar bg-success/);
});
- it("calling calculate() on progress multiple times in a row doesn't change the value", () => {
- const startsAt = moment.utc([2000, 0, 1, 0, 0, 0]);
- const endsAt = moment.utc([2000, 0, 1, 1, 0, 0]);
-
+ it("progressbar is updated every 30 seconds", () => {
+ advanceTo(moment.utc([2000, 0, 1, 0, 30, 0]));
const tree = MountedSilenceProgress();
- const instance = tree.instance();
+ expect(toDiffableHtml(tree.html())).toMatch(/progress-bar bg-success/);
- const value = toJS(instance.progress.value);
- instance.progress.calculate(startsAt, endsAt);
- instance.progress.calculate(startsAt, endsAt);
- instance.progress.calculate(startsAt, endsAt);
- expect(toJS(instance.progress.value)).toBe(value);
+ advanceTo(moment.utc([2000, 0, 1, 0, 50, 0]));
+ jest.runOnlyPendingTimers();
+ expect(toDiffableHtml(tree.html())).toMatch(/progress-bar bg-warning/);
+
+ advanceTo(moment.utc([2000, 0, 1, 0, 55, 0]));
+ jest.runOnlyPendingTimers();
+ expect(toDiffableHtml(tree.html())).toMatch(/progress-bar bg-danger/);
});
- it("resets the timer on unmount", () => {
+ it("unmounts cleanly", () => {
const tree = MountedSilenceProgress();
- expect(tree.instance().progressTimer).not.toBeNull();
- tree.instance().componentWillUnmount();
- expect(tree.instance().progressTimer).toBeNull();
+ tree.unmount();
});
});