Skip to content

Commit 499799a

Browse files
authored
Merge pull request #200 from codeableorg/e2e
E2e
2 parents beca6d2 + 4f9bbf9 commit 499799a

File tree

16 files changed

+791
-19
lines changed

16 files changed

+791
-19
lines changed

.env

Lines changed: 0 additions & 12 deletions
This file was deleted.

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ dist-ssr
2626
# React Router
2727
.react-router/
2828

29-
.build/
29+
.build/
30+
.env
31+
32+
# Playwright
33+
/test-results/
34+
/playwright-report/
35+
/blob-report/
36+
/playwright/.cache/

package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
},
4949
"devDependencies": {
5050
"@eslint/js": "^9.15.0",
51+
"@playwright/test": "^1.53.1",
5152
"@react-router/dev": "^7.5.1",
5253
"@testing-library/dom": "^10.4.0",
5354
"@testing-library/jest-dom": "^6.6.3",

playwright.config.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// import dotenv from 'dotenv';
8+
// import path from 'path';
9+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
10+
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: './src/e2e',
16+
/* Run tests in files in parallel */
17+
fullyParallel: true,
18+
/* Fail the build on CI if you accidentally left test.only in the source code. */
19+
forbidOnly: !!process.env.CI,
20+
/* Retry on CI only */
21+
retries: process.env.CI ? 2 : 0,
22+
/* Opt out of parallel tests on CI. */
23+
workers: process.env.CI ? 1 : undefined,
24+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
25+
reporter: 'html',
26+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
27+
use: {
28+
/* Base URL to use in actions like `await page.goto('/')`. */
29+
// baseURL: 'http://localhost:3000',
30+
31+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32+
trace: 'on-first-retry',
33+
},
34+
35+
/* Configure projects for major browsers */
36+
projects: [
37+
{
38+
name: 'chromium',
39+
use: { ...devices['Desktop Chrome'] },
40+
},
41+
42+
{
43+
name: 'firefox',
44+
use: { ...devices['Desktop Firefox'] },
45+
},
46+
47+
{
48+
name: 'webkit',
49+
use: { ...devices['Desktop Safari'] },
50+
},
51+
52+
/* Test against mobile viewports. */
53+
// {
54+
// name: 'Mobile Chrome',
55+
// use: { ...devices['Pixel 5'] },
56+
// },
57+
// {
58+
// name: 'Mobile Safari',
59+
// use: { ...devices['iPhone 12'] },
60+
// },
61+
62+
/* Test against branded browsers. */
63+
// {
64+
// name: 'Microsoft Edge',
65+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
66+
// },
67+
// {
68+
// name: 'Google Chrome',
69+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
70+
// },
71+
],
72+
73+
/* Run your local dev server before starting the tests */
74+
// webServer: {
75+
// command: 'npm run start',
76+
// url: 'http://localhost:3000',
77+
// reuseExistingServer: !process.env.CI,
78+
// },
79+
});

src/db/migrations/initial.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS products (
3636
CREATE TABLE IF NOT EXISTS carts (
3737
id SERIAL PRIMARY KEY,
3838
session_cart_id UUID UNIQUE DEFAULT gen_random_uuid(),
39-
user_id INTEGER REFERENCES users(id),
39+
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
4040
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
4141
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
4242
);
@@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS cart_items (
5353

5454
CREATE TABLE IF NOT EXISTS orders (
5555
id SERIAL PRIMARY KEY,
56-
user_id INTEGER REFERENCES users(id),
56+
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
5757
total_amount NUMERIC(10,2) NOT NULL,
5858

5959
-- Customer and shipping details

src/e2e/demo.signin.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
import { hashPassword } from "@/lib/security";
4+
import type { CreateUserDTO } from "@/models/user.model";
5+
import {
6+
createUser,
7+
deleteUser,
8+
getUserByEmail,
9+
} from "@/repositories/user.repository";
10+
11+
test.describe("Visitante inicio sesion", () => {
12+
let testUserId: number;
13+
14+
test.beforeAll(async () => {
15+
const testUser: CreateUserDTO = {
16+
17+
name: null,
18+
password: await hashPassword("letmein"),
19+
isGuest: false,
20+
};
21+
22+
const existingUser = await getUserByEmail(testUser.email);
23+
24+
if (existingUser) {
25+
await deleteUser(existingUser.id);
26+
}
27+
28+
const user = await createUser(testUser);
29+
testUserId = user.id;
30+
});
31+
32+
test.afterAll(async () => {
33+
await deleteUser(testUserId);
34+
});
35+
36+
test("test", async ({ page }) => {
37+
await page.goto("http://localhost:5173/");
38+
await page.getByTestId("login").click();
39+
await page.getByRole("textbox", { name: "Correo electrónico" }).click();
40+
await page
41+
.getByRole("textbox", { name: "Correo electrónico" })
42+
43+
await page
44+
.getByRole("textbox", { name: "Correo electrónico" })
45+
.press("Tab");
46+
await page.getByRole("textbox", { name: "Contraseña" }).fill("letmein");
47+
await page.getByRole("button", { name: "Iniciar sesión" }).click();
48+
49+
await expect(page.getByText("Bienvenido [email protected]")).toBeVisible();
50+
});
51+
});

src/e2e/demo.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test.describe("Visitor", () => {
4+
test("can add a product to the cart", async ({ page }) => {
5+
await page.goto("http://localhost:5173/");
6+
7+
await expect(page).toHaveTitle(/inicio/i);
8+
9+
await page.getByRole("menuitem", { name: "Polos", exact: true }).click();
10+
await expect(page.getByRole("heading", { name: "Polos" })).toBeVisible();
11+
12+
await page.getByTestId("product-item").first().click();
13+
const button = page.getByRole("button", {
14+
name: "Agregar al Carrito",
15+
});
16+
await expect(button).toBeVisible();
17+
await button.click();
18+
const cartCount = page.getByTestId("cart-count");
19+
await expect(cartCount).toHaveText("1");
20+
});
21+
});

src/e2e/example.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('https://playwright.dev/');
5+
6+
// Expect a title "to contain" a substring.
7+
await expect(page).toHaveTitle(/Playwright/);
8+
});
9+
10+
test('get started link', async ({ page }) => {
11+
await page.goto('https://playwright.dev/');
12+
13+
// Click the get started link.
14+
await page.getByRole('link', { name: 'Get started' }).click();
15+
16+
// Expects page to have a heading with the name of Installation.
17+
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
18+
});

0 commit comments

Comments
 (0)