|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -import OsInputCapture from '../lib/os-input-capture.js'; |
| 3 | +import oic from '../lib/os-input-capture.js'; |
| 4 | +import _ from 'lodash'; |
4 | 5 |
|
5 | 6 | let globals = {};
|
6 | 7 |
|
7 |
| -describe('OsInputCapture', () => { |
| 8 | +describe('oic', () => { |
8 | 9 | beforeEach(() => {
|
9 |
| - globals.osInputCapture = new OsInputCapture(); |
| 10 | + _.assign(globals, { oic }); |
10 | 11 | });
|
11 |
| - it('should be defined', () => { |
12 |
| - expect(globals.osInputCapture).toBeDefined(); |
| 12 | + it('should expose the core classes', () => { |
| 13 | + expect(globals.oic.OsInputCapture).toBeDefined(); |
| 14 | + expect(globals.oic.KeyboardLogger).toBeDefined(); |
| 15 | + expect(globals.oic.MouseLogger).toBeDefined(); |
| 16 | + expect(globals.oic.WindowLogger).toBeDefined(); |
13 | 17 | });
|
14 |
| - it('should create instances of the logger classes', () => { |
15 |
| - expect(globals.osInputCapture.keyboardLogger).toBeDefined(); |
16 |
| - expect(globals.osInputCapture.mouseLogger).toBeDefined(); |
17 |
| - expect(globals.osInputCapture.windowLogger).toBeDefined(); |
| 18 | + describe('OsInputCapture', () => { |
| 19 | + it('should not add any loggers by default', () => { |
| 20 | + let inputLogger = new globals.oic.OsInputCapture(); |
| 21 | + expect(inputLogger.keyboardLogger).not.toBeDefined(); |
| 22 | + expect(inputLogger.mouseLogger).not.toBeDefined(); |
| 23 | + expect(inputLogger.windowLogger).not.toBeDefined(); |
| 24 | + }); |
| 25 | + it('should add keyboard logger if specified', () => { |
| 26 | + let inputLogger = new globals.oic.OsInputCapture(['keyboard']); |
| 27 | + expect(inputLogger.keyboardLogger).toBeDefined(); |
| 28 | + }); |
| 29 | + it('should add mouse logger if specified', () => { |
| 30 | + let inputLogger = new globals.oic.OsInputCapture(['mouse']); |
| 31 | + expect(inputLogger.mouseLogger).toBeDefined(); |
| 32 | + }); |
| 33 | + it('should add window logger if specified', () => { |
| 34 | + let inputLogger = new globals.oic.OsInputCapture(['window']); |
| 35 | + expect(inputLogger.windowLogger).toBeDefined(); |
| 36 | + }); |
| 37 | + describe('addKeyboardLogger', () => { |
| 38 | + it('should add keyboard logger to OsInputCapture', () => { |
| 39 | + let inputLogger = new globals.oic.OsInputCapture(); |
| 40 | + inputLogger.addKeyboardLogger({}); |
| 41 | + expect(inputLogger.keyboardLogger).toBeDefined(); |
| 42 | + }); |
| 43 | + it('should use supplied opts if present', () => { |
| 44 | + let fakeOpts = { |
| 45 | + keyboardOptions: { |
| 46 | + inputPath: 'fakeInputPath', |
| 47 | + outputDir: 'fakeOutputPath' |
| 48 | + } |
| 49 | + }; |
| 50 | + let inputLogger = new globals.oic.OsInputCapture(); |
| 51 | + inputLogger.addKeyboardLogger(fakeOpts); |
| 52 | + expect(inputLogger.keyboardLogger.opts).toEqual(fakeOpts.keyboardOptions); |
| 53 | + }); |
| 54 | + }); |
| 55 | + describe('addMouseLogger', () => { |
| 56 | + it('should add mouse logger to OsInputCapture', () => { |
| 57 | + let inputLogger = new globals.oic.OsInputCapture(); |
| 58 | + inputLogger.addMouseLogger({}); |
| 59 | + expect(inputLogger.mouseLogger).toBeDefined(); |
| 60 | + }); |
| 61 | + it('should use supplied opts if present', () => { |
| 62 | + let fakeOpts = { |
| 63 | + mouseOptions: { |
| 64 | + inputPath: 'fakeInputPath', |
| 65 | + outputDir: 'fakeOutputPath' |
| 66 | + } |
| 67 | + }; |
| 68 | + let inputLogger = new globals.oic.OsInputCapture(); |
| 69 | + inputLogger.addMouseLogger(fakeOpts); |
| 70 | + expect(inputLogger.mouseLogger.opts).toEqual(fakeOpts.mouseOptions); |
| 71 | + }); |
| 72 | + }); |
| 73 | + describe('addWindowLogger', () => { |
| 74 | + it('should add window logger to OsInputCapture', () => { |
| 75 | + let inputLogger = new globals.oic.OsInputCapture(); |
| 76 | + inputLogger.addWindowLogger({}); |
| 77 | + expect(inputLogger.windowLogger).toBeDefined(); |
| 78 | + }); |
| 79 | + it('should use supplied opts if present', () => { |
| 80 | + let fakeOpts = { |
| 81 | + windowOptions: { |
| 82 | + outputDir: 'fakeOutputPath' |
| 83 | + } |
| 84 | + }; |
| 85 | + let inputLogger = new globals.oic.OsInputCapture(); |
| 86 | + inputLogger.addWindowLogger(fakeOpts); |
| 87 | + expect(inputLogger.windowLogger.opts).toEqual(fakeOpts.windowOptions); |
| 88 | + }); |
| 89 | + }); |
| 90 | + describe('toggleActive', () => { |
| 91 | + it('should toggle its own active state', () => { |
| 92 | + let inputLogger = new globals.oic.OsInputCapture(); |
| 93 | + let originalState = inputLogger.active; |
| 94 | + inputLogger.toggleActive(); |
| 95 | + expect(inputLogger.active).toEqual(!originalState); |
| 96 | + }); |
| 97 | + it('should toggle its keyboardLogger active state if its defined', () => { |
| 98 | + let fakeOpts = { |
| 99 | + keyboardOptions: { |
| 100 | + inputPath: 'fakeInputPath', |
| 101 | + outputDir: 'fakeOutputPath' |
| 102 | + } |
| 103 | + }; |
| 104 | + let inputLogger = new globals.oic.OsInputCapture(['keyboard'], fakeOpts); |
| 105 | + let originalState = inputLogger.keyboardLogger.active; |
| 106 | + inputLogger.toggleActive(); |
| 107 | + expect(inputLogger.keyboardLogger.active).toEqual(!originalState); |
| 108 | + }); |
| 109 | + it('should toggle its mouseLogger active state if its defined', () => { |
| 110 | + let fakeOpts = { |
| 111 | + mouseOptions: { |
| 112 | + inputPath: 'fakeInputPath', |
| 113 | + outputDir: 'fakeOutputPath' |
| 114 | + } |
| 115 | + }; |
| 116 | + let inputLogger = new globals.oic.OsInputCapture(['mouse'], fakeOpts); |
| 117 | + let originalState = inputLogger.mouseLogger.active; |
| 118 | + inputLogger.toggleActive(); |
| 119 | + expect(inputLogger.mouseLogger.active).toEqual(!originalState); |
| 120 | + }); |
| 121 | + it('should toggle its keyboardLogger active state if its defined', () => { |
| 122 | + let fakeOpts = { |
| 123 | + windowOptions: { |
| 124 | + outputDir: 'fakeOutputPath' |
| 125 | + } |
| 126 | + }; |
| 127 | + let inputLogger = new globals.oic.OsInputCapture(['window'], fakeOpts); |
| 128 | + let originalState = inputLogger.windowLogger.active; |
| 129 | + inputLogger.toggleActive(); |
| 130 | + expect(inputLogger.windowLogger.active).toEqual(!originalState); |
| 131 | + }); |
| 132 | + }); |
| 133 | + describe('getWindow', () => { |
| 134 | + it('should call windowLogger.get if this.windowLogger is defined', () => { |
| 135 | + let fakeOpts = { |
| 136 | + windowOptions: { |
| 137 | + outputDir: 'fakeOutputPath' |
| 138 | + } |
| 139 | + }; |
| 140 | + let inputLogger = new globals.oic.OsInputCapture(['window'], fakeOpts); |
| 141 | + spyOn(inputLogger.windowLogger, 'get'); |
| 142 | + inputLogger.getWindow(); |
| 143 | + expect(inputLogger.windowLogger.get).toHaveBeenCalled(); |
| 144 | + }); |
| 145 | + }); |
18 | 146 | });
|
19 | 147 | });
|
0 commit comments