Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "main.js",
"bin": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "node test/serial-send-endline.test.js",
"start": "node main.js",
"make": "npm i -g pkg && pkg . && chmod -R 777 build"
},
Expand Down
37 changes: 37 additions & 0 deletions server/test/serial-send-endline.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const vm = require("vm");

const www = path.join(__dirname, "..", "www");
const html = fs.readFileSync(path.join(www, "index.html"), "utf8");
const expectedHandler = "input.sendText(input.textToSend, input.endlineToSend)";

const serialInput = html.match(/<input\b(?=[^>]*v-model="input\.textToSend")[^>]*>/);
const sendButton = html.match(/<button\b[^>]*>Send<\/button>/);

assert.ok(serialInput, "serial text input must exist");
assert.ok(sendButton, "serial send button must exist");
const enterHandler = serialInput[0].match(/v-on:keyup\.enter="([^"]+)"/);
const sendHandler = sendButton[0].match(/@click="([^"]+)"/);
assert.ok(enterHandler, "serial text input must define an Enter handler");
assert.ok(sendHandler, "serial send button must define a click handler");
assert.strictEqual(enterHandler[1], expectedHandler);
assert.strictEqual(sendHandler[1], expectedHandler);

const dataInput = fs.readFileSync(path.join(www, "classes", "communication", "data", "DataInput.js"), "utf8");
const dataInputSerial = fs.readFileSync(path.join(www, "classes", "communication", "data", "DataInputSerial.js"), "utf8");
const context = { module: { exports: {} } };
vm.runInNewContext(`${dataInput}\n${dataInputSerial}\nmodule.exports = DataInputSerial;`, context);

const messages = [];
const connection = { sendServerCommand: message => messages.push(message) };
const serial = new context.module.exports(connection, "Serial");
messages.length = 0;

for (const [lineEnding, expected] of [["\\r\\n", "\r\n"], ["\\n", "\n"], ["\\r", "\r"], ["", ""]]) {
serial.sendText("STATUS", lineEnding);
assert.strictEqual(messages.pop().text, `STATUS${expected}`);
}

console.log("serial send Enter and button handlers preserve the selected line ending");
4 changes: 2 additions & 2 deletions server/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
<div v-for="conn in connections" class="flex-col">
<div v-for="input in conn.inputs" class="flex-col">
<div v-if="input.type=='serial' && input.port" class="send-text-container">
<input v-on:keyup.enter="input.sendText(input.textToSend)" type="text" v-bind:placeholder="'Send to '+input.name+' '+input.port+' ('+input.connection.name+')'" v-model="input.textToSend" style="width:100%"/>
<input v-on:keyup.enter="input.sendText(input.textToSend, input.endlineToSend)" type="text" v-bind:placeholder="'Send to '+input.name+' '+input.port+' ('+input.connection.name+')'" v-model="input.textToSend" style="width:100%"/>
<select v-model="input.endlineToSend" style="max-width: 60px;">
<option value="\r\n">\r\n</option>
<option value="\n">\n</option>
Expand Down Expand Up @@ -352,4 +352,4 @@
<script src="./utils/stats/computeStats.js"></script>
<script src="./main.js"></script>

</html>
</html>