more cli tests

This commit is contained in:
Thomas Ruoff
2016-03-08 22:32:30 +01:00
parent a82891c9e8
commit 03f11a88d5
2 changed files with 63 additions and 1 deletions

View File

@@ -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]');
});
});
});