From 107d32586eb8c13db153aed1f4e1fa683d21a6a4 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Fri, 14 Mar 2025 00:41:32 +0100 Subject: [PATCH] register page --- .woodpecker/playwright.yaml | 3 +- main.go | 15 ++++++ pkg/web/web.go | 11 +++- playwright/playwright.config.js | 2 +- playwright/playwright.config.js.ci | 81 ++++++++++++++++++++++++++++++ playwright/tests/example.spec.js | 11 ++-- templates/register.html | 62 +++++++++++++++++++++++ 7 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 playwright/playwright.config.js.ci create mode 100644 templates/register.html diff --git a/.woodpecker/playwright.yaml b/.woodpecker/playwright.yaml index e67e4de..b741f11 100644 --- a/.woodpecker/playwright.yaml +++ b/.woodpecker/playwright.yaml @@ -15,7 +15,8 @@ steps: - name: playwright image: mcr.microsoft.com/playwright:v1.50.0 commands: - - cd playwright; + - cd playwright + - cp playwright.config.js.ci playwright.config.js - npm install - npx playwright install - npx playwright test diff --git a/main.go b/main.go index 1785f9e..962d9ea 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,32 @@ package main import ( + "embed" + "html/template" + "git.keks.cloud/kekskurse/miniauth/pkg/web" "github.com/gin-gonic/gin" ) +//go:embed templates/* +var templatesFS embed.FS + func main() { router := setupRouter() router.Run(":8080") } +func loadTemplates() *template.Template { + tmpl, err := template.ParseFS(templatesFS, "templates/*.html") + if err != nil { + panic(err) // Handle error entsprechend + } + return tmpl +} + func setupRouter() *gin.Engine { router := gin.Default() + router.SetHTMLTemplate(loadTemplates()) routesWeb := router.Group("/web") webServer := web.NewWeb() diff --git a/pkg/web/web.go b/pkg/web/web.go index 680c9f4..9958149 100644 --- a/pkg/web/web.go +++ b/pkg/web/web.go @@ -1,6 +1,10 @@ package web -import "github.com/gin-gonic/gin" +import ( + "net/http" + + "github.com/gin-gonic/gin" +) type Web struct{} @@ -10,5 +14,10 @@ func NewWeb() Web { } func (w Web) RegisterRoutes(routing *gin.RouterGroup) error { + routing.GET("/register", w.GetRegisterPage) return nil } + +func (w Web) GetRegisterPage(c *gin.Context) { + c.HTML(http.StatusOK, "register.html", nil) +} diff --git a/playwright/playwright.config.js b/playwright/playwright.config.js index 96a2a36..acda745 100644 --- a/playwright/playwright.config.js +++ b/playwright/playwright.config.js @@ -27,7 +27,7 @@ export default defineConfig({ /* 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://127.0.0.1:3000', + baseURL: 'http://127.0.0.1:8080', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', diff --git a/playwright/playwright.config.js.ci b/playwright/playwright.config.js.ci new file mode 100644 index 0000000..acda745 --- /dev/null +++ b/playwright/playwright.config.js.ci @@ -0,0 +1,81 @@ +// @ts-check +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: './tests', + /* 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://127.0.0.1:8080', + + /* 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://127.0.0.1:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); + diff --git a/playwright/tests/example.spec.js b/playwright/tests/example.spec.js index 0c14412..a2d6183 100644 --- a/playwright/tests/example.spec.js +++ b/playwright/tests/example.spec.js @@ -3,10 +3,15 @@ import { test, expect } from '@playwright/test'; test('check ping route', async ({ page }) => { - await page.goto('http://miniauth:8080/ping'); - - await page.screenshot({ path: 'screenshot.png' }); + await page.goto('/ping'); // Expects page to have a heading with the name of Installation. await expect(page.getByText('pong')).toBeVisible(); }); + +test('see register page', async ({page}) => { + await page.goto('/web/register'); + + await expect(page.getByRole('heading', { name: 'Registrieren'})).toBeVisible(); + await expect(page.getByRole('button', { name: 'Registrieren' })).toBeVisible(); +}) diff --git a/templates/register.html b/templates/register.html new file mode 100644 index 0000000..66a53a6 --- /dev/null +++ b/templates/register.html @@ -0,0 +1,62 @@ + + + + + + Registrierung + + + +
+

Registrieren

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + + +

Bereits ein Konto? Anmelden

+
+ + +