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; }); });
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("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("_createGraph", () => { it("should create a blessed-contrib line graph", () => { sandbox.spy(testContainer, "append"); options.layoutConfig.view.limit = 8; sandbox.stub(BaseLineGraph.prototype, "_createGraph"); const baseGraph = new BaseLineGraph(options); BaseLineGraph.prototype._createGraph.restore(); expect(baseGraph).to.not.have.property("node"); baseGraph._createGraph(options); expect(baseGraph).to.have.property("node").that.is.an.instanceof(contrib.line); expect(baseGraph.node).to.have.nested.property("options.label", " graph A "); expect(baseGraph.node).to.have.nested.property("options.maxY", undefined); expect(baseGraph.node).to.have.property("position") .that.deep.equals(options.layoutConfig.getPosition(options.parent)); expect(testContainer.append).to.have.been.calledOnce.and.calledWithExactly(baseGraph.node); }); });
describe("constructor", () => { beforeEach(() => { sandbox.stub(BaseLineGraph.prototype, "_createGraph"); }); it("should use limit from layoutConfig", () => { const limit = 7; options.layoutConfig.view.limit = limit; const baseGraph = new BaseLineGraph(options); expect(baseGraph).to.have.property("limit", limit); expect(baseGraph).to.have.nested.property("series.a.y") .that.deep.equals(_.times(limit, _.constant(0))); }); it("should create graph and set up event listener", () => { const baseGraph = new BaseLineGraph(options); expect(baseGraph).to.be.an.instanceof(BaseView); expect(baseGraph._createGraph).to.have.been.calledOnce; expect(testContainer.screen.on).to.have.been.calledWithExactly("metrics", 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; }); });