From 45fefa68e191abdfba0b0dccdbb4961474c609e1 Mon Sep 17 00:00:00 2001 From: hasan-py Date: Fri, 25 Oct 2024 18:47:29 +0600 Subject: [PATCH] game add edit test case added --- client/e2e/support/constants.ts | 3 + client/e2e/tests/addEditGame.spec.ts | 104 ++++++++++++++++----------- 2 files changed, 66 insertions(+), 41 deletions(-) diff --git a/client/e2e/support/constants.ts b/client/e2e/support/constants.ts index 256a0a4..84b86a0 100644 --- a/client/e2e/support/constants.ts +++ b/client/e2e/support/constants.ts @@ -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"), }; diff --git a/client/e2e/tests/addEditGame.spec.ts b/client/e2e/tests/addEditGame.spec.ts index a75bdfd..e952a0e 100644 --- a/client/e2e/tests/addEditGame.spec.ts +++ b/client/e2e/tests/addEditGame.spec.ts @@ -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) => { @@ -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(); + }); });