Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e #103

Merged
merged 2 commits into from
Oct 24, 2024
Merged

e2e #103

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/numberGame/Pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class Pokemon {
}
}

module.exports = Pokemon
module.exports = Pokemon
1 change: 0 additions & 1 deletion frontend/src/components/GuessForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export function GuessForm(props) {
<div className="md-5">
<br/>
<div className="flex">

<input type="number" value={props.input} onChange={(e) => props.setInput(e.target.value)} id="website-admin" className="rounded-lg bg-gray-50 border border-gray-300 text-gray-900 focus:ring-blue-500 focus:border-blue-500 block flex-1 min-w-0 w-full text-sm p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Your guess"></input>
</div>

Expand Down
31 changes: 31 additions & 0 deletions tests/inGame.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { test, expect, chromium } = require("@playwright/test");
const Utils = require("./utils")

const utils = new Utils()

test.describe("In game page", () => {
let playerPage;
let context;
let browser;

test.beforeEach(async ({ page }) => {
await page.goto("/");

await page.getByPlaceholder("Username").fill("Joe");
await page.locator("button").click();

browser = await chromium.launch();
context = await browser.newContext();
playerPage = await context.newPage();
});

test.afterEach(async () => {
await context.close();
await browser.close();
});

test("mocks a pokemon and doesnt call api", async ({page}) => {

expect(screen.getByText("Hello Please Work!!!!!!"))
});
})
6 changes: 6 additions & 0 deletions tests/playerLobby.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ test.describe("Player Lobby Page", () => {
await expect(page.getByText("Simon")).toBeVisible();
await expect(page.getByText("Joe (Host)")).toBeVisible();
});
test("when a host starts a game, the player is directed to in-game", async ({page}) => {
await utils.newPlayerJoinGame(page, playerPage, "Simon");
await utils.hostStartsGame(page)
await expect(playerPage).toHaveURL("/in-game");

})
});
13 changes: 8 additions & 5 deletions tests/utils.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
const { expect} = require("@playwright/test");
const { expect } = require("@playwright/test");

class Utils {

async newPlayerJoinGame(page, newPage, name) {
// host shares link
const gameLink = await page.getByTestId("game-link").textContent();
// player goes to host's link
await newPage.goto(gameLink)
await expect(newPage).toHaveURL(gameLink)
await newPage.goto(gameLink);
await expect(newPage).toHaveURL(gameLink);
// player enters name and clicks join room
await newPage.getByPlaceholder("Username").fill(name);
await newPage.locator("button").click();
}

async hostStartsGame(page) {
await page.getByRole("button", { name: "Start Game" }).click();
}
}

module.exports = Utils
module.exports = Utils;