diff --git a/client/e2e/support/constants.ts b/client/e2e/support/constants.ts index a417caf..0f75f54 100644 --- a/client/e2e/support/constants.ts +++ b/client/e2e/support/constants.ts @@ -7,4 +7,5 @@ export const API_ROUTES = { CHECK_MODERATOR: serverURL("/api/auth/check-moderator"), CREATE_MODERATOR: serverURL("/api/auth/create-moderator"), GAME_LIST: serverURL("/api/review/list-review"), + GAME_DETAILS: serverURL("/api/review/get-review"), }; diff --git a/client/e2e/tests/gameListAndReview.spec.ts b/client/e2e/tests/gameListAndReview.spec.ts index df2b0e0..b9c0b27 100644 --- a/client/e2e/tests/gameListAndReview.spec.ts +++ b/client/e2e/tests/gameListAndReview.spec.ts @@ -63,88 +63,89 @@ test.describe("Game List", () => { }); }); -// 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"]', "john@example.com"); -// 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"]', "john@example.com"); -// 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="john@example.com"]'); -// 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(); -// } -// }); -// }); +test.describe("Game Review", () => { + const currentGame = gameListResponse.data[0]; + + test.beforeEach(async ({ page, context }) => { + 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"]', "john@example.com"); + 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("/"); + + const gameReviewApiUrl = `${ + API_ROUTES.GAME_DETAILS + "/" + currentGame._id + }`; + + await page.route(gameReviewApiUrl, async (route) => { + await route.fulfill({ json: { data: currentGame } }); + }); + // Mocking geolocation + await context.grantPermissions(["geolocation"]); + await page.locator(".grid .col-span-1 div").first().click(); + }); + + test("Game Review: should render game review page and details", async ({ + page, + }) => { + await expect(page).toHaveURL(/\/review\/[a-zA-Z0-9]+/); + + // Verify the game title + const gameTitle = page.locator("p.chakra-text.text-protest.text-3xl"); + await expect(gameTitle).toHaveText(currentGame.gameName); + + // Verify the description + const gameDescription = page.locator("p.chakra-text.text-black").first(); + await expect(gameDescription).toHaveText(currentGame.gameDescription); + + // Verify the review stars + const svgContainer = page.locator("div.text-black").first(); + const svgCount = await svgContainer.locator("svg").count(); + expect(svgCount).toBe(currentGame.avgRating); + + // Verify the total rating score + const totalRating = page.locator("div.text-black .chakra-text").first(); + await expect(totalRating).toHaveText(currentGame.avgRating.toFixed(2)); + + // Verify the total reviews + const totalReviews = page.locator("div.text-black .chakra-text").last(); + await expect(totalReviews).toHaveText( + `${currentGame?.reviewCount} Reviews` + ); + }); + + // test("Game Review: should submit a review", async ({ page, context }) => { + // await page.fill('input[placeholder="Email"]', "john@example.com"); + // 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(); + // }); +});