Skip to content

Commit

Permalink
map and add,edit game test code added
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan-py committed Oct 24, 2024
1 parent f8a3b17 commit 521e1a7
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/e2e/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import createModeratorResponse from "../fixtures/createModerator";
import gameListResponse from "../fixtures/gameList";
import moderatorExistsResponse from "../fixtures/moderatorExists";
import moderatorNotExistsResponse from "../fixtures/moderatorNotExists";
import mapDataResponse from "../fixtures/mapData";

export {
createModeratorResponse,
gameListResponse,
moderatorExistsResponse,
moderatorNotExistsResponse,
mapDataResponse,
};
125 changes: 125 additions & 0 deletions client/e2e/fixtures/mapData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
export default {
data: [
{
_id: "671797bdaa12e197d1cc4de4",
gameName: "Overwatch 2",
reviews: {
rating: 5,
username: "overwatchfan",
email: "[email protected]",
latitude: "40.7128",
longitude: "-74.0060",
},
},
{
_id: "671797bdaa12e197d1cc4de4",
gameName: "Overwatch 2",
reviews: {
rating: 4,
username: "gamer123",
email: "[email protected]",
latitude: "51.5074",
longitude: "-0.1278",
},
},
{
_id: "671797bdaa12e197d1cc4dec",
gameName: "PUBG: BATTLEGROUNDS",
reviews: {
rating: 4,
username: "pubgplayer",
email: "[email protected]",
latitude: "37.7749",
longitude: "-122.4194",
},
},
{
_id: "671797bdaa12e197d1cc4dee",
gameName: "Enlisted",
reviews: {
rating: 5,
username: "historybuff",
email: "[email protected]",
latitude: "52.5200",
longitude: "13.4050",
},
},
{
_id: "671797bdaa12e197d1cc4df0",
gameName: "Forge of Empires",
reviews: {
rating: 4,
username: "citybuilder",
email: "[email protected]",
latitude: "51.5074",
longitude: "-0.1278",
},
},
{
_id: "671797bdaa12e197d1cc4df2",
gameName: "Genshin Impact",
reviews: {
rating: 5,
username: "adventurer",
email: "[email protected]",
latitude: "35.6895",
longitude: "139.6917",
},
},
{
_id: "671797bdaa12e197d1cc4de7",
gameName: "Diablo Immortal",
reviews: {
rating: 4,
username: "diablofan",
email: "[email protected]",
latitude: "35.6895",
longitude: "139.6917",
},
},
{
_id: "671797bdaa12e197d1cc4de9",
gameName: "Lost Ark",
reviews: {
rating: 5,
username: "arkexplorer",
email: "[email protected]",
latitude: "37.5665",
longitude: "126.9780",
},
},
{
_id: "671797bdaa12e197d1cc4de9",
gameName: "Lost Ark",
reviews: {
rating: 3,
username: "casualgamer",
email: "[email protected]",
latitude: "40.7128",
longitude: "-74.0060",
},
},
{
_id: "671797bdaa12e197d1cc4df4",
gameName: "Fall Guys",
reviews: {
rating: 5,
username: "beanlover",
email: "[email protected]",
latitude: "51.5074",
longitude: "-0.1278",
},
},
{
_id: "671797bdaa12e197d1cc4df4",
gameName: "Fall Guys",
reviews: {
rating: 4,
username: "partygamer",
email: "[email protected]",
latitude: "37.7749",
longitude: "-122.4194",
},
},
],
};
1 change: 1 addition & 0 deletions client/e2e/support/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const API_ROUTES = {
GAME_LIST: serverURL("/api/review/list-review"),
GAME_DETAILS: serverURL("/api/review/get-review"),
ADD_GAME_REVIEW: serverURL("/api/review/update-review"),
GET_MAP_DATA: serverURL("/api/review/map-data"),
};
107 changes: 107 additions & 0 deletions client/e2e/tests/addEditGame.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { test, expect } from "@playwright/test";
import { API_ROUTES } from "../support/constants";
import { gameListResponse, moderatorExistsResponse } from "../fixtures";

test.describe("Games: Add, Edit from Admin panel", () => {
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) => {
route.fulfill({
body: JSON.stringify({ 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("/games");
await page.waitForLoadState("networkidle");
});

test("Add Games validations check", async ({ page }) => {
await page.click("#add-game-button");
await page.click("#save-button-add-game");

await expect(page.locator("text=Game Name must be provided")).toBeVisible();
await expect(
page.locator("text=Game Image must be a valid URL")
).toBeVisible();
await expect(
page.locator("text=Description must be provided")
).toBeVisible();

await page.click("#cancel-button-add-game");
});

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

await page.fill('input[placeholder="Game Name"]', "");
await page.fill('input[placeholder="Game Image (URL Only)"]', "");
await page.fill('textarea[placeholder="Game description..."]', "");

await page.click("#save-button-add-game");

await expect(page.locator("text=Game Name must be provided")).toBeVisible();
await expect(
page.locator("text=Game Image must be a valid URL")
).toBeVisible();
await expect(
page.locator("text=Description must be provided")
).toBeVisible();

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();
// });
});
54 changes: 54 additions & 0 deletions client/e2e/tests/reviewsMap.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { test, expect } from "@playwright/test";
import { API_ROUTES } from "../support/constants";
import { mapDataResponse, moderatorExistsResponse } from "../fixtures";

test.describe("Leaflet Map Test", () => {
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) => {
route.fulfill({
body: JSON.stringify({ 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.GET_MAP_DATA, async (route) => {
await route.fulfill({ json: mapDataResponse });
});

await page.goto("/map");
await page.waitForLoadState("networkidle");
});

test("should render the leaflet map", async ({ page }) => {
const mapContainer = await page.locator("#map-container");
await expect(mapContainer).toBeVisible();
});

test("should render the map and display markers", async ({ page }) => {
const markers = await page.locator(".leaflet-marker-icon");

// Check if markers count is at least 1
const count = await markers.count();
expect(count).toBeGreaterThan(0); // Check if count is greater than 0

// Ensure all markers are visible
for (let i = 0; i < count; i++) {
await expect(markers.nth(i)).toBeVisible();
}
});

test("should open a popup when a marker is clicked", async ({ page }) => {
const firstMarker = await page.locator(".leaflet-marker-icon").first();
await firstMarker.click({ force: true });
await expect(page.locator(".leaflet-popup")).toBeVisible();
});
});

0 comments on commit 521e1a7

Please sign in to comment.