Skip to content

Commit

Permalink
Initial playwright test
Browse files Browse the repository at this point in the history
  • Loading branch information
itaigilo committed Sep 29, 2024
1 parent ce126bf commit 68390c1
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const PullsList = ({repo, after, prefix, onPaginate}) => {
else content = (results && !!results.length ?
<>
<Card>
<ListGroup variant="flush">
<ListGroup variant="flush" className="pulls-list">
{results.map(pull => (
<PullWidget key={pull.id} repo={repo} pull={pull}/>
))}
Expand Down
206 changes: 121 additions & 85 deletions webui/test/e2e/common/quickstart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,101 +2,137 @@ import { test, expect } from "@playwright/test";
import { RepositoriesPage } from "../poms/repositoriesPage";
import { RepositoryPage } from "../poms/repositoryPage";
import { ObjectViewerPage } from "../poms/objectViewerPage";
import { PullsPage } from "../poms/pullsPage";

const QUICKSTART_REPO_NAME = "quickstart";
const PARQUET_OBJECT_NAME = "lakes.parquet";
const NEW_BRANCH_NAME = "denmark-lakes";

const SELECT_QUERY =
"SELECT country, COUNT(*) FROM READ_PARQUET('lakefs://quickstart/main/lakes.parquet') GROUP BY country ORDER BY COUNT(*) DESC LIMIT 5;";
"SELECT country, COUNT(*) FROM READ_PARQUET('lakefs://quickstart/main/lakes.parquet') GROUP BY country ORDER BY COUNT(*) DESC LIMIT 5;";
const CREATE_TABLE_QUERY =
"CREATE OR REPLACE TABLE lakes AS SELECT * FROM READ_PARQUET('lakefs://quickstart/denmark-lakes/lakes.parquet');";
"CREATE OR REPLACE TABLE lakes AS SELECT * FROM READ_PARQUET('lakefs://quickstart/denmark-lakes/lakes.parquet');";
const DELETE_QUERY = "DELETE FROM lakes WHERE Country != 'Denmark';";
const COPY_QUERY =
"COPY lakes TO 'lakefs://quickstart/denmark-lakes/lakes.parquet';";
"COPY lakes TO 'lakefs://quickstart/denmark-lakes/lakes.parquet';";
const SELECT_NEW_BRANCH =
"DROP TABLE lakes; SELECT country, COUNT(*) FROM READ_PARQUET('lakefs://quickstart/denmark-lakes/lakes.parquet') GROUP BY country ORDER BY COUNT(*) DESC LIMIT 5;";
"DROP TABLE lakes; SELECT country, COUNT(*) FROM READ_PARQUET('lakefs://quickstart/denmark-lakes/lakes.parquet') GROUP BY country ORDER BY COUNT(*) DESC LIMIT 5;";

test.describe("Quickstart", () => {
test.describe.configure({ mode: "serial" });
test("create repo w/ sample data", async ({ page }) => {
const repositoriesPage = new RepositoriesPage(page);
await repositoriesPage.goto();
await repositoriesPage.createRepository(QUICKSTART_REPO_NAME, true);
});

test("view and query parquet object", async ({ page }) => {
const repositoriesPage = new RepositoriesPage(page);
await repositoriesPage.goto();
await repositoriesPage.goToRepository(QUICKSTART_REPO_NAME);

const repositoryPage = new RepositoryPage(page);
await repositoryPage.clickObject(PARQUET_OBJECT_NAME);
await expect(page.getByText("Loading...")).not.toBeVisible();

const objectViewerPage = new ObjectViewerPage(page);
await objectViewerPage.enterQuery(SELECT_QUERY);
await objectViewerPage.clickExecuteButton();
await expect(await objectViewerPage.getResultRowCount()).toEqual(5);
});

test("transforming data", async ({ page }) => {
const repositoriesPage = new RepositoriesPage(page);
await repositoriesPage.goto();
await repositoriesPage.goToRepository(QUICKSTART_REPO_NAME);

const repositoryPage = new RepositoryPage(page);
await repositoryPage.createBranch(NEW_BRANCH_NAME);

await repositoryPage.gotoObjectsTab();
await repositoryPage.clickObject(PARQUET_OBJECT_NAME);
await expect(page.getByText("Loading...")).not.toBeVisible();

const objectViewerPage = new ObjectViewerPage(page);
await objectViewerPage.enterQuery(CREATE_TABLE_QUERY);
await objectViewerPage.clickExecuteButton();

await objectViewerPage.enterQuery(DELETE_QUERY);
await objectViewerPage.clickExecuteButton();

await objectViewerPage.enterQuery(COPY_QUERY);
await objectViewerPage.clickExecuteButton();

await objectViewerPage.enterQuery(SELECT_NEW_BRANCH);
await objectViewerPage.clickExecuteButton();
await expect(await objectViewerPage.getResultRowCount()).toEqual(1);
});

test("commit and merge", async ({ page }) => {
const repositoriesPage = new RepositoriesPage(page);
await repositoriesPage.goto();
await repositoriesPage.goToRepository(QUICKSTART_REPO_NAME);

const repositoryPage = new RepositoryPage(page);
await repositoryPage.gotoUncommittedChangeTab();
await repositoryPage.switchBranch(NEW_BRANCH_NAME);
await expect(
await page.getByText("Showing changes for branch")
).toBeVisible();
await expect(await repositoryPage.getUncommittedCount()).toEqual(1);

await repositoryPage.commitChanges("denmark");
await expect(page.getByText("No changes")).toBeVisible();

await repositoryPage.gotoCompareTab();
await repositoryPage.switchBaseBranch("main");
await expect(await page.getByText("Showing changes between")).toBeVisible();
await expect(await repositoryPage.getUncommittedCount()).toEqual(1);
await repositoryPage.merge("merge commit");
await expect(page.getByText("No changes")).toBeVisible();

await repositoriesPage.goto();
await repositoriesPage.goToRepository(QUICKSTART_REPO_NAME);
await repositoryPage.clickObject(PARQUET_OBJECT_NAME);
await expect(page.getByText("Loading...")).not.toBeVisible();
const objectViewerPage = new ObjectViewerPage(page);
await objectViewerPage.enterQuery(SELECT_QUERY);
await objectViewerPage.clickExecuteButton();
await expect(await objectViewerPage.getResultRowCount()).toEqual(1);
});
test.describe.configure({mode: "serial"});
test("create repo w/ sample data", async ({page}) => {
const repositoriesPage = new RepositoriesPage(page);
await repositoriesPage.goto();
await repositoriesPage.createRepository(QUICKSTART_REPO_NAME, true);
});

test("view and query parquet object", async ({page}) => {
const repositoriesPage = new RepositoriesPage(page);
await repositoriesPage.goto();
await repositoriesPage.goToRepository(QUICKSTART_REPO_NAME);

const repositoryPage = new RepositoryPage(page);
await repositoryPage.clickObject(PARQUET_OBJECT_NAME);
await expect(page.getByText("Loading...")).not.toBeVisible();

const objectViewerPage = new ObjectViewerPage(page);
await objectViewerPage.enterQuery(SELECT_QUERY);
await objectViewerPage.clickExecuteButton();
await expect(await objectViewerPage.getResultRowCount()).toEqual(5);
});

test("transforming data", async ({page}) => {
const repositoriesPage = new RepositoriesPage(page);
await repositoriesPage.goto();
await repositoriesPage.goToRepository(QUICKSTART_REPO_NAME);

const repositoryPage = new RepositoryPage(page);
await repositoryPage.createBranch(NEW_BRANCH_NAME);

await repositoryPage.gotoObjectsTab();
await repositoryPage.clickObject(PARQUET_OBJECT_NAME);
await expect(page.getByText("Loading...")).not.toBeVisible();

const objectViewerPage = new ObjectViewerPage(page);
await objectViewerPage.enterQuery(CREATE_TABLE_QUERY);
await objectViewerPage.clickExecuteButton();

await objectViewerPage.enterQuery(DELETE_QUERY);
await objectViewerPage.clickExecuteButton();

await objectViewerPage.enterQuery(COPY_QUERY);
await objectViewerPage.clickExecuteButton();

await objectViewerPage.enterQuery(SELECT_NEW_BRANCH);
await objectViewerPage.clickExecuteButton();
await expect(await objectViewerPage.getResultRowCount()).toEqual(1);
});

test("commit and merge", async ({page}) => {
const repositoriesPage = new RepositoriesPage(page);
await repositoriesPage.goto();
await repositoriesPage.goToRepository(QUICKSTART_REPO_NAME);

const repositoryPage = new RepositoryPage(page);
await repositoryPage.gotoUncommittedChangeTab();
await repositoryPage.switchBranch(NEW_BRANCH_NAME);
await expect(
await page.getByText("Showing changes for branch")
).toBeVisible();
await expect(await repositoryPage.getUncommittedCount()).toEqual(1);

await repositoryPage.commitChanges("denmark");
await expect(page.getByText("No changes")).toBeVisible();

await repositoryPage.gotoCompareTab();
await repositoryPage.switchBaseBranch("main");
await expect(await page.getByText("Showing changes between")).toBeVisible();
await expect(await repositoryPage.getUncommittedCount()).toEqual(1);
await repositoryPage.merge("merge commit");
await expect(page.getByText("No changes")).toBeVisible();

await repositoriesPage.goto();
await repositoriesPage.goToRepository(QUICKSTART_REPO_NAME);
await repositoryPage.clickObject(PARQUET_OBJECT_NAME);
await expect(page.getByText("Loading...")).not.toBeVisible();
const objectViewerPage = new ObjectViewerPage(page);
await objectViewerPage.enterQuery(SELECT_QUERY);
await objectViewerPage.clickExecuteButton();
await expect(await objectViewerPage.getResultRowCount()).toEqual(1);
});

test("pull requests", async ({page}) => {
const repositoriesPage = new RepositoriesPage(page);
await repositoriesPage.goto();
await repositoriesPage.goToRepository(QUICKSTART_REPO_NAME);

const branchNameForPull = "branch-for-pull-1";
const commitMsg = "commit-for-pull-1";

const repositoryPage = new RepositoryPage(page);

await repositoryPage.gotoObjectsTab();
await repositoryPage.switchBranch(branchNameForPull);
await repositoryPage.deleteFirstFileInDirectory("images/");

await repositoryPage.gotoUncommittedChangeTab();
expect(await repositoryPage.getUncommittedCount()).toEqual(1);
await repositoryPage.commitChanges(commitMsg);
await expect(page.getByText("No changes")).toBeVisible();

await repositoryPage.gotoPullRequestsTab();
await expect(page.getByText("Create Pull Request")).toBeVisible();
const pullsPage = new PullsPage(page);
expect(await pullsPage.getPullsListCount()).toEqual(0);

await pullsPage.clickCreatePullButton();
await expect(page.getByRole("heading", {name: "Create Pull Request"})).toBeVisible();
await pullsPage.switchCompareBranch(branchNameForPull);
const titleForPull1 = "PR for branch 1";
await pullsPage.fillPullTitle(titleForPull1);
await pullsPage.clickCreatePullButton();
await expect(page.getByRole("heading", {name: titleForPull1})).toBeVisible();

await expect(page.locator("div.lakefs-uri").getByText(`main...${branchNameForPull}`)).toBeVisible();
});
});
38 changes: 38 additions & 0 deletions webui/test/e2e/poms/pullsPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Page } from "@playwright/test";

export class PullsPage {
private page: Page;

constructor(page: Page) {
this.page = page;
}

async getPullsListCount(): Promise<number> {
await this.page.locator("div.pulls-list").isVisible();
return this.page
.locator("div.pulls-list")
.locator("pull-row")
.count();
}

async getResultRowCount(): Promise<number> {
return this.page
.locator("table.table")
.locator("tbody")
.locator("tr")
.count();
}

async switchCompareBranch(name: string): Promise<void> {
await this.page.getByRole("button", { name: "to branch: " }).click();
await this.page.getByRole("button", { name }).click();
}

async clickCreatePullButton(): Promise<void> {
await this.page.getByRole("button", { name: "Create Pull Request" }).click();
}

async fillPullTitle(title: string): Promise<void> {
await this.page.getByPlaceholder("Add a title...").fill(title);
}
}
39 changes: 39 additions & 0 deletions webui/test/e2e/poms/repositoryPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class RepositoryPage {
.click();
}

// branch operations

async createBranch(name: string): Promise<void> {
await this.page
.getByRole("link", { name: "Branches", exact: false })
Expand All @@ -37,6 +39,35 @@ export class RepositoryPage {
await this.page.getByRole("button", { name }).click();

Check failure on line 39 in webui/test/e2e/poms/repositoryPage.ts

View workflow job for this annotation

GitHub Actions / Quickstart

[quickstart] › common/quickstart.spec.ts:104:9 › Quickstart › pull requests

1) [quickstart] › common/quickstart.spec.ts:104:9 › Quickstart › pull requests ─────────────────── Error: locator.click: Test timeout of 30000ms exceeded. Call log: - waiting for getByRole('button', { name: 'branch-for-pull-1' }) at poms/repositoryPage.ts:39 37 | async switchBranch(name: string): Promise<void> { 38 | await this.page.getByRole("button", { name: "branch: " }).click(); > 39 | await this.page.getByRole("button", { name }).click(); | ^ 40 | } 41 | 42 | // file manipulation operations at RepositoryPage.switchBranch (/home/runner/work/lakeFS/lakeFS/webui/test/e2e/poms/repositoryPage.ts:39:51) at /home/runner/work/lakeFS/lakeFS/webui/test/e2e/common/quickstart.spec.ts:115:9
}

// file manipulation operations

async deleteFirstFileInDirectory(dirName: string): Promise<void> {
await this.page.getByRole("link", {name: dirName}).click();
await this.page
.locator("table.table")
.locator("tbody")
.locator("tr")
.first()
.locator("div.dropdown")
.hover();
await this.page
.locator("table.table")
.locator("tbody")
.locator("tr")
.first()
.locator("div.dropdown")
.locator("button")
.click();
await this.page
.locator("div.dropdown")
.locator(".dropdown-item")
.last()
.click();
await this.page.getByRole("button", {name: "Yes"}).click();
}

// uncommitted changes operations

async getUncommittedCount(): Promise<number> {
await this.page.locator("div.card").isVisible();
return this.page
Expand All @@ -57,6 +88,8 @@ export class RepositoryPage {
.click();
}

// merge operations

async merge(commitMsg: string): Promise<void> {
await this.page.getByRole("button", { name: "Merge" }).click();
if (commitMsg?.length) {
Expand All @@ -75,6 +108,8 @@ export class RepositoryPage {
await this.page.getByRole("button", { name }).click();
}

// navigation

async gotoObjectsTab(): Promise<void> {
await this.page.getByRole("link", { name: "Objects" }).click();
}
Expand All @@ -86,4 +121,8 @@ export class RepositoryPage {
async gotoCompareTab(): Promise<void> {
await this.page.getByRole("link", { name: "Compare" }).click();
}

async gotoPullRequestsTab(): Promise<void> {
await this.page.getByRole("link", { name: "Pull Requests" }).click();
}
}

0 comments on commit 68390c1

Please sign in to comment.