describe("form_onReset", () => { it("hides any error text being shown", () => { const gotoTimeView = new GotoTimeView(options); gotoTimeView.form.emit("reset"); expect(gotoTimeView.errorText.hide).to.have.been.calledOnce; }); });
/* eslint-disable no-magic-numbers */ it("should update series and label", () => { options.layoutConfig.view.limit = 4; options.layoutConfig.view.title = "cpu"; options.unit = "%"; const baseGraph = new BaseLineGraph(options); expect(baseGraph).to.have.nested.property("series.a.y").that.deep.equals([0, 0, 0, 0]); baseGraph.update({ a: 29 }); expect(baseGraph).to.have.nested.property("series.a.y").that.deep.equals([0, 0, 0, 29]); expect(baseGraph.node.setLabel).to.have.been.calledWith(" cpu (29%) "); baseGraph.update({ a: 8 }); expect(baseGraph).to.have.nested.property("series.a.y").that.deep.equals([0, 0, 29, 8]); expect(baseGraph.node.setLabel).to.have.been.calledWith(" cpu (8%) "); });
describe("node_onShow", () => { it("saves focus and pops up the dialog", () => { const gotoTimeView = new GotoTimeView(options); const spyTextBoxFocus = sandbox.spy(gotoTimeView.textBox, "focus"); gotoTimeView.node.emit("show"); expect(gotoTimeView.screen.saveFocus).to.have.been.calledOnce; expect(gotoTimeView.node.setFront).to.have.been.calledOnce; expect(gotoTimeView.form.reset).to.have.been.calledOnce; expect(spyTextBoxFocus).to.have.been.calledOnce; }); });
describe("acceptButton_onKey_escape", () => { it("presses the cancel button programmatically", () => { // to make the screen act like a real event emitter, set stubEvents to false // and create a new testContainer createTestContainer(false); const gotoTimeView = new GotoTimeView(options); gotoTimeView.acceptButton.focus(); gotoTimeView.screen.program.emit("keypress", "escape", { full: "escape" }); expect(gotoTimeView.cancelButton.press).to.have.been.calledOnce; }); });
describe("hide", () => { it("hides the popup and restores focus", () => { const gotoTimeView = new GotoTimeView(options); gotoTimeView.hide(); expect(gotoTimeView.node.hide).to.have.been.calledOnce; expect(gotoTimeView.screen.restoreFocus).to.have.been.calledOnce; expect(gotoTimeView.screen.render).to.have.been.calledOnce; }); });
describe("constructor", () => { it("should require logProvider", () => { options.logProvider = undefined; expect(() => { new StreamView(options); // eslint-disable-line no-new }).to.throw("StreamView requires logProvider"); }); it("should create a log node and listen for given events", () => { const streamView = new StreamView(options); expect(streamView).to.have.property("node").that.is.an.instanceof(blessed.log); expect(streamView.node).to.have.nested.property("options.label", " stdout / stderr "); expect(testContainer.screen.on).to.have.been .calledWithExactly("stdout", sinon.match.func) .and.calledWithExactly("stderr", sinon.match.func); }); });
describe("form_onCancel", () => { it("hides the popup", () => { const gotoTimeView = new GotoTimeView(options); const spyHide = sandbox.spy(gotoTimeView, "hide"); gotoTimeView.form.emit("cancel"); expect(spyHide).to.have.been.calledOnce; }); });
describe("screen_onMetrics", () => { it("updates the time range label", () => { // to make the screen act like a real event emitter, set stubEvents to false // and create a new testContainer createTestContainer(false); const gotoTimeView = new GotoTimeView(options); const spyGetTimeRangeLabel = sandbox.spy(gotoTimeView, "getTimeRangeLabel"); gotoTimeView.screen.emit("metrics"); expect(spyGetTimeRangeLabel).to.have.been.calledOnce; expect(gotoTimeView.timeRangeLabel.setContent) .to.have.been.calledWithExactly(spyGetTimeRangeLabel.returnValues[0]); }); });
describe("isVisible", () => { it("returns the visibility of the popup", () => { const gotoTimeView = new GotoTimeView(options); gotoTimeView.toggle(); expect(gotoTimeView.node.toggle).to.have.been.calledOnce; expect(gotoTimeView.isVisible()).to.equal(false); }); });
describe("acceptButton_onPress", () => { it("submits the form", () => { const gotoTimeView = new GotoTimeView(options); gotoTimeView.acceptButton.emit("press"); expect(gotoTimeView.form.submit).to.have.been.calledOnce; }); });
describe("textBox_onKey_enter", () => { it("presses the accept button programmatically", () => { // to make the screen act like a real event emitter, set stubEvents to false // and create a new testContainer createTestContainer(false); const gotoTimeView = new GotoTimeView(options); gotoTimeView.textBox.focus(); gotoTimeView.screen.program.emit("keypress", "enter", { full: "enter" }); expect(gotoTimeView.acceptButton.press).to.have.been.calledOnce; }); });
describe("toggle", () => { it("toggles the visibility of the popup", () => { const gotoTimeView = new GotoTimeView(options); gotoTimeView.toggle(); expect(gotoTimeView.node.toggle).to.have.been.calledOnce; }); });
describe("cancelButton_onPress", () => { it("cancels the form", () => { const gotoTimeView = new GotoTimeView(options); gotoTimeView.cancelButton.emit("press"); expect(gotoTimeView.form.cancel).to.have.been.calledOnce; }); });
describe("cancelButton_onKey_escape", () => { it("presses itself programmatically", () => { // to make the screen act like a real event emitter, set stubEvents to false // and create a new testContainer createTestContainer(false); const gotoTimeView = new GotoTimeView(options); gotoTimeView.cancelButton.focus(); gotoTimeView.screen.program.emit("keypress", "escape", { full: "escape" }); expect(gotoTimeView.cancelButton.press).to.have.been.calledOnce; }); });
describe("textBox_onKey_escape", () => { it("presses the cancel button programmatically", () => { // to make the screen act like a real event emitter, set stubEvents to false // and create a new testContainer createTestContainer(false); const gotoTimeView = new GotoTimeView(options); gotoTimeView.textBox.focus(); gotoTimeView.screen.program.emit("keypress", "escape", { full: "escape" }); expect(gotoTimeView.cancelButton.press).to.have.been.calledOnce; }); });