Skip to content
Merged

E2e #200

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
12 changes: 0 additions & 12 deletions .env

This file was deleted.

9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ dist-ssr
# React Router
.react-router/

.build/
.build/
.env

# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
64 changes: 64 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
},
"devDependencies": {
"@eslint/js": "^9.15.0",
"@playwright/test": "^1.53.1",
"@react-router/dev": "^7.5.1",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
Expand Down
79 changes: 79 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './src/e2e',
/* 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: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://localhost:3000',

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

/* 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: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://localhost:3000',
// reuseExistingServer: !process.env.CI,
// },
});
4 changes: 2 additions & 2 deletions src/db/migrations/initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS products (
CREATE TABLE IF NOT EXISTS carts (
id SERIAL PRIMARY KEY,
session_cart_id UUID UNIQUE DEFAULT gen_random_uuid(),
user_id INTEGER REFERENCES users(id),
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Expand All @@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS cart_items (

CREATE TABLE IF NOT EXISTS orders (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
total_amount NUMERIC(10,2) NOT NULL,

-- Customer and shipping details
Expand Down
51 changes: 51 additions & 0 deletions src/e2e/demo.signin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { test, expect } from "@playwright/test";

import { hashPassword } from "@/lib/security";
import type { CreateUserDTO } from "@/models/user.model";
import {
createUser,
deleteUser,
getUserByEmail,
} from "@/repositories/user.repository";

test.describe("Visitante inicio sesion", () => {
let testUserId: number;

test.beforeAll(async () => {
const testUser: CreateUserDTO = {
email: "diego@codeable.com",
name: null,
password: await hashPassword("letmein"),
isGuest: false,
};

const existingUser = await getUserByEmail(testUser.email);

if (existingUser) {
await deleteUser(existingUser.id);
}

const user = await createUser(testUser);
testUserId = user.id;
});

test.afterAll(async () => {
await deleteUser(testUserId);
});

test("test", async ({ page }) => {
await page.goto("http://localhost:5173/");
await page.getByTestId("login").click();
await page.getByRole("textbox", { name: "Correo electrónico" }).click();
await page
.getByRole("textbox", { name: "Correo electrónico" })
.fill("diego@codeable.com");
await page
.getByRole("textbox", { name: "Correo electrónico" })
.press("Tab");
await page.getByRole("textbox", { name: "Contraseña" }).fill("letmein");
await page.getByRole("button", { name: "Iniciar sesión" }).click();

await expect(page.getByText("Bienvenido diego@codeable.com")).toBeVisible();
});
});
21 changes: 21 additions & 0 deletions src/e2e/demo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test, expect } from "@playwright/test";

test.describe("Visitor", () => {
test("can add a product to the cart", async ({ page }) => {
await page.goto("http://localhost:5173/");

await expect(page).toHaveTitle(/inicio/i);

await page.getByRole("menuitem", { name: "Polos", exact: true }).click();
await expect(page.getByRole("heading", { name: "Polos" })).toBeVisible();

await page.getByTestId("product-item").first().click();
const button = page.getByRole("button", {
name: "Agregar al Carrito",
});
await expect(button).toBeVisible();
await button.click();
const cartCount = page.getByTestId("cart-count");
await expect(cartCount).toHaveText("1");
});
});
18 changes: 18 additions & 0 deletions src/e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
});

test('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');

// Click the get started link.
await page.getByRole('link', { name: 'Get started' }).click();

// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});
Loading