Skip to content

Commit

Permalink
Added tests related to saving/loading (#52)
Browse files Browse the repository at this point in the history
* test: added 4 tests for saving/loading: backpack, blockly/C++ workspace and starting a new project
  • Loading branch information
pajotg authored May 10, 2024
1 parent eb8789f commit 0ea57de
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions tests/browser_storage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { expect, test } from "@playwright/test";
import { goToHomePage, openExample as loadExample } from "./utils";

test.beforeEach(goToHomePage);

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

await loadExample(page, "blink");

// Put something in the backpack
await page
.getByText("repeat forever")
.dragTo(page.locator(".blocklyBackpack"));

// Check that its in the backpack
await expect(page.getByText("repeat forever")).toBeHidden();
await page.locator(".blocklyBackpack").click();
await expect(page.getByText("repeat forever")).toBeVisible();

// Start a new project, why not?
await page.getByRole("button", { name: "My projects" }).click();
await page.getByRole("cell", { name: "New" }).click();

await page.reload();

// Load a different robot type than before, cause why not
await page.getByRole("button", { name: "Leaphy Click Leaphy Click" }).click();

await expect(page.getByText("repeat forever")).toBeHidden();
await page.locator(".blocklyBackpack").click();
await expect(page.getByText("repeat forever")).toBeVisible();

await page.getByText("repeat forever").dragTo(page.getByText("Leaphy"), {
force: true,
targetPosition: {
x: 30,
y: 30,
},
});

// Check that the blocks have been loaded properly
await page.locator(".side").first().click(); // Open code
await expect(page.locator(".view-lines")).toContainText("delay(1000)");
});

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

await loadExample(page, "blink");

await page.reload();

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

await expect(page.getByText("repeat forever")).toBeVisible();
});

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

await expect(page.getByText("setup")).toBeHidden();
await expect(page.getByText("testing")).toBeVisible();

await page.reload();

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

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 loadExample(page, "blink");

// Start a new project, should reset to the default
await page.getByRole("button", { name: "My projects" }).click();
await page.getByRole("cell", { name: "New" }).click();

// Open the same editor
await page.getByText("Leaphy Original").click();
await page.getByText("Original Uno").click();

// Its a new project, it should not be here!
await expect(page.getByText("repeat forever")).toBeHidden();
});

0 comments on commit 0ea57de

Please sign in to comment.