Skip to content

Commit

Permalink
Add first e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
wkwiatek committed Sep 21, 2024
1 parent 6706e87 commit 07d7404
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/Instructions/InstructionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const InstructionItem = ({
<TableRow
ref={ref}
className={classNames("hover:bg-gray-300", { "opacity-50": isLast })}
test-id="instruction-item"
style={{ backgroundColor: isHighlighted ? bgColor : "initial" }}
>
{instructionMode === InstructionMode.BYTECODE && (
Expand Down
1 change: 1 addition & 0 deletions src/components/ProgramUpload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const ProgramUpload = ({
</Tabs>
<DialogFooter>
<Button
id="load-button"
type="button"
disabled={!file}
onClick={() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/PvmSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const PvmSelect = ({
}
}}
>
<SelectTrigger>
<SelectTrigger test-id="pvm-select">
<SelectValue placeholder="Select a PVM" />
</SelectTrigger>
<SelectContent>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Registers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const Registers = ({
</div>
<div className="flex flex-row items-center justify-between w-full">
<p className="flex-[2]">Status</p>
<p className="flex-[3]" style={{ color: getStatusColor(currentState.status) }}>
<p className="flex-[3]" style={{ color: getStatusColor(currentState.status) }} test-id="program-status">
{currentState.status !== undefined ? Status[currentState.status] : null}
</p>
</div>
Expand Down
53 changes: 53 additions & 0 deletions tests/run-program.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { test, expect, Page } from "@playwright/test";

async function runProgramTest(page: Page, pvmType: string) {
// Navigate to your app
await page.goto("http://localhost:5173");

// Select the PVM type
await page.waitForSelector('button[test-id="pvm-select"]');

await page.click('button[test-id="pvm-select"]');

const pvmOption = page.locator('div[role="option"]', { hasText: new RegExp(pvmType, "i") });
await pvmOption.waitFor({ state: "visible" });
await pvmOption.click();

// Wait for the ProgramUpload component to be visible
await page.waitForSelector('button:has-text("Load")');

// Click the Load Program button
await page.click('button:has-text("Load")');

// Wait for the program to load
await page.waitForTimeout(1000);

await page.click('button:has-text("Examples")');
await page.click('button[id="option-fibonacci"]');
await page.click('button[id="load-button"]');

await page.waitForTimeout(1000);

const jumpIndInstruction = page.locator('span:has-text("JUMP_IND")');
await expect(jumpIndInstruction).toBeVisible();

// Test the "Run" button functionality
await page.click('button:has-text("Run")');

// Wait for execution to complete
await page.waitForTimeout(5000);

const programStatus = page.locator('[test-id="program-status"]');
await expect(programStatus).toHaveText("HALT");

// const jumpIndInstructionParent = page.locator('div[test-id="instruction-item"]:has(span:has-text("JUMP_IND"))');
// await expect(jumpIndInstructionParent).toHaveCSS('background-color', 'rgb(76, 175, 80)');
}

test("Run program with typeberry PVM", async ({ page }) => {
await runProgramTest(page, "@typeberry");
});

test("Run program with polkavm PVM", async ({ page }) => {
await runProgramTest(page, "polkavm");
});

0 comments on commit 07d7404

Please sign in to comment.