* 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
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { UhkBuffer, UserConfiguration } from '../../uhk-common/index';
|
|
|
|
const fs = require('fs');
|
|
|
|
const userConfig = JSON.parse(fs.readFileSync('../uhk-web/src/app/services/user-config.json'));
|
|
|
|
describe('Test Serializer', () => {
|
|
it('full config match', () => {
|
|
const config1Js = userConfig;
|
|
const config1Ts: UserConfiguration = new UserConfiguration().fromJsonObject(config1Js);
|
|
const config1Buffer = new UhkBuffer();
|
|
config1Ts.toBinary(config1Buffer);
|
|
const config1BufferContent = config1Buffer.getBufferContent();
|
|
fs.writeFileSync('user-config.bin', config1BufferContent);
|
|
|
|
config1Buffer.offset = 0;
|
|
console.log();
|
|
const config2Ts = new UserConfiguration().fromBinary(config1Buffer);
|
|
console.log('\n');
|
|
const config2Js = config2Ts.toJsonObject();
|
|
const config2Buffer = new UhkBuffer();
|
|
config2Ts.toBinary(config2Buffer);
|
|
fs.writeFileSync('user-config-serialized.json', JSON.stringify(config2Js, undefined, 4));
|
|
const config2BufferContent = config1Buffer.getBufferContent();
|
|
fs.writeFileSync('user-config-serialized.bin', config2BufferContent);
|
|
|
|
expect(config1Js).toEqual(config2Js);
|
|
|
|
const buffersContentsAreEqual: boolean = Buffer.compare(config1BufferContent, config2BufferContent) === 0;
|
|
expect(buffersContentsAreEqual).toBe(true);
|
|
|
|
});
|
|
|
|
it('check json serializer', () => {
|
|
const config1Ts: UserConfiguration = new UserConfiguration().fromJsonObject(userConfig);
|
|
const jsonObject = config1Ts.toJsonObject();
|
|
|
|
expect(jsonObject).toEqual(userConfig);
|
|
});
|
|
});
|