Skip to content

Commit

Permalink
fix: test robot select
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben committed Aug 19, 2024
1 parent 149ab2f commit b2294b0
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 57 deletions.
16 changes: 14 additions & 2 deletions src/lib/state/workspace.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,20 @@ export const microPythonIO = writable<MicroPythonIO | undefined>();
export const microPythonRun = writable<IOEventTarget | undefined>();

export function tempSave() {
const contentAddress = `${get(robot).saveAddress}_content`;
localStorage.setItem(`${get(robot).saveAddress}_robot`, get(robot).id);
let saveAddress = get(robot).saveAddress;
switch (get(mode)) {
case Mode.ADVANCED: {
saveAddress = "l_c++";
break;
}
case Mode.PYTHON: {
saveAddress = "l_micropython";
break;
}
}

const contentAddress = `${saveAddress}_content`;
localStorage.setItem(`${saveAddress}_robot`, get(robot).id);

switch (get(mode)) {
case Mode.BLOCKS: {
Expand Down
9 changes: 3 additions & 6 deletions tests/arduino.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { expect, test } from "@playwright/test";
import { goToHomePage, openExample, setupArduino } from "./utils";
import { goToHomePage, openExample, selectRobot, setupArduino } from "./utils";

test.describe.configure({ mode: "serial" });

test.beforeEach(setupArduino);
test.beforeEach(goToHomePage);

test("Arduino - Blockly upload", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await openExample(page, "Blink");

await page.getByRole("button", { name: "Upload to robot" }).click();
Expand All @@ -26,8 +24,7 @@ test("Arduino - Blockly upload", async ({ page }) => {
});

test("Arduino - C++ upload", async ({ page }) => {
await page.getByText("Leaphy C++").click();

await selectRobot(page, "Leaphy C++", "Arduino Uno");
await page.getByRole("button", { name: "Upload to robot" }).click();
await expect(
page.getByRole("button", { name: "Go back to editor" }),
Expand Down
6 changes: 2 additions & 4 deletions tests/blink_example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as consumers from "node:stream/consumers";
import { expect, test } from "@playwright/test";
import { goToHomePage, openExample } from "./utils";
import { goToHomePage, openExample, selectRobot } from "./utils";

test.beforeEach(goToHomePage);

test("Load Blink example and check code", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await openExample(page, "Blink");

await page.locator(".side").first().click(); // Open code
Expand Down
23 changes: 7 additions & 16 deletions tests/browser_storage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { expect, test } from "@playwright/test";
import { goToHomePage, openExample } from "./utils";
import { goToHomePage, openExample, selectRobot } from "./utils";

test.beforeEach(goToHomePage);

test("Saving - Backpack", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await openExample(page, "Blink");

// Put something in the backpack
Expand Down Expand Up @@ -46,21 +44,17 @@ test("Saving - Backpack", async ({ page }) => {
});

test("Saving - Blockly", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await openExample(page, "Blink");

await page.reload();

await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await expect(page.getByText("repeat forever")).toBeVisible();
});

test("Saving - C++", async ({ page }) => {
await page.getByRole("button", { name: "Leaphy C++ Leaphy C++" }).click();
await selectRobot(page, "Leaphy C++", "Arduino Uno");
await page.getByText("setup").click();
await page.getByLabel("Editor content;Press Alt+F1").fill("testing");

Expand All @@ -69,16 +63,13 @@ test("Saving - C++", async ({ page }) => {

await page.reload();

await page.getByRole("button", { name: "Leaphy C++ Leaphy C++" }).click();

await selectRobot(page, "Leaphy C++", "Arduino Uno");
await expect(page.getByText("setup")).toBeHidden();
await expect(page.getByText("testing")).toBeVisible();
});

test("Saving - New project", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await openExample(page, "Blink");

// Start a new project, should reset to the default
Expand Down
15 changes: 8 additions & 7 deletions tests/code_tests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { promises as fs } from "node:fs";
import { type Page, expect, test } from "@playwright/test";
import { goToHomePage, mockShowOpenFilePicker, openExample } from "./utils";
import {
goToHomePage,
mockShowOpenFilePicker,
openExample,
selectRobot,
} from "./utils";

test.beforeEach(goToHomePage);

Expand Down Expand Up @@ -40,15 +45,11 @@ test("Code blocks - Leaphy Click", async ({ page }) => {
});

test("Code blocks - Original Uno", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await testExtension(page, ".l_original_uno");
});

test("Code blocks - Flitz Uno", async ({ page }) => {
await page.getByText("Leaphy Flitz").click();
await page.getByText("Flitz Uno").click();

await selectRobot(page, "Leaphy Flitz", "Flitz Uno");
await testExtension(page, ".l_flitz_uno");
});
7 changes: 2 additions & 5 deletions tests/language.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, expect, test } from "@playwright/test";
import { goToHomePage, openExample } from "./utils";
import { goToHomePage, openExample, selectRobot } from "./utils";

test.beforeEach(goToHomePage);

Expand All @@ -10,10 +10,7 @@ test("Language", async ({ page }) => {
await page.getByRole("cell", { name: "Nederlands" }).click();
await page.getByRole("button", { name: "Mijn projecten" }).click();
await page.getByRole("cell", { name: "Nieuw" }).click();
await page.getByRole("button", { name: "Leaphy Original Leaphy" }).click();
await page
.getByRole("button", { name: "Original Nano ESP32 Original" })
.click();
await selectRobot(page, "Leaphy Original", "Original Nano ESP32", "Ga door");
await expect(page.getByText("Lees afstand")).toBeVisible();
await expect(page.getByText("Lees anapin")).toBeVisible();
await expect(page.getByText("Lees gas")).toBeVisible();
Expand Down
6 changes: 2 additions & 4 deletions tests/load_workspace.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { goToHomePage, mockShowOpenFilePicker } from "./utils";
import { goToHomePage, mockShowOpenFilePicker, selectRobot } from "./utils";

test.beforeEach(goToHomePage);

Expand All @@ -10,9 +10,7 @@ let test_files = [

for (let [testName, file] of test_files) {
test(`LoadAndSave - ${testName}`, async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await page.getByRole("button", { name: "My projects" }).click();

// Playwright doesn't seem to support `showOpenFilePicker()` so mock it
Expand Down
5 changes: 2 additions & 3 deletions tests/pins.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, expect, test } from "@playwright/test";
import { goToHomePage } from "./utils";
import { goToHomePage, selectRobot } from "./utils";

test.beforeEach(goToHomePage);

Expand Down Expand Up @@ -90,8 +90,7 @@ test("Pins - Uno", async ({ page }) => {
});

test("Pins - Nano", async ({ page }) => {
await page.getByText("Arduino Nano").click();
await page.getByText("Arduino Nano ESP32").click();
await selectRobot(page, "Arduino Nano", "Arduino Nano ESP32");

await test_pins(page, nano_pins);
});
Expand Down
14 changes: 4 additions & 10 deletions tests/undo_redo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, expect, test } from "@playwright/test";
import { goToHomePage, openExample } from "./utils";
import { goToHomePage, openExample, selectRobot } from "./utils";

test.beforeEach(goToHomePage);

Expand All @@ -11,9 +11,7 @@ async function redo(page: Page) {
}

test("Undo redo - Deletion", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await openExample(page, "Blink");

// Delete the repeat forever block
Expand Down Expand Up @@ -42,9 +40,7 @@ test("Undo redo - Deletion", async ({ page }) => {
});

test("Undo redo - Variable change", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await openExample(page, "Blink");

// Change a boolean
Expand Down Expand Up @@ -74,9 +70,7 @@ test("Undo redo - Variable change", async ({ page }) => {
});

test("Undo redo - Dragging", async ({ page }) => {
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

await selectRobot(page, "Leaphy Original", "Original Uno");
await openExample(page, "Blink");

await page.locator(".side").first().click(); // Open code
Expand Down
11 changes: 11 additions & 0 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ test.beforeEach(async ({ context }) => {
});
});

export async function selectRobot(
page: Page,
tile: string,
robot: string,
continueName = "Continue",
) {
await page.getByText(tile).click();
await page.getByText(robot).click();
await page.getByText(continueName).click();
}

export async function setupArduino({ page }: PlaywrightTestArgs) {
let board = await setupPlaywrightArduino(page);
page.once("close", (_) => {
Expand Down

0 comments on commit b2294b0

Please sign in to comment.