Skip to content

Commit 331e4dc

Browse files
committed
adding automated test for checking pins
1 parent a95121c commit 331e4dc

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

__tests__/Interpreter.e2e.test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const sleep = (milliseconds) => {
1111

1212
const runIcon = "#arduino_simulator_start_icon"
1313
const stopIcon = "#arduino_simulator_stop_icon"
14+
const pinDigital0 =
15+
"#root > div:nth-child(4) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)"
16+
const pinAnalog0 =
17+
"#root > div:nth-child(4) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)"
1418
const serialInput =
1519
"#root > div:nth-child(4) > div:nth-child(3) > div:nth-child(2) > input:nth-child(1)"
1620
const serialSubmit =
@@ -33,7 +37,7 @@ describe("Interpreter End-To-End", () => {
3337
},
3438
})
3539
window.DEFAULT_SKETCH =
36-
'/*\n\nArduino Simulator developed by LRusso.com\n\n*/\n\nchar charOne[] = "Char 1 example.";\nString stringOne = "String 1 example.";\nString stringTwo = String("String 2 example.");\nString stringThree = String(15);\nString stringFour = String(15.50);\n\nvoid setup()\n\t{\n\tSerial.begin(9600);\n\tSerial.println(charOne);\n\tSerial.println(stringOne);\n\tSerial.println(stringTwo);\n\tSerial.println(stringThree);\n\tSerial.println(stringFour);\n\tSerial.println("------------------");\n\tSerial.println("Write something in the textbox above to test that this sketch sends the serial data to the Arduino board and back to the Serial Monitor.");\n\t}\n\nvoid loop()\n\t{\n\twhile(Serial.available()>0)\n\t\t{\n\t\tchar receivedChar = Serial.read();\n\t\tSerial.print(receivedChar);\n\t\t}\n\t}'
40+
'/*\n\nArduino Simulator developed by LRusso.com\n\n*/\n\nint LED_PIN = 0;\nint DCMOTOR_PIN = 0;\nchar charOne[] = "Char 1 example.";\nString stringOne = "String 1 example.";\nString stringTwo = String("String 2 example.");\nString stringThree = String(15);\nString stringFour = String(15.50);\n\nvoid setup()\n\t{\n\tSerial.begin(9600);\n\tSerial.println(charOne);\n\tSerial.println(stringOne);\n\tSerial.println(stringTwo);\n\tSerial.println(stringThree);\n\tSerial.println(stringFour);\n\tSerial.println("------------------");\n\tSerial.println("Write something in the textbox above to test that this sketch sends the serial data to the Arduino board and back to the Serial Monitor.");\n\tpinMode(LED_PIN, OUTPUT);\n\tpinMode(DCMOTOR_PIN, OUTPUT);\n\tdelay(5000);\n\tdigitalWrite(LED_PIN, HIGH);\n\tanalogWrite(DCMOTOR_PIN, 255);\n\t}\n\nvoid loop()\n\t{\n\twhile(Serial.available()>0)\n\t\t{\n\t\tchar receivedChar = Serial.read();\n\t\tSerial.print(receivedChar);\n\t\t}\n\t}'
3741
})
3842
try {
3943
await page.goto("http://localhost:3000")
@@ -42,7 +46,7 @@ describe("Interpreter End-To-End", () => {
4246
}
4347
})
4448

45-
test("Running a Sketch and reading the Serial data", async () => {
49+
test("Running a Sketch and checking the Digital Pin 0", async () => {
4650
await page.waitForSelector(runIcon)
4751

4852
sleep(5000)
@@ -51,6 +55,23 @@ describe("Interpreter End-To-End", () => {
5155

5256
await page.waitForSelector(stopIcon)
5357

58+
sleep(7000)
59+
60+
const digitalPinStatus = await page.$eval(
61+
pinDigital0,
62+
(el) => el.style.backgroundColor
63+
)
64+
65+
expect(digitalPinStatus).toBe("green")
66+
})
67+
68+
test("Checking the Analog Pin 0", async () => {
69+
const analogPinStatus = await page.$eval(pinAnalog0, (el) => el.innerText)
70+
71+
expect(analogPinStatus).toBe("255")
72+
})
73+
74+
test("Reading the Serial data", async () => {
5475
sleep(5000)
5576

5677
const serialData = await page.$eval(serialOutputData, (el) => el.innerText)

__tests__/__snapshots__/Interpreter.e2e.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Interpreter End-To-End Running a Sketch and reading the Serial data 1`] = `
3+
exports[`Interpreter End-To-End Reading the Serial data 1`] = `
44
"Char 1 example.
55
String 1 example.
66
String 2 example.

0 commit comments

Comments
 (0)