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("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); }); });
it("validates data received and hides when valid", () => { const mockData = { textBox: "" }; const mockValidatedData = ""; const stubValidate = sandbox.stub(options.metricsProvider, "validateTimeLabel").returns(mockValidatedData); const gotoTimeView = new GotoTimeView(options); const spyValidate = sandbox.spy(gotoTimeView, "validate"); const spyHide = sandbox.spy(gotoTimeView, "hide"); gotoTimeView.form.emit("submit", mockData); expect(stubValidate) .to.have.been.calledOnce .and.to.have.been.calledWithExactly(mockData.textBox); expect(spyValidate) .to.have.been.calledOnce .and.to.have.been.calledWithExactly(mockData) .and.to.have.returned(mockValidatedData); expect(spyHide).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("onEvent", () => { it("should call update for each gauge", () => { const memory = new MemoryGaugeView(options); expect(memory).to.have.property("heapGauge").that.is.an.instanceof(contrib.gauge); expect(memory).to.have.property("rssGauge").that.is.an.instanceof(contrib.gauge); sandbox.stub(memory, "update"); const mem = { heapUsed: 23, heapTotal: 39, rss: 290, systemTotal: 80010 }; memory.onEvent({ mem }); expect(memory.update).to.have.been.calledTwice .and.to.have.been.calledWithExactly(memory.heapGauge, mem.heapUsed, mem.heapTotal) .and.to.have.been.calledWithExactly(memory.rssGauge, mem.rss, mem.systemTotal); }); });
describe("constructor", () => { it("should create a box with two gauges and listen for metrics event", () => { const append = sandbox.spy(blessed.node.prototype, "append"); const memory = new MemoryGaugeView(options); expect(memory).to.have.property("node").that.is.an.instanceof(blessed.box); expect(memory.node).to.have.nested.property("options.label", " memory "); expect(append.thirdCall).to.have.been.calledOn(testContainer) .and.calledWithExactly(memory.node); expect(testContainer.screen.on).to.have.been.calledWithExactly("metrics", sinon.match.func); expect(memory).to.have.property("heapGauge").that.is.an.instanceof(contrib.gauge); expect(memory.heapGauge).to.have.nested.property("options.label", "heap"); expect(append.firstCall).to.have.been.calledOn(memory.node) .and.calledWithExactly(memory.heapGauge); expect(memory).to.have.property("rssGauge").that.is.an.instanceof(contrib.gauge); expect(memory.rssGauge).to.have.nested.property("options.label", "resident"); expect(append.secondCall).to.have.been.calledOn(memory.node) .and.calledWithExactly(memory.rssGauge); }); });
.and.to.have.been.calledWithExactly(mockData.textBox); .and.to.have.been.calledWithExactly(mockData) .and.to.have.thrown(mockError); .to.have.been.calledWithExactly(mockError.message);
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); }); });
memory.update(memory.rssGauge, used, total); expect(memory.rssGauge.setPercent).to.have.been.calledOnce.and.calledWithExactly(pct); expect(memory.heapGauge.setLabel).to.have.been.calledWithExactly("resident: 50 kB / 60.3 MB"); }); .and.calledWithExactly([ { percent: 20, stroke: "red" }, ]); expect(memory.heapGauge.setLabel).to.have.been.calledWithExactly("heap: 500 B / 2.5 kB"); }); });
expect(cpu.update).to.have.been.calledOnce.and.calledWithExactly({ cpu: "3.2" }); expect(cpu.update).to.have.been.calledTwice.and.calledWithExactly({ cpu: "9.0" }); }); });
streamView.log("something\nmultiline\n"); expect(streamView.node.log).to.have.been.calledOnce .and.calledWithExactly("something\nmultiline"); }); .and.calledWithExactly("THIS should be included"); .and.calledWithExactly(" should be included"); }); .and.calledWithExactly("but not THIS one\nor that one"); }); });
.and.calledWithExactly("resize", sinon.match.func); .and.calledWithExactly(testContainer); expect(baseView._getPosition(testContainer)).to.equal( options.layoutConfig.getPosition.firstCall.returnValue
eventLoop.onEvent({ eventLoop: data }); expect(eventLoop.update).to.have.been.calledOnce .and.calledWithExactly({ delay: data.delay, high: data.high }); });
context('#express warns when redundant param is passed', function() { it('warns on given both params \'expressApp\' and \'router\'', function() { var bkp = console.warn.bind(); console.warn = sinon.spy(); testApp.express({ expressApp: app, router: express.Router() }); var warning = 'Usage deprecated: Both \'expressApp\' and \'router\' are specified.\nMore details on https://github.com/alexa-js/alexa-app/blob/master/UPGRADING.md'; expect(console.warn).to.have.been.calledWithExactly(warning); console.warn = bkp; }); });
describe('.searchTs(sessionNum, sessionTimeMS)', function () { it('sends cmd with args', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.playbackControls.searchTs(1, 5000) sendCmd.should.have.been.calledWithExactly(12, 1, 5000) }) })