Skip to content

Commit

Permalink
Fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
itexpert120 committed Aug 12, 2024
1 parent 2a49a76 commit df07478
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions playwright-tests/tests/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ test.describe("Homepage", () => {
page
.getByRole("navigation")
.getByRole("link", { name: "Submit your project" });

await expect(getSubmitProjectButton()).toBeVisible();
const popupPromise = page.waitForEvent("popup");

await getSubmitProjectButton().click();

const popup = await popupPromise;
const popupUrl = await popup.evaluate("location.href");

await expect(popupUrl).toContain(
"https://submit.nearcatalog.xyz/new-project/",
);
Expand All @@ -29,17 +25,12 @@ test.describe("Homepage", () => {
}) => {
const ecosystemProjects = page.locator(".no-scrollbar").first();
await expect(ecosystemProjects).toBeVisible();

const firstProject = ecosystemProjects.getByRole("link").first();
await expect(firstProject).toBeVisible();

const projectHeading = firstProject.locator("h3");
await expect(projectHeading).toBeVisible();

await firstProject.click();

await firstProject.click({ force: true });
const projectPageHeading = page.locator("h2").first();
await page.waitForLoadState("networkidle");
await expect(projectPageHeading).toBeVisible();
});

Expand All @@ -48,13 +39,14 @@ test.describe("Homepage", () => {
}) => {
const section = page.locator("#hot-projects div").first();
await expect(section).toBeVisible();
const project = page.locator(".relative > div > .relative > .no-scrollbar");
const projects = page.locator(
".relative > div > .relative > .no-scrollbar",
);
await expect(projects).toBeVisible();
const project = projects.locator(".project-card").first();
await expect(project).toBeVisible();
const projectHeading = project.locator("h3").first();
await expect(projectHeading).toBeVisible();
await project.click();
const projectPageHeading = page.locator("h2").first();
await page.waitForLoadState("networkidle");
await project.click({ force: true });
const projectPageHeading = page.locator("#top div").locator("h2").first();
await expect(projectPageHeading).toBeVisible();
});

Expand All @@ -67,6 +59,28 @@ test.describe("Homepage", () => {
const searchInput = page.getByPlaceholder("Search projects");
await expect(searchInput).toBeVisible();
await searchInput.fill("build dao");
// intercept network requests
await page.route("**/*", (route) => {
route.fulfill({
status: 200,
body: JSON.stringify({
"build-dao": {
slug: "build-dao",
profile: {
name: "Build DAO",
tagline:
"Decentralizing the developer community, pushing protocol standards, fostering innovation, and enabling collaboration.",
image: {
url: "https://nearcatalog.xyz/wp-content/uploads/nearcatalog/build-dao.jpg",
},
tags: {
"ecosystem-support": "Ecosystem Support",
},
},
},
}),
});
});

const buildDaoProject = page
.locator(".projects-list")
Expand All @@ -79,15 +93,21 @@ test.describe("Homepage", () => {
await expect(tags).toBeVisible();
const tag = tags.locator("a").first();
await expect(tag).toBeVisible();
await tag.click();
await tag.click({ force: true });
await page.waitForURL("/category/*");
await expect(page.locator("h2").first()).toBeVisible();
});

test("should show error on no results found", async ({ page }) => {
const searchInput = page.getByPlaceholder("Search projects");
await expect(searchInput).toBeVisible();
await expect(searchInput).toBeEnabled();
await searchInput.fill("gibberish");
await page.route("**/*", (route) => {
route.fulfill({
status: 200,
body: JSON.stringify(false),
});
});
await expect(page.locator(".projects-list")).toBeHidden();
await expect(page.locator(".projects-list-skeleton")).toBeHidden();
await expect(page.locator(".error-message")).toBeVisible();
Expand Down

0 comments on commit df07478

Please sign in to comment.