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 #58

Merged
merged 27 commits into from
Jul 25, 2024
Merged

E2e #58

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
- WATCHPACK_POLLING=true

ports:
- 4000:4000
volumes:
Expand Down
4 changes: 4 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
89 changes: 89 additions & 0 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "e2e",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"author": "",
"license": "ISC",
"dependencies": {
"@playwright/test": "^1.41.2"
},
"devDependencies": {
"@types/node": "^20.14.2"
}
}
107 changes: 107 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import type { PlaywrightTestConfig } from "@playwright/test";
import { devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
const config: PlaywrightTestConfig = {
testDir: "./tests",
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000,
},
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
// forbidOnly: !!process.env.CI,
/* Retry on CI only */
// retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: 3 ,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [["html", { open: "never" }], ["list"]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://localhost:7000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: {
...devices["Desktop Chrome"],
},
},

{
name: "firefox",
use: {
...devices["Desktop Firefox"],
},
},

{
name: "webkit",
use: {
...devices["Desktop Safari"],
},
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: {
// ...devices['Pixel 5'],
// },
// },
// {
// name: 'Mobile Safari',
// use: {
// ...devices['iPhone 12'],
// },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: {
// channel: 'msedge',
// },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// },
],

/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// port: 3000,
// },
};

export default config;
54 changes: 54 additions & 0 deletions e2e/tests/register.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { test, expect } from "@playwright/test";

function generateUniqueEmail() {
const timestamp = Date.now();
return `adelina_${timestamp}@gmail.com`;
}

test.describe("User tests", () => {
test("User subscription", async ({ page }) => {
await page.goto("http://localhost:7000/", { waitUntil: "networkidle" });

await page.getByTestId("AccountCircleIcon").click();

await expect(page).toHaveURL("http://localhost:7000/login");

await page.getByRole("link", { name: "S'inscrire" }).click();

await expect(page).toHaveURL("http://localhost:7000/register");

// Ensure elements are visible before interacting
const surname = await page.waitForSelector('[data-testid="surname"]', {
state: "visible",
});
await surname.fill("Adelina");

const name = await page.waitForSelector('[data-testid="name"]', {
state: "visible",
});
await name.fill("Aubert");

const email = await page.waitForSelector('[data-testid="email"]', {
state: "visible",
});
await email.fill(generateUniqueEmail());

const password = await page.waitForSelector('[data-testid="password"]', {
state: "visible",
});
await password.fill("Adelina12345*");

const select = await page.waitForSelector('[data-testid="city-select"]', {
state: "visible",
});
await select.click();

await page.getByRole("option", { name: "Paris" }).click();
await page.getByTestId("submit").click();

await expect(page).toHaveURL("http://localhost:7000/login");
});

});


6 changes: 6 additions & 0 deletions frontend/src/pages/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const Register = () => {
</Typography>

<TextField
inputProps={{ "data-testid": "surname" }}
required
fullWidth
placeholder="Prénom *"
Expand All @@ -126,6 +127,7 @@ const Register = () => {
/>

<TextField
inputProps={{ "data-testid": "name" }}
required
fullWidth
placeholder="Nom *"
Expand All @@ -152,6 +154,7 @@ const Register = () => {
/>

<TextField
inputProps={{ "data-testid": "email" }}
required
fullWidth
placeholder="E-mail *"
Expand All @@ -173,6 +176,7 @@ const Register = () => {
/>

<TextField
inputProps={{ "data-testid": "password" }}
required
fullWidth
placeholder="Mot de passe *"
Expand Down Expand Up @@ -212,6 +216,7 @@ const Register = () => {
<FormControl fullWidth margin="normal" error={!!errors.city}>
<InputLabel id="city-label">Sélectionner une ville</InputLabel>
<Select
data-testid="city-select"
labelId="city-label"
{...registerForm("city", {
required: "Une ville doit être sélectionnée",
Expand All @@ -233,6 +238,7 @@ const Register = () => {
</FormControl>

<Button
data-testid="submit"
variant="contained"
color="primary"
type="submit"
Expand Down
50 changes: 0 additions & 50 deletions frontend/tests-e2e/create-city.spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions frontend/tests-e2e/poi-details.spec.ts

This file was deleted.

Loading
Loading