Skip to content

Commit

Permalink
Merge pull request #103 from shammy642/more-e2e
Browse files Browse the repository at this point in the history
e2e
  • Loading branch information
shammy642 authored Oct 24, 2024
2 parents db13d2a + 9c09422 commit b93159b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
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;

0 comments on commit b93159b

Please sign in to comment.