From 03f11a88d5d4f95a66138850780921e405901209 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Tue, 8 Mar 2016 22:32:30 +0100 Subject: [PATCH] more cli tests --- cli.js | 2 +- test/cli.tests.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/cli.js b/cli.js index b067092..95345d6 100755 --- a/cli.js +++ b/cli.js @@ -39,7 +39,7 @@ if (argv.help || argv.h) { console.log('Using profile', profile); } - console.log('Switching on', selectedMonitors); + console.log('Switching on', selectedMonitors.length ? selectedMonitors : 'all connected monitors'); devices.then(devices => { const xrandrOptions = swm.generateXrandrOptions(selectedMonitors, devices); diff --git a/test/cli.tests.js b/test/cli.tests.js index 6b55674..d48addd 100644 --- a/test/cli.tests.js +++ b/test/cli.tests.js @@ -52,5 +52,67 @@ describe('cli', () => { assert.equal(consoleLogSpy.args[1].join(' '), 'LVDS1: Connected'); assert.equal(consoleLogSpy.args[2].join(' '), 'HDMI2: Disconnected'); }); + + describe('switching', () => { + let minimistStub; + let selectedMonitors; + let deviceData; + let getDevicesStub; + let generateXrandrOptionsStub; + let switchDevicesStub; + let executePostCmdStub; + + beforeEach(() => { + selectedMonitors = ['LVDS1']; + minimistStub = sandbox.stub(); + minimistStub.returns({ + _: selectedMonitors, + postCmd: '[some post cmd]' + }); + + deviceData = { + LVDS1: {connected: true}, + HDMI2: {connected: false} + }; + + getDevicesStub = sandbox.stub().returns({ + then: cb => cb(deviceData) + }); + generateXrandrOptionsStub = sandbox.stub().returns('[some xrandr options]'); + switchDevicesStub = sandbox.stub(); + executePostCmdStub = sandbox.stub(); + + const cli = proxyquire('../cli.js', { + 'minimist': minimistStub, + './swm.js': { + getDevices: getDevicesStub, + generateXrandrOptions: generateXrandrOptionsStub, + switchDevices: switchDevicesStub, + executePostCmd: executePostCmdStub + }, + './config.js': {} + }); + }); + + it('calls getDevices', () => { + assert.equal(getDevicesStub.callCount, 1, 'calls device stub'); + }); + + it('calls generateXrandrOptions', () => { + assert.equal(generateXrandrOptionsStub.callCount, 1, 'calls generateXrandrOptions'); + assert.equal(generateXrandrOptionsStub.args[0][0], selectedMonitors); + }); + + it('calls switchDevices', () => { + assert.equal(switchDevicesStub.callCount, 1); + assert.equal(switchDevicesStub.args[0][0], '[some xrandr options]'); + }); + + it('calls executePostCmd', () => { + assert.equal(executePostCmdStub.callCount, 1); + assert.equal(executePostCmdStub.args[0][0], '[some post cmd]'); + + }); + }); });