-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
231 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { API_ROUTES } from "../support/constants"; | ||
import { gameListResponse, moderatorExistsResponse } from "../fixtures"; | ||
|
||
test.describe("Game List", () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.route(API_ROUTES.CHECK_MODERATOR, async (route) => { | ||
await route.fulfill({ json: moderatorExistsResponse }); | ||
}); | ||
|
||
await page.goto("/login"); | ||
|
||
await page.route(API_ROUTES.LOGIN, async (route) => { | ||
await route.fulfill({ | ||
json: { | ||
token: "mockToken", | ||
}, | ||
}); | ||
}); | ||
|
||
await page.fill('input[placeholder="Email"]', "[email protected]"); | ||
await page.fill('input[placeholder="Password"]', "password123"); | ||
|
||
await page.click("button"); | ||
|
||
await page.route(API_ROUTES.GAME_LIST, async (route) => { | ||
await route.fulfill({ json: gameListResponse }); | ||
}); | ||
|
||
await page.goto("/"); | ||
}); | ||
|
||
test("Should display game cards with images, titles, and review counts", async ({ | ||
page, | ||
}) => { | ||
await expect(page.locator(".grid")).toBeVisible(); | ||
|
||
const gameCards = page.locator(".grid .col-span-1"); | ||
|
||
const firstGameCard = gameCards.first(); | ||
await expect(firstGameCard.locator("img")).toHaveAttribute( | ||
"src", | ||
/thumbnail\.jpg/ | ||
); | ||
await expect(firstGameCard.locator("img")).toHaveAttribute( | ||
"alt", | ||
/Game Image/ | ||
); | ||
|
||
await expect(firstGameCard.locator("p.text-lg")).toBeVisible(); | ||
await expect(firstGameCard.locator("p.text-lg")).not.toBeEmpty(); | ||
|
||
await expect(firstGameCard.locator("p.text-sm")).toBeVisible(); | ||
await expect(firstGameCard.locator("p.text-sm")).not.toBeEmpty(); | ||
|
||
await expect(firstGameCard.locator("p.text-xs")).toContainText("Reviews"); | ||
}); | ||
|
||
test("Should check hover effect on game cards", async ({ page }) => { | ||
const firstGameCard = page.locator(".grid .col-span-1 div").first(); | ||
await firstGameCard.hover(); | ||
await expect(firstGameCard).toHaveClass(/hover:-translate-y-1/); | ||
}); | ||
}); | ||
|
||
// test.describe("Game Review", () => { | ||
// test.beforeEach(async ({ page }) => { | ||
// await page.route(API_ROUTES.CHECK_MODERATOR, async (route) => { | ||
// await route.fulfill({ json: moderatorExistsResponse }); | ||
// }); | ||
|
||
// await page.goto("/login"); | ||
|
||
// await page.route(API_ROUTES.LOGIN, async (route) => { | ||
// await route.fulfill({ | ||
// json: { | ||
// token: "mockToken", | ||
// }, | ||
// }); | ||
// }); | ||
|
||
// await page.fill('input[placeholder="Email"]', "[email protected]"); | ||
// await page.fill('input[placeholder="Password"]', "password123"); | ||
|
||
// await page.click("button"); | ||
|
||
// await page.route(API_ROUTES.GAME_LIST, async (route) => { | ||
// await route.fulfill({ json: gameListResponse }); | ||
// }); | ||
|
||
// await page.goto("/"); | ||
// }); | ||
|
||
// test("Game Review: should render game review page", async ({ page }) => { | ||
// await page.goto("/"); | ||
// const firstGameCard = page.locator(".grid .col-span-1 div").first(); | ||
// await firstGameCard.click(); | ||
|
||
// await expect(page).toHaveURL(/\/review\/[a-zA-Z0-9]+/); | ||
// }); | ||
|
||
// test("Game Review: should submit a review", async ({ page, context }) => { | ||
// // Mocking geolocation | ||
// await context.grantPermissions(["geolocation"]); | ||
// await page.goto("/"); | ||
|
||
// await page.route("**/games", (route) => | ||
// route.fulfill({ | ||
// status: 200, | ||
// body: JSON.stringify([{ id: "1", name: "Mock Game", reviews: [] }]), | ||
// }) | ||
// ); | ||
|
||
// await page.goto("/"); | ||
// const firstGameCard = page.locator(".grid .col-span-1 div").first(); | ||
// await firstGameCard.click(); | ||
|
||
// await page.fill('input[placeholder="Email"]', "[email protected]"); | ||
// await page.fill('input[placeholder="Name"]', "John Doe"); | ||
// await page.fill( | ||
// 'textarea[placeholder="Here is a sample placeholder"]', | ||
// "Nice game. Loved it." | ||
// ); | ||
|
||
// await page.locator('fieldset.rating label[for="star4"]').click(); | ||
// await page.click("#submit-review-button"); | ||
|
||
// await expect(page.locator("text=Thank you for your review!")).toBeVisible(); | ||
// await expect(page.locator("text=John Doe")).toBeVisible(); | ||
// await expect(page.locator("text=Nice game. Loved it.")).toBeVisible(); | ||
// }); | ||
|
||
// test("Game Review: should delete review from admin panel", async ({ | ||
// page, | ||
// }) => { | ||
// await page.goto("/games"); | ||
|
||
// const reviewLocator = page.locator('[review-email="[email protected]"]'); | ||
// const reviewCount = await reviewLocator.count(); | ||
|
||
// for (let i = 0; i < reviewCount; i++) { | ||
// const review = reviewLocator.nth(i); | ||
// await review.click(); | ||
// await page.waitForTimeout(500); | ||
// await expect( | ||
// page.locator("text=Review deleted successfully") | ||
// ).toBeVisible(); | ||
// } | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { API_ROUTES } from "../support/constants"; | ||
import { moderatorExistsResponse } from "../fixtures"; | ||
|
||
test.describe("Moderator Admin Panel", () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.route(API_ROUTES.CHECK_MODERATOR, async (route) => { | ||
await route.fulfill({ json: moderatorExistsResponse }); | ||
}); | ||
|
||
await page.goto("/login"); | ||
|
||
await page.fill('input[placeholder="Email"]', "[email protected]"); | ||
await page.fill('input[placeholder="Password"]', "password123"); | ||
|
||
await page.route(API_ROUTES.LOGIN, async (route) => { | ||
await route.fulfill({ | ||
json: { | ||
token: "mockToken", | ||
}, | ||
}); | ||
}); | ||
|
||
await page.click("button"); | ||
}); | ||
|
||
test("Check admin login successfully", async ({ page }) => { | ||
await expect(page.locator("text=Login successfully")).toBeVisible(); | ||
}); | ||
|
||
test("Check all the menu accessible", async ({ page }) => { | ||
// Check admin URL | ||
await expect(page).toHaveURL("/admin"); | ||
|
||
// Navigate to different menus | ||
await page.click("#home-card"); | ||
await expect(page).toHaveURL("/"); | ||
|
||
await page.goBack(); | ||
await expect(page).toHaveURL("/admin"); | ||
|
||
await page.click("#game-list-card"); | ||
await expect(page).toHaveURL("/games"); | ||
|
||
await page.goBack(); | ||
await expect(page).toHaveURL("/admin"); | ||
|
||
await page.click("#review-in-map"); | ||
await expect(page).toHaveURL("/map"); | ||
|
||
await page.goBack(); | ||
await expect(page).toHaveURL("/admin"); | ||
}); | ||
|
||
test("Check logout functionality", async ({ page }) => { | ||
// Ensure URL is admin | ||
await expect(page).toHaveURL("/admin"); | ||
|
||
// Perform logout | ||
await page.click("#logout-button"); | ||
await expect(page.locator("text=Logout successful")).toBeVisible(); | ||
await expect(page).toHaveURL("/login"); | ||
}); | ||
}); | ||
|
||
test("Check all the protected menu not accessible when logged out", async ({ | ||
page, | ||
}) => { | ||
// Try to access admin page directly | ||
await page.goto("/admin", { waitUntil: "domcontentloaded" }); | ||
await expect(page).toHaveURL("/login"); | ||
|
||
// Try to access map page directly | ||
await page.goto("/map", { waitUntil: "domcontentloaded" }); | ||
await expect(page).toHaveURL("/login"); | ||
|
||
// Try to access games page directly | ||
await page.goto("/games", { waitUntil: "domcontentloaded" }); | ||
await expect(page).toHaveURL("/login"); | ||
}); |