Skip to content

Commit

Permalink
game add edit test case added
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan-py committed Oct 25, 2024
1 parent 521e1a7 commit 45fefa6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 41 deletions.
3 changes: 3 additions & 0 deletions client/e2e/support/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ export const API_ROUTES = {
GAME_DETAILS: serverURL("/api/review/get-review"),
ADD_GAME_REVIEW: serverURL("/api/review/update-review"),
GET_MAP_DATA: serverURL("/api/review/map-data"),
CREATE_NEW_GAME: serverURL("/api/review/new-review"),
UPDATE_GAME: serverURL("/api/review/update-review"),
DELETE_GAME: serverURL("/api/review/delete-review"),
};
104 changes: 63 additions & 41 deletions client/e2e/tests/addEditGame.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { API_ROUTES } from "../support/constants";
import { gameListResponse, moderatorExistsResponse } from "../fixtures";

test.describe("Games: Add, Edit from Admin panel", () => {
const currentGame = gameListResponse.data[0];

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) => {
Expand Down Expand Up @@ -64,44 +65,65 @@ test.describe("Games: Add, Edit from Admin panel", () => {
await page.click("#cancel-button-add-game");
});

// test("Check add new games", async ({ page }) => {
// await page.click("#add-game-button");

// await page.fill('input[placeholder="Game Name"]', "Lost Ark 2");
// await page.fill(
// 'input[placeholder="Game Image (URL Only)"]',
// "https://www.freetogame.com/g/517/thumbnail.jpg"
// );
// await page.fill(
// 'textarea[placeholder="Game description..."]',
// "Free-to-play multiplayer massive adventure filled with lands waiting to be explored"
// );

// await page.click("#save-button-add-game");
// await expect(page.locator("text=Game created successfully")).toBeVisible();
// });

// test("Check edit games", async ({ page }) => {
// const editButton = page.locator('[data-button="edit-game"]').first();
// await editButton.click();

// await page.fill('input[placeholder="Game Name"]', "Lost Ark 2 Edited");
// await page.fill(
// 'input[placeholder="Game Image (URL Only)"]',
// "https://www.freetogame.com/g/517/thumbnail.jpg"
// );
// await page.fill(
// 'textarea[placeholder="Game description..."]',
// "Edited Free-to-play multiplayer massive adventure filled with lands waiting to be explored"
// );

// await page.click("#save-button-add-game");
// await expect(page.locator("text=Game update successfully")).toBeVisible();
// });

// test("Check delete game", async ({ page }) => {
// const deleteButton = page.locator('[data-button="delete-game"]').first();
// await deleteButton.click();
// await expect(page.locator("text=Game deleted successfully")).toBeVisible();
// });
test("Check add new games", async ({ page }) => {
await page.click("#add-game-button");

await page.fill('input[placeholder="Game Name"]', "Lost Ark 2");
await page.fill(
'input[placeholder="Game Image (URL Only)"]',
"https://www.freetogame.com/g/517/thumbnail.jpg"
);
await page.fill(
'textarea[placeholder="Game description..."]',
"Free-to-play multiplayer massive adventure filled with lands waiting to be explored"
);

await page.route(API_ROUTES.CREATE_NEW_GAME, async (route) => {
await route.fulfill({
json: { data: {}, message: "Data created successfully" },
});
});
await page.click("#save-button-add-game");

await expect(page.locator("text=Game created successfully")).toBeVisible();
});

test("Check edit games", async ({ page }) => {
const editButton = page.locator('[data-button="edit-game"]').first();
await editButton.click();

await page.fill('input[placeholder="Game Name"]', "Lost Ark 2 Edited");
await page.fill(
'input[placeholder="Game Image (URL Only)"]',
"https://www.freetogame.com/g/517/thumbnail.jpg"
);
await page.fill(
'textarea[placeholder="Game description..."]',
"Edited Free-to-play multiplayer massive adventure filled with lands waiting to be explored"
);

const updateApiURL = API_ROUTES.UPDATE_GAME + "/" + currentGame._id;
await page.route(updateApiURL, async (route) => {
await route.fulfill({
json: { data: {}, message: "Update successfully" },
});
});
await page.click("#save-button-add-game");

await expect(page.locator("text=Game update successfully")).toBeVisible();
});

test("Check delete game", async ({ page }) => {
const deleteButton = page.locator('[data-button="delete-game"]').first();

const deleteApiURL = API_ROUTES.DELETE_GAME + "/" + currentGame._id;
await page.route(deleteApiURL, async (route) => {
await route.fulfill({
json: { data: {}, message: "Update successfully" },
});
});
await deleteButton.click();

await expect(page.locator("text=Game deleted successfully")).toBeVisible();
});
});

0 comments on commit 45fefa6

Please sign in to comment.