Skip to content

Commit

Permalink
changed test code for home and login without server with mock api and…
Browse files Browse the repository at this point in the history
… all
  • Loading branch information
hasan-py committed Oct 19, 2024
1 parent b14ed27 commit a495e48
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 84 deletions.
191 changes: 191 additions & 0 deletions client/e2e/fixtures/gameList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
export default {
data: [
{
_id: "671363aaf22203668e1adb7c",
gameName: "Diablo Immortal",
gameImage: "https://www.freetogame.com/g/521/thumbnail.jpg",
gameDescription:
"Built for mobile and also released on PC, Diablo Immortal fills in the gaps between Diablo II and III in an MMOARPG environment.",
reviews: [
{
text: "Addictive gameplay, but could use better optimization.",
rating: 4,
username: "diablofan",
email: "[email protected]",
latitude: "35.6895",
longitude: "139.6917",
_id: "671363aaf22203668e1adb7d",
},
],
reviewCount: 1,
avgRating: 4,
},
{
_id: "671363aaf22203668e1adb83",
gameName: "Enlisted",
gameImage: "https://www.freetogame.com/g/508/thumbnail.jpg",
gameDescription:
"Get ready to command your own World War II military squad in Gaijin and Darkflow Software’s MMO squad-based shooter Enlisted.",
reviews: [
{
text: "Realistic and immersive experience!",
rating: 5,
username: "historybuff",
email: "[email protected]",
latitude: "52.5200",
longitude: "13.4050",
_id: "671363aaf22203668e1adb84",
},
],
reviewCount: 1,
avgRating: 5,
},
{
_id: "671363aaf22203668e1adb85",
gameName: "Forge of Empires",
gameImage: "https://www.freetogame.com/g/345/thumbnail.jpg",
gameDescription:
"A free to play 2D browser-based online strategy game, become the leader and raise your city.",
reviews: [
{
text: "Addictive city-building gameplay!",
rating: 4,
username: "citybuilder",
email: "[email protected]",
latitude: "51.5074",
longitude: "-0.1278",
_id: "671363aaf22203668e1adb86",
},
],
reviewCount: 1,
avgRating: 4,
},
{
_id: "671363aaf22203668e1adb87",
gameName: "Genshin Impact",
gameImage: "https://www.freetogame.com/g/475/thumbnail.jpg",
gameDescription:
"If you’ve been looking for a game to scratch that open-world action RPG itch, one with perhaps a bit of Asian flair, then you’re going to want to check out miHoYo’s Genshin Impact.",
reviews: [
{
text: "Stunning visuals and engaging combat!",
rating: 5,
username: "adventurer",
email: "[email protected]",
latitude: "35.6895",
longitude: "139.6917",
_id: "671363aaf22203668e1adb88",
},
],
reviewCount: 1,
avgRating: 5,
},
{
_id: "671363aaf22203668e1adb89",
gameName: "Fall Guys",
gameImage: "https://www.freetogame.com/g/523/thumbnail.jpg",
gameDescription:
"Play the most competitive massively multiplayer party royale game featuring beans ever for free on a variety of platforms.",
reviews: [
{
text: "Hilarious chaos and addictive gameplay!",
rating: 5,
username: "beanlover",
email: "[email protected]",
latitude: "51.5074",
longitude: "-0.1278",
_id: "671363aaf22203668e1adb8a",
},
{
text: "Great fun with friends, but needs more content.",
rating: 4,
username: "partygamer",
email: "[email protected]",
latitude: "37.7749",
longitude: "-122.4194",
_id: "671363aaf22203668e1adb8b",
},
],
reviewCount: 2,
avgRating: 4.5,
},
{
_id: "671363aaf22203668e1adb7e",
gameName: "Lost Ark",
gameImage: "https://www.freetogame.com/g/517/thumbnail.jpg",
gameDescription:
"Smilegate’s free-to-play multiplayer ARPG is a massive adventure filled with lands waiting to be explored, people waiting to be met, and an ancient evil waiting to be destroyed.",
reviews: [
{
text: "Incredible world design and engaging combat!",
rating: 5,
username: "arkexplorer",
email: "[email protected]",
latitude: "37.5665",
longitude: "126.9780",
_id: "671363aaf22203668e1adb7f",
},
{
text: "Fun, but too much grinding.",
rating: 3,
username: "casualgamer",
email: "[email protected]",
latitude: "40.7128",
longitude: "-74.0060",
_id: "671363aaf22203668e1adb80",
},
],
reviewCount: 2,
avgRating: 4,
},
{
_id: "671363aaf22203668e1adb81",
gameName: "PUBG: BATTLEGROUNDS",
gameImage: "https://www.freetogame.com/g/516/thumbnail.jpg",
gameDescription:
"Get into the action in one of the longest running battle royale games PUBG Battlegrounds.",
reviews: [
{
text: "Intense matches and satisfying gunplay!",
rating: 4,
username: "pubgplayer",
email: "[email protected]",
latitude: "37.7749",
longitude: "-122.4194",
_id: "671363aaf22203668e1adb82",
},
],
reviewCount: 1,
avgRating: 4,
},
{
_id: "671363aaf22203668e1adb79",
gameName: "Overwatch 2",
gameImage: "https://www.freetogame.com/g/540/thumbnail.jpg",
gameDescription:
"A hero-focused first-person team shooter from Blizzard Entertainment.",
reviews: [
{
text: "Exciting gameplay and diverse characters!",
rating: 5,
username: "overwatchfan",
email: "[email protected]",
latitude: "40.7128",
longitude: "-74.0060",
_id: "671363aaf22203668e1adb7a",
},
{
text: "Could use more content, but still enjoyable.",
rating: 4,
username: "gamer123",
email: "[email protected]",
latitude: "51.5074",
longitude: "-0.1278",
_id: "671363aaf22203668e1adb7b",
},
],
reviewCount: 2,
avgRating: 4.5,
},
],
};
10 changes: 8 additions & 2 deletions client/e2e/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import createModeratorResponse from "../fixtures/createModerator";
import gameListResponse from "../fixtures/gameList";
import moderatorExistsResponse from "../fixtures/moderatorExists";
import moderatorNotExistsResponse from "../fixtures/moderatorNotExists";
import createModerator from "../fixtures/createModerator";

export { moderatorExistsResponse, moderatorNotExistsResponse, createModerator };
export {
createModeratorResponse,
gameListResponse,
moderatorExistsResponse,
moderatorNotExistsResponse,
};
1 change: 1 addition & 0 deletions client/e2e/support/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export const API_ROUTES = {
LOGIN: serverURL("/api/auth/login"),
CHECK_MODERATOR: serverURL("/api/auth/check-moderator"),
CREATE_MODERATOR: serverURL("/api/auth/create-moderator"),
GAME_LIST: serverURL("/api/review/list-review"),
};
30 changes: 24 additions & 6 deletions client/e2e/tests/home.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
import { test, expect } from "@playwright/test";
import { expect, test } from "@playwright/test";
import { gameListResponse } from "../fixtures";
import { API_ROUTES } from "../support/constants";

test("Home page: Rendered successfully and show hero text", async ({
page,
}) => {
await page.route(API_ROUTES.GAME_LIST, async (route) => {
await route.fulfill({ json: { data: [] } });
});

test("Home page rendered successfully", async ({ page }) => {
await page.goto("/");
await expect(
page.locator("text=Find your next captivating gaming moment")
).toBeVisible();
});

test("Game List: No games found", async ({ page }) => {
await page.route(API_ROUTES.GAME_LIST, async (route) => {
await route.fulfill({ json: { data: [] } });
});

await page.goto("/");
await expect(page.locator("text=No game listed")).toBeVisible();
await expect(page.locator("text=Only Moderator can list game")).toBeVisible();
});

test("Game List: should display game cards with images, titles, and review counts", async ({
page,
}) => {
await page.route(API_ROUTES.GAME_LIST, async (route) => {
await route.fulfill({ json: gameListResponse });
});

await page.goto("/");

// Check that the grid exists
await expect(page.locator(".grid")).toBeVisible();

const gameCards = page.locator(".grid .col-span-1");
const cardCount = await gameCards.count(); // Get the number of game cards

// Check if the count is greater than 1
expect(cardCount).toBeGreaterThan(1);

// Check the first game card
const firstGameCard = gameCards.first();
await expect(firstGameCard.locator("img")).toHaveAttribute(
"src",
Expand All @@ -32,7 +51,6 @@ test("Game List: should display game cards with images, titles, and review count
/Game Image/
);

// Check game card details
await expect(firstGameCard.locator("p.text-lg")).toBeVisible();
await expect(firstGameCard.locator("p.text-lg")).not.toBeEmpty();

Expand Down
Loading

0 comments on commit a495e48

Please sign in to comment.