mirror of
https://github.com/tomru/switchmon.git
synced 2026-03-03 06:27:23 +01:00
more cli tests
This commit is contained in:
@@ -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]');
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user