Skip to content

Commit

Permalink
game review details test code added
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan-py committed Oct 22, 2024
1 parent 63db182 commit a687ba1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 85 deletions.
1 change: 1 addition & 0 deletions client/e2e/support/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
};
171 changes: 86 additions & 85 deletions client/e2e/tests/gameListAndReview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// });
});

0 comments on commit a687ba1

Please sign in to comment.