From 1a5ef88c55cdaecf2d30bf241ba9c2f33020b635 Mon Sep 17 00:00:00 2001 From: counterweight Date: Thu, 28 Aug 2025 22:57:20 +0200 Subject: [PATCH] basic tests --- package.json | 3 ++- playwright.config.js | 13 +++++++++++++ tests/basic.spec.js | 12 ++++++++++++ tests/invite.spec.js | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 playwright.config.js create mode 100644 tests/basic.spec.js create mode 100644 tests/invite.spec.js diff --git a/package.json b/package.json index 2c904f5..568a109 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "watch": "webpack --watch", "cli": "node src/cli.js", "lint": "eslint . --fix", - "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,html,ejs}\"" + "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,html,ejs}\"", + "test": "playwright test" }, "keywords": [], "author": "", diff --git a/playwright.config.js b/playwright.config.js new file mode 100644 index 0000000..c7f57c8 --- /dev/null +++ b/playwright.config.js @@ -0,0 +1,13 @@ +const { defineConfig } = require('@playwright/test'); + +module.exports = defineConfig({ + testDir: './tests', + use: { + baseURL: 'http://localhost:3000', + }, + webServer: { + command: 'npm start', + url: 'http://localhost:3000', + reuseExistingServer: !process.env.CI, + }, +}); diff --git a/tests/basic.spec.js b/tests/basic.spec.js new file mode 100644 index 0000000..3c51e92 --- /dev/null +++ b/tests/basic.spec.js @@ -0,0 +1,12 @@ +const { test, expect } = require('@playwright/test'); + +test('app starts and public page is reachable', async ({ page }) => { + // Navigate to the root page + await page.goto('/'); + + // Check that the page loads (should redirect to login) + await expect(page).toHaveURL('/login'); + + // Verify we can see some content on the login page + await expect(page.locator('body')).toBeVisible(); +}); diff --git a/tests/invite.spec.js b/tests/invite.spec.js new file mode 100644 index 0000000..d49cde1 --- /dev/null +++ b/tests/invite.spec.js @@ -0,0 +1,36 @@ +const { test, expect } = require('@playwright/test'); +const { execSync } = require('child_process'); + +test('can create invite with CLI and access invite page', async ({ page }) => { + // Create an invite using the CLI + const inviterNpub = 'npub1test1234567890abcdefghijklmnopqrstuvwxyz'; + + try { + const output = execSync(`npm run cli createAppInvite ${inviterNpub}`, { + encoding: 'utf8', + cwd: process.cwd() + }); + + // Extract the invite UUID from the CLI output + const match = output.match(/http:\/\/localhost\/invite\/([a-f0-9-]+)/); + if (!match) { + throw new Error('Could not extract invite UUID from CLI output'); + } + + const inviteUuid = match[1]; + console.log(`Created invite with UUID: ${inviteUuid}`); + + // Navigate to the invite page + await page.goto(`/invite/${inviteUuid}`); + + // Check that the invite page loads correctly + await expect(page).toHaveTitle('Invite Details'); + await expect(page.locator('h1')).toContainText('¡Has sido invitado a la seca!'); + await expect(page.locator('#laseca-logo')).toBeVisible(); + await expect(page.locator('#nostr-signup-button')).toBeVisible(); + + } catch (error) { + console.error('Error creating invite or accessing page:', error); + throw error; + } +});