it("should update series without exceeding limit", () => { options.layoutConfig.view.limit = 3; options.series.high = { highwater: true }; const baseGraph = new BaseLineGraph(options); baseGraph.update({ a: 27, high: 27 }); expect(baseGraph).to.have.nested.property("series.a.y").that.deep.equals([0, 0, 27]); expect(baseGraph).to.have.nested.property("series.high.y").that.deep.equals([27, 27, 27]); });
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); }); });
/* 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("recalculatePosition", () => { it("should set new position and recreate node", () => { const baseGraph = new BaseLineGraph(options); sandbox.spy(testContainer, "remove"); sandbox.spy(testContainer, "append"); sandbox.stub(baseGraph, "_getPosition").returns({ top: "20%" }); baseGraph.recalculatePosition(); expect(baseGraph.node).to.have.property("position").that.deep.equals({ top: "20%" }); expect(testContainer.remove).to.have.been.calledOnce; expect(testContainer.append).to.have.been.calledOnce; }); it("should do nothing if position is unchanged", () => { options.layoutConfig.getPosition = function () { return { top: "10%" }; }; const baseGraph = new BaseLineGraph(options); const originalPosition = baseGraph.node.position; sandbox.spy(testContainer, "remove"); sandbox.stub(baseGraph, "_getPosition").returns({ top: "10%" }); baseGraph.recalculatePosition(); expect(baseGraph.node).to.have.property("position", originalPosition); expect(testContainer.remove).to.have.not.been.called; }); });
it("should update highwater series", () => { options.layoutConfig.view.limit = 3; options.series.high = { highwater: true }; const baseGraph = new BaseLineGraph(options); expect(baseGraph).to.have.nested.property("series.a.y").that.deep.equals([0, 0, 0]); expect(baseGraph).to.have.nested.property("series.high").that.deep.equals({ x: [":02", ":01", ":00"], y: [0, 0, 0], style: { line: "red" } }); baseGraph.update({ a: 2, high: 4 }); expect(baseGraph).to.have.nested.property("series.a.y").that.deep.equals([0, 0, 2]); expect(baseGraph).to.have.nested.property("series.high").that.deep.equals({ x: [":02", ":01", ":00"], y: [4, 4, 4], style: { line: "red" } }); expect(baseGraph.node.setLabel).to.have.been.calledWith(" graph A (2), high (4) "); });
// receiving metrics now would cause an emit sandbox.stub(metricsProvider, "emit").callsFake((key, data, discardEvent) => { if (discardEvent) { return; } expect(key) .to.be.a("string") .that.equals("metrics"); expect(data) .to.be.an("object") .that.deep.equals( _.last(metricsProvider._aggregation[metricsProvider.zoomLevelKey].data) ); });
/* eslint prefer-arrow-callback: 0 */ describe('request headers transformation', function desc() { it('should correct headers', () => { const bad_headers = { '': 'header0', 'p3p ': 'header1', ' aze': 'header2', ' aze-sdf-aze': 'header3', ' #aze #12': 'header4', 'X-Normal-Header': 'header5', }; const good_headers = { 'p3p': 'header1', 'aze': 'header2', 'aze-sdf-aze': 'header3', 'aze12': 'header4', 'X-Normal-Header': 'header5', }; const expected = sanitize.headers(bad_headers); expect(expected).to.be.deep.equals(good_headers); }); });
it("wait day of month", () => { // 1565540804 = Sunday 11 August 2019 16:26:44 const wait = new Wait().dayOfMonth(11); expect(wait._getTimestampOrDuration()).to.be.deep.equals([1565540804, null]); });