describe('zwaveService', () => { const zwaveService = ZwaveService(gladys, 'be86c4db-489f-466c-aeea-1e262c4ee720'); it('should have controllers', () => { expect(zwaveService) .to.have.property('controllers') .and.be.instanceOf(Object); }); it('should start service', async () => { await zwaveService.start(); }); it('should stop service', async () => { await zwaveService.stop(); }); });
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("_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); }); });
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("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); }); });
describe('#Cli', () => { it('should return a Cli instance with correct default options', () => { const cli = new Cli(); cli.should.be.instanceof(Cli); cli.should.have.property('prefix', 'LANDO'); cli.should.have.property('logLevel', 'warn'); cli.should.have.property('userConfRoot').and.not.be.empty; }); it('should return a Cli instance with custom options', () => { const prefix = '16309'; const logLevel = 'allthelogz'; const userConfRoot = '/tmp'; const cli = new Cli(prefix, logLevel, userConfRoot); cli.should.be.instanceof(Cli); cli.should.have.property('prefix', prefix); cli.should.have.property('logLevel', logLevel); cli.should.have.property('userConfRoot', userConfRoot); }); });
expect(oneHouse) .to.have.property('rooms') .and.to.be.instanceOf(Array); }); });
describe('service', () => { const stateManager = new StateManager(); const service = new Service(services, stateManager); it('should start a service', async () => { await service.load(gladys); await service.start('example'); }); it('should return the example service', async () => { expect(service.getService('example')).to.be.instanceOf(Object).and.to.be.not.null; // eslint-disable-line }); it('should return null a service', async () => { expect(service.getService('DONOTEXIST')).to.be.null; // eslint-disable-line }); it('should return service with message capabilities', async () => { const messageServices = await service.getMessageServices(); expect(messageServices).to.be.instanceOf(Array); }); it('should return service by name', async () => { const testService = await service.getByName('test-service'); expect(testService).to.have.property('name', 'test-service'); }); it('should throw service not found', async () => { const promise = service.getByName('not-found'); return assert.isRejected(promise, 'SERVICE_NOT_FOUND'); }); });
describe('Light.buildLightObject', () => { it('should should build light object with binary deviceFeature', async () => { const stateManager = new StateManager(event); const deviceManager = new Device(event, {}, stateManager, {}); const device = { id: '78ffc050-71c4-4dfe-8f3b-4b153e79c457', selector: 'test', features: [ { category: DEVICE_FEATURE_CATEGORIES.LIGHT, type: DEVICE_FEATURE_TYPES.LIGHT.BINARY, }, ], }; const light = deviceManager.lightManager.buildLightObject(device); expect(light) .to.have.property('turnOn') .and.be.instanceOf(Function); expect(light) .to.have.property('turnOff') .and.be.instanceOf(Function); }); });
describe('ExampleService', () => { const exampleService = ExampleService(); it('should have start function', () => { expect(exampleService) .to.have.property('start') .and.be.instanceOf(Function); }); it('should have stop function', () => { expect(exampleService) .to.have.property('stop') .and.be.instanceOf(Function); }); it('should have light object', () => { expect(exampleService) .to.have.property('light') .and.be.instanceOf(Object); }); it('exampleService.light should have turnOn function', () => { expect(exampleService.light) .to.have.property('turnOn') .and.be.instanceOf(Function); }); it('exampleService.light should have turnOff function', () => { expect(exampleService.light) .to.have.property('turnOff') .and.be.instanceOf(Function); }); });
describe('PhilipsHueService', () => { it('should have controllers', () => { const philipsHueService = PhilipsHueService(); expect(philipsHueService) .to.have.property('controllers') .and.be.instanceOf(Object); }); it('should start service', async () => { const philipsHueService = PhilipsHueService(); await philipsHueService.start(); }); it('should stop service', async () => { const philipsHueService = PhilipsHueService(); await philipsHueService.stop(); }); });