* test: add basis of the unit testing of the uhk-common package * test(serializer): Add KeystrokeAction tests * fix(serializer): Fix KeystrokeAction scancode mapping * test(serializer): Add NoneAction test cases * test(serializer): Add MouseAction test cases * test(serializer): Add PlayMacroAction test cases * test(serializer): Add SwitchKeymapAction test cases * test(serializer): Add UserConfiguration test cases fix KeyAction mapping * test(serializer): Add SwitchLayerAction test cases
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { NoneAction } from './none-action';
|
|
import { keyActionType } from './key-action';
|
|
import { UhkBuffer } from '../../uhk-buffer';
|
|
import { binaryDefaultHelper, jsonDefaultHelper } from '../../../../test/serializer-test-helper';
|
|
|
|
// TODO: Add null, undefined, empty object, empty buffer test cases
|
|
describe('node-action', () => {
|
|
it('should be instantiate', () => {
|
|
const action = new NoneAction();
|
|
expect(action).toBeTruthy();
|
|
});
|
|
|
|
describe('fromJsonObject', () => {
|
|
it('should map null', () => {
|
|
const action = new NoneAction();
|
|
expect(action.fromJsonObject({keyActionType: keyActionType.NoneAction})).toEqual(new NoneAction());
|
|
});
|
|
});
|
|
|
|
describe('toJsonObject', () => {
|
|
it('should work', () => {
|
|
const action = new NoneAction();
|
|
expect(action.toJsonObject()).toEqual({
|
|
keyActionType: keyActionType.NoneAction
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('fromBinary', () => {
|
|
it('should work', () => {
|
|
const buffer = new UhkBuffer();
|
|
const action = new NoneAction();
|
|
action.toBinary(buffer);
|
|
expect(action).toEqual(new NoneAction());
|
|
});
|
|
});
|
|
|
|
describe('toBinary', () => {
|
|
it('should work', () => {
|
|
const buffer = new UhkBuffer();
|
|
const action = new NoneAction();
|
|
action.toBinary(buffer);
|
|
|
|
const expected = new UhkBuffer();
|
|
expected.offset = 1;
|
|
expect(buffer).toEqual(expected);
|
|
});
|
|
});
|
|
|
|
describe('toString', () => {
|
|
it('should return with "<NoneAction>"', () => {
|
|
const action = new NoneAction();
|
|
expect(action.toString()).toEqual('<NoneAction>');
|
|
});
|
|
});
|
|
|
|
describe('getName', () => {
|
|
it('should return with "NoneAction"', () => {
|
|
const action = new NoneAction();
|
|
expect(action.getName()).toEqual('NoneAction');
|
|
});
|
|
});
|
|
|
|
describe('full serialization', () => {
|
|
it('should json match with default constructor', () => {
|
|
jsonDefaultHelper(new NoneAction());
|
|
});
|
|
|
|
it('should binary match with default constructor', () => {
|
|
binaryDefaultHelper(new NoneAction());
|
|
});
|
|
});
|
|
});
|