-
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
2 changed files
with
87 additions
and
85 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
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 |
---|---|---|
|
@@ -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"]', "[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(); | ||
// } | ||
// }); | ||
// }); | ||
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"]', "[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("/"); | ||
|
||
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"]', "[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(); | ||
// }); | ||
}); |