73 lines
2.7 KiB
JavaScript
Executable File
73 lines
2.7 KiB
JavaScript
Executable File
const WSSenderGrbl = require('../robot/WSSenderGrbl.js');
|
|
|
|
describe("WSSenderGrbl implements SenderInterface", () => {
|
|
|
|
test("is an instance of SenderInterface and exposes required methods", () => {
|
|
const SenderInterface = require('../robot/SenderInterface');
|
|
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
|
|
|
|
expect(sender).toBeInstanceOf(SenderInterface);
|
|
expect(typeof sender.connect).toBe('function');
|
|
expect(typeof sender.send).toBe('function');
|
|
expect(typeof sender.getStatus).toBe('function');
|
|
expect(typeof sender.disconnect).toBe('function');
|
|
});
|
|
|
|
test("test mode has connected status", () => {
|
|
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
|
|
expect(sender.getStatus()).toMatchObject({ state: 'connected', isTestMode: true });
|
|
});
|
|
|
|
test("send() returns false when not connected, true in test mode", () => {
|
|
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
|
|
expect(sender.send("G1 x1")).toBe(true);
|
|
|
|
sender.ws = null;
|
|
expect(sender.send("G1 x1")).toBe(false);
|
|
});
|
|
|
|
test("disconnect() transitions to disconnected state", () => {
|
|
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
|
|
sender.disconnect();
|
|
expect(sender.getStatus()).toMatchObject({ state: 'disconnected' });
|
|
});
|
|
|
|
});
|
|
|
|
describe("WSSenderGrbl.execCommand writes correct G-code via send()", () => {
|
|
|
|
test("writes correct G-code for xyz axes", () => {
|
|
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
|
|
|
|
const mOld = { x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, e: 0 };
|
|
const mNew = { x: 12.34, y: 1.0, z: 2.0, a: 0, b: 0, c: 0, e: 0 };
|
|
|
|
sender.execCommand("G1", mOld, mNew);
|
|
|
|
expect(sender.ws.written).toBe("G90 G1 x12.34 y57.30 z57.30 f2300.00\n");
|
|
});
|
|
|
|
test("writes correct G-code for elbow (a axis)", () => {
|
|
const sender = new WSSenderGrbl("test.test", 2300, "a", null, null);
|
|
|
|
const mOld = { x: 0, y: 0, z: 0, a: Math.PI, b: 0, c: 0, e: 0 };
|
|
const mNew = { x: 12.34, y: Math.PI / 2, z: 0, a: Math.PI / 8, b: 0, c: 0, e: 0 };
|
|
|
|
sender.execCommand("G1", mOld, mNew);
|
|
|
|
expect(sender.ws.written).toBe("G90 G1 x22.50 f2300.00\n");
|
|
});
|
|
|
|
test("G92 command is sent without extra G90 prefix", () => {
|
|
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
|
|
|
|
const mOld = { x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, e: 0 };
|
|
const mNew = { x: 12.34, y: 1.0, z: 2.0, a: 0, b: 0, c: 0, e: 0 };
|
|
|
|
sender.execCommand("G92", mOld, mNew);
|
|
|
|
expect(sender.ws.written.replace("G90 ", "")).toBe("G92 x12.34 y57.30 z57.30 f2300.00\n");
|
|
});
|
|
|
|
});
|