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", () => { 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); }); });
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("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("HelpView", () => { let sandbox; let testContainer; before(() => { sandbox = sinon.createSandbox(); }); beforeEach(() => { utils.stubWidgets(sandbox); testContainer = utils.getTestContainer(sandbox); }); afterEach(() => { sandbox.restore(); }); it("should create a box with text describing keybindings", () => { const help = new HelpView({ parent: testContainer }); expect(help).to.have.property("node").that.is.an.instanceof(blessed.box); expect(help.node).to.have.nested.property("options.content").that.contains("keybindings"); expect(help.node).to.have.property("hidden", true); }); });
/* 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%) "); });
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) "); });
it('returns a promise that resolves to events committed', () => es.commit([goodEvent, goodEvent2]).then(events => { expect(events).to.be.an('Array'); expect(events).to.have.length(2); expect(events).to.have.nested.property('[0].type', 'somethingHappened'); }));
it('should not find uninstrumented nodes when those nodes are filtered out', () => { // given const spans = [ ...trace(uiAppSpan(), serverSpan()), // ok ...trace(uiAppSpan(), mergedSpan()), // ok ...trace(uiAppSpan(), clientSpan()), // uninstrumented (downstream) ...trace(uiAppSpan(), meshSpan()) // uninstrumented (downstream) ]; const serviceName = 'some-ui-app'; const filter = ['upstream']; // when const {summary} = extractNodesAndLinks({spans, serviceName}, filter); // then expect(summary).to.have.property('hasViolations', false); expect(summary).to.not.have.nested.property('violations.uninstrumented'); });
describe('-> Create SMAPI client with bad version', function() { var smapiClient; beforeEach(function() { smapiClient = SMAPI_CLIENT({ version: 'bad', region: 'bad' }); }); it('responds with a Object with default version', function() { expect(smapiClient).to.have.property('version', 'v1'); expect(smapiClient).to.have.nested.property('version', 'v1'); }); });
describe('on(commandType, handler)', () => { it('validates parameters', () => { expect(() => bus.on()).to.throw(TypeError); expect(() => bus.on('test')).to.throw(TypeError); expect(() => bus.on('test', () => { })).to.not.throw(); }); it('sets up a handler on messageBus for a given commandType', () => { bus.on('doSomething', () => { }); expect(messageBus.on).to.have.property('calledOnce', true); expect(messageBus.on).to.have.nested.property('firstCall.args[0]', 'doSomething'); expect(messageBus.on).to.have.nested.property('firstCall.args[1]').that.is.a('Function'); }); });
describe('getAllEvents(eventTypes)', () => { it('returns a promise that resolves to all committed events of specific types', async () => { await es.commit([goodEvent, goodEvent2]); const events = []; for await (const e of es.getAllEvents(['somethingHappened'])) events.push(e); expect(events).to.have.length(2); expect(events).to.have.nested.property('[0].aggregateId', '1'); expect(events).to.have.nested.property('[1].aggregateId', '2'); }); });
describe('enqueue(commandType, aggregateId, commandPayload)', () => { it('adds command to saga.uncommittedMessages list', () => { s.apply({ type: 'somethingHappened' }); const { uncommittedMessages } = s; expect(uncommittedMessages).to.have.length(1); expect(uncommittedMessages[0]).to.have.property('sagaId', s.id); expect(uncommittedMessages[0]).to.have.property('sagaVersion', s.version - 1); expect(uncommittedMessages[0]).to.have.property('type', 'doSomething'); expect(uncommittedMessages[0]).to.have.nested.property('payload.foo', 'bar'); }); });