From ce3562f07911fc5a017dd12fff448cc41decd299 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 16:00:02 +0100 Subject: [PATCH 01/20] add playwright tests --- .gitea/workflows/action.yml | 27 ++++++++++-- frontend/.gitignore | 5 +++ frontend/package.json | 2 + frontend/playwright.config.ts | 75 ++++++++++++++++++++++++++++++++++ frontend/tests/example.spec.ts | 22 ++++++++++ 5 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 frontend/playwright.config.ts create mode 100644 frontend/tests/example.spec.ts diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 4b7a8f7..7af2ef5 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -9,7 +9,28 @@ env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} jobs: - test: + test-frontend: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install dependencies + run: npm ci + - name: Install Playwright Browsers + run: npx playwright install --with-deps + - name: Run Playwright tests + run: npx playwright test + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 + + test-backend: runs-on: ubuntu-latest container: rust:latest @@ -35,7 +56,7 @@ jobs: deploy-staging: runs-on: ubuntu-latest container: rust:latest - needs: [test] + needs: [test_frontend, test_backend] if: github.ref == 'refs/heads/staging' steps: - name: Setup Environment @@ -95,7 +116,7 @@ jobs: deploy-main: runs-on: ubuntu-latest container: rust:latest - needs: [test] + needs: [test_frontend, test_backend] if: github.ref == 'refs/heads/main' steps: - name: Setup Environment diff --git a/frontend/.gitignore b/frontend/.gitignore index d8b83df..bdf87f1 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -1 +1,6 @@ package-lock.json +node_modules/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/frontend/package.json b/frontend/package.json index 8b82d1e..0b42352 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -9,7 +9,9 @@ "preview": "vite preview" }, "devDependencies": { + "@playwright/test": "^1.40.1", "@types/d3": "^7.4.1", + "@types/node": "^20.11.4", "autoprefixer": "^10.4.14", "postcss": "^8.4.21", "sass": "^1.60.0", diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts new file mode 100644 index 0000000..a12a9b0 --- /dev/null +++ b/frontend/playwright.config.ts @@ -0,0 +1,75 @@ +import { defineConfig, devices } from '@playwright/test'; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * 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: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: 'cd .. && ./test_db.sh && cargo r', + }, +}); diff --git a/frontend/tests/example.spec.ts b/frontend/tests/example.spec.ts new file mode 100644 index 0000000..18740ca --- /dev/null +++ b/frontend/tests/example.spec.ts @@ -0,0 +1,22 @@ +import { test, expect } from '@playwright/test'; + +test('cox can create trip', async ({ page }) => { + await page.goto('http://localhost:8000/auth'); + await page.getByPlaceholder('Name').click(); + await page.getByPlaceholder('Name').fill('cox'); + await page.getByPlaceholder('Name').press('Tab'); + await page.getByPlaceholder('Passwort').fill('cox'); + await page.getByRole('button', { name: 'Einloggen' }).click(); + await expect(page.locator('body')).toContainText('Login erfolgreich'); + await page.locator('li').filter({ hasText: 'Geplante Ausfahrten' }).click(); + await page.getByRole('link', { name: 'Geplante Ausfahrten' }).click(); + await page.locator('.relative').first().click(); + await page.locator('#sidebar #planned_starting_time').click(); + await page.locator('#sidebar #planned_starting_time').press('ArrowLeft'); + await page.locator('#sidebar #planned_starting_time').press('Tab'); + await page.locator('#sidebar #planned_starting_time').fill('14:00'); + await page.locator('#sidebar #planned_starting_time').press('Tab'); + await page.getByRole('spinbutton').fill('4'); + await page.getByRole('button', { name: 'Erstellen', exact: true }).click(); + await expect(page.locator('body')).toContainText('Ausfahrt erfolgreich erstellt.'); +}); From 537458b58e5db70461df9958ff26728df77b526f Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 16:07:40 +0100 Subject: [PATCH 02/20] try --- .gitea/workflows/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 7af2ef5..3a6530c 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -14,9 +14,9 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 + - name: Setup Environment + run: | + apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y - name: Install dependencies run: npm ci - name: Install Playwright Browsers From bd650f738c8cde303ebc85922528fb9c26c958b6 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 16:09:09 +0100 Subject: [PATCH 03/20] try --- .gitea/workflows/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 3a6530c..2595cdc 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -14,9 +14,9 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Setup Environment - run: | - apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y + - name: Setup Environment + run: | + apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y - name: Install dependencies run: npm ci - name: Install Playwright Browsers From 4ab1a36fcd780dffddd69655f2037fe8b30294a5 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 16:09:45 +0100 Subject: [PATCH 04/20] try --- .gitea/workflows/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 2595cdc..b822bbd 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - name: Setup Environment run: | apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y + - uses: actions/checkout@v3 - name: Install dependencies run: npm ci - name: Install Playwright Browsers From c1493ad9143679d5e27dd3580ea6e008d9a945f2 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 16:10:13 +0100 Subject: [PATCH 05/20] try --- .gitea/workflows/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index b822bbd..6b5efc2 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -11,7 +11,7 @@ env: jobs: test-frontend: runs-on: ubuntu-latest - + container: rust:latest steps: - name: Setup Environment run: | From ae673657b0436c9f3349e128c0400f77b85f3fb8 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 16:13:41 +0100 Subject: [PATCH 06/20] try --- .gitea/workflows/action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 6b5efc2..2966061 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -18,16 +18,16 @@ jobs: apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y - uses: actions/checkout@v3 - name: Install dependencies - run: npm ci + run: cd frontend && npm ci - name: Install Playwright Browsers - run: npx playwright install --with-deps + run: cd frontend && npx playwright install --with-deps - name: Run Playwright tests - run: npx playwright test + run: cd frontend && npx playwright test - uses: actions/upload-artifact@v3 if: always() with: name: playwright-report - path: playwright-report/ + path: frontend/playwright-report/ retention-days: 30 test-backend: From 98d8b512eea58d8bc31eb33cd15e5627bd4a2cf6 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 16:16:56 +0100 Subject: [PATCH 07/20] try --- .gitea/workflows/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 2966061..633e9b8 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -18,7 +18,7 @@ jobs: apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y - uses: actions/checkout@v3 - name: Install dependencies - run: cd frontend && npm ci + run: cd frontend && npm install - name: Install Playwright Browsers run: cd frontend && npx playwright install --with-deps - name: Run Playwright tests From 875799c3d71789264f4d7700846e3026a5c0b447 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 16:42:57 +0100 Subject: [PATCH 08/20] try --- .gitea/workflows/action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 633e9b8..f637ba7 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -17,6 +17,10 @@ jobs: run: | apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y - uses: actions/checkout@v3 + - name: Build + run: | + cargo build + cd frontend && npm install && npm run build - name: Install dependencies run: cd frontend && npm install - name: Install Playwright Browsers From b633a4bfee3b29c056f928d75348efaa9689b9b9 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 16:55:47 +0100 Subject: [PATCH 09/20] try --- .gitea/workflows/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index f637ba7..62422d6 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -17,6 +17,8 @@ jobs: run: | apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y - uses: actions/checkout@v3 + - name: Run Test DB Script + run: ./test_db.sh - name: Build run: | cargo build From 442453bef388be5c88c4dd53e2633f40c33858ee Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 19:17:17 +0100 Subject: [PATCH 10/20] try --- .gitea/workflows/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 62422d6..7b5f418 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -54,6 +54,7 @@ jobs: - name: Build run: | cargo build + mkdir svelte && cd svelte && mkdir build && cd .. cd frontend && npm install && npm run build - name: Run Tests From 64bb15cc8b6eb21c085bcfaadd070b98bc3b0610 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 19:40:20 +0100 Subject: [PATCH 11/20] try --- .gitea/workflows/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 7b5f418..9ab476b 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -20,7 +20,8 @@ jobs: - name: Run Test DB Script run: ./test_db.sh - name: Build - run: | + run: + mkdir svelte && cd svelte && mkdir build && cd .. cargo build cd frontend && npm install && npm run build - name: Install dependencies @@ -54,7 +55,6 @@ jobs: - name: Build run: | cargo build - mkdir svelte && cd svelte && mkdir build && cd .. cd frontend && npm install && npm run build - name: Run Tests From 7aef741c6f44687c750a37a902d2a1cbe1ac1053 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 19:48:41 +0100 Subject: [PATCH 12/20] try --- .gitea/workflows/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 9ab476b..1972712 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -21,7 +21,7 @@ jobs: run: ./test_db.sh - name: Build run: - mkdir svelte && cd svelte && mkdir build && cd .. + cd svelte && mkdir build && cd .. cargo build cd frontend && npm install && npm run build - name: Install dependencies From bc1916ceab20decfd8bf84d40b7b19e1ec3d2952 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 19:54:24 +0100 Subject: [PATCH 13/20] try --- .gitea/workflows/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 1972712..bfddc09 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -22,7 +22,9 @@ jobs: - name: Build run: cd svelte && mkdir build && cd .. + pwd cargo build + pwd cd frontend && npm install && npm run build - name: Install dependencies run: cd frontend && npm install From 2a025d7519788de30729dba8b37024abdd995431 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 20:00:41 +0100 Subject: [PATCH 14/20] try --- .gitea/workflows/action.yml | 3 --- svelte/.gitignore | 1 - 2 files changed, 4 deletions(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index bfddc09..6fa4dab 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -21,10 +21,7 @@ jobs: run: ./test_db.sh - name: Build run: - cd svelte && mkdir build && cd .. - pwd cargo build - pwd cd frontend && npm install && npm run build - name: Install dependencies run: cd frontend && npm install diff --git a/svelte/.gitignore b/svelte/.gitignore index 8f6c617..9280939 100644 --- a/svelte/.gitignore +++ b/svelte/.gitignore @@ -1,6 +1,5 @@ .DS_Store node_modules -/build /.svelte-kit /package .env From 6a1bde55a27f0284bf8edc7593c48f9dc462aa5c Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 20:04:34 +0100 Subject: [PATCH 15/20] try --- .gitea/workflows/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 6fa4dab..62422d6 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -20,7 +20,7 @@ jobs: - name: Run Test DB Script run: ./test_db.sh - name: Build - run: + run: | cargo build cd frontend && npm install && npm run build - name: Install dependencies From 7e1a0a2159eaa99935f08880cc1d10cf05b02680 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 20:24:02 +0100 Subject: [PATCH 16/20] try --- src/rest/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rest/mod.rs b/src/rest/mod.rs index b90bac0..ef69ad9 100644 --- a/src/rest/mod.rs +++ b/src/rest/mod.rs @@ -27,7 +27,7 @@ async fn login(login: Form>, db: &State) -> String { pub fn config(rocket: Rocket) -> Rocket { rocket - .mount("/", FileServer::from("svelte/build").rank(0)) + //.mount("/", FileServer::from("svelte/build").rank(0)) .mount("/api/login", routes![login]) } From c372051561b9a13440ff50a0200d441e18d8a963 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jan 2024 22:29:57 +0100 Subject: [PATCH 17/20] try --- .gitea/workflows/action.yml | 2 +- frontend/tests/cox.spec.ts | 114 ++++++++++++++++++++++++++++ frontend/tests/example.spec.ts | 22 ------ templates/includes/macros.html.tera | 2 +- 4 files changed, 116 insertions(+), 24 deletions(-) create mode 100644 frontend/tests/cox.spec.ts delete mode 100644 frontend/tests/example.spec.ts diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 62422d6..cdf19ad 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -28,7 +28,7 @@ jobs: - name: Install Playwright Browsers run: cd frontend && npx playwright install --with-deps - name: Run Playwright tests - run: cd frontend && npx playwright test + run: cd frontend && npx playwright test --workers 1 - uses: actions/upload-artifact@v3 if: always() with: diff --git a/frontend/tests/cox.spec.ts b/frontend/tests/cox.spec.ts new file mode 100644 index 0000000..ae65a99 --- /dev/null +++ b/frontend/tests/cox.spec.ts @@ -0,0 +1,114 @@ +import { test, expect } from '@playwright/test'; + +test('cox can create and delete trip', async ({ page }) => { + await page.goto('http://localhost:8000/auth'); + await page.getByPlaceholder('Name').click(); + await page.getByPlaceholder('Name').fill('cox'); + await page.getByPlaceholder('Name').press('Tab'); + await page.getByPlaceholder('Passwort').fill('cox'); + await page.getByPlaceholder('Passwort').press('Enter'); + await page.getByRole('link', { name: 'Geplante Ausfahrten' }).click(); + await page.locator('.relative').first().click(); + await page.locator('#sidebar #planned_starting_time').click(); + await page.locator('#sidebar #planned_starting_time').fill('18:00'); + await page.locator('#sidebar #planned_starting_time').press('Tab'); + await page.locator('#sidebar #planned_starting_time').press('Tab'); + await page.getByRole('spinbutton').fill('5'); + await page.getByRole('button', { name: 'Erstellen', exact: true }).click(); + await page.getByRole('link', { name: 'Geplante Ausfahrten' }).click(); + await expect(page.locator('body')).toContainText('18:00 Uhr (cox) Details'); + + await page.goto('http://localhost:8000/planned'); + await page.getByRole('link', { name: 'Details' }).click(); + await page.getByRole('link', { name: 'Termin löschen' }).click(); + await expect(page.locator('body')).toContainText('Erfolgreich gelöscht!'); +}); + +test.describe('cox can edit trips', () => { + let sharedPage; + + test.beforeEach(async ({ browser }) => { + const page = await browser.newPage(); + + await page.goto('http://localhost:8000/auth'); + await page.getByPlaceholder('Name').click(); + await page.getByPlaceholder('Name').fill('cox'); + await page.getByPlaceholder('Name').press('Tab'); + await page.getByPlaceholder('Passwort').fill('cox'); + await page.getByPlaceholder('Passwort').press('Enter'); + await page.getByRole('link', { name: 'Geplante Ausfahrten' }).click(); + await page.locator('.relative').first().click(); + await page.locator('#sidebar #planned_starting_time').click(); + await page.locator('#sidebar #planned_starting_time').fill('18:00'); + await page.locator('#sidebar #planned_starting_time').press('Tab'); + await page.locator('#sidebar #planned_starting_time').press('Tab'); + await page.getByRole('spinbutton').fill('5'); + await page.getByRole('button', { name: 'Erstellen', exact: true }).click(); + + sharedPage = page; + }); + + test('edit remarks', async () => { + await sharedPage.goto('http://localhost:8000/planned'); + await sharedPage.getByRole('link', { name: 'Details' }).click(); + await sharedPage.locator('#sidebar #notes').click(); + await sharedPage.locator('#sidebar #notes').fill('Meine Anmerkung'); + await sharedPage.getByRole('button', { name: 'Speichern' }).click(); + await sharedPage.getByRole('link', { name: 'Geplante Ausfahrten' }).click(); + await sharedPage.getByRole('link', { name: 'Details' }).click(); + await expect(sharedPage.locator('#sidebar')).toContainText('Meine Anmerkung'); + await sharedPage.locator('.sidebar-overlay').click(); + }); + + test('add and remove guest', async () => { + await sharedPage.goto('http://localhost:8000/planned'); + await sharedPage.getByRole('link', { name: 'Details' }).click(); + await sharedPage.locator('#sidebar #user_note').click(); + await sharedPage.locator('#sidebar #user_note').fill('Mein Gast'); + await sharedPage.getByRole('button', { name: 'Gast hinzufügen' }).click(); + await expect(sharedPage.locator('body')).toContainText('Erfolgreich angemeldet!'); + await sharedPage.getByRole('link', { name: 'Details' }).click(); + await expect(sharedPage.locator('#sidebar')).toContainText('Freie Plätze: 4'); + await expect(sharedPage.locator('#sidebar')).toContainText('Mein Gast (Gast) Abmelden'); + await expect(sharedPage.getByRole('link', { name: 'Termin löschen' })).not.toBeVisible(); + + await sharedPage.getByRole('link', { name: 'Abmelden' }).click(); + await expect(sharedPage.locator('body')).toContainText('Erfolgreich abgemeldet!'); + await sharedPage.getByRole('link', { name: 'Details' }).click(); + await expect(sharedPage.locator('#sidebar')).toContainText('Freie Plätze: 5'); + await expect(sharedPage.locator('#sidebar')).toContainText('Keine Ruderer angemeldet'); + await expect(sharedPage.getByRole('link', { name: 'Termin löschen' })).toBeVisible(); + + await sharedPage.locator('.sidebar-overlay').click(); + }); + + test('change amount rower', async () => { + await sharedPage.goto('http://localhost:8000/planned'); + await sharedPage.getByRole('link', { name: 'Details' }).click(); + await expect(sharedPage.locator('#sidebar')).toContainText('Freie Plätze: 5'); + await sharedPage.getByRole('spinbutton').click(); + await sharedPage.getByRole('spinbutton').fill('3'); + await sharedPage.getByRole('button', { name: 'Speichern' }).click(); + await expect(sharedPage.locator('body')).toContainText('Ausfahrt erfolgreich aktualisiert.'); + await sharedPage.getByRole('link', { name: 'Geplante Ausfahrten' }).click(); + }); + + test('call off trip', async () => { + await sharedPage.goto('http://localhost:8000/planned'); + await sharedPage.getByRole('link', { name: 'Details' }).click(); + await expect(sharedPage.locator('#sidebar')).toContainText('Freie Plätze: 5'); + await sharedPage.getByRole('spinbutton').click(); + await sharedPage.getByRole('spinbutton').fill('0'); + await sharedPage.getByRole('button', { name: 'Speichern' }).click(); + await expect(sharedPage.locator('body')).toContainText('Ausfahrt erfolgreich aktualisiert.'); + await sharedPage.getByRole('link', { name: 'Geplante Ausfahrten' }).click(); + await expect(sharedPage.locator('body')).toContainText('(Absage cox )'); + }); + + test.afterEach(async () => { + await sharedPage.goto('http://localhost:8000/planned'); + await sharedPage.getByRole('link', { name: 'Details' }).click(); + await sharedPage.getByRole('link', { name: 'Termin löschen' }).click(); + await sharedPage.close(); + }); +}); diff --git a/frontend/tests/example.spec.ts b/frontend/tests/example.spec.ts deleted file mode 100644 index 18740ca..0000000 --- a/frontend/tests/example.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { test, expect } from '@playwright/test'; - -test('cox can create trip', async ({ page }) => { - await page.goto('http://localhost:8000/auth'); - await page.getByPlaceholder('Name').click(); - await page.getByPlaceholder('Name').fill('cox'); - await page.getByPlaceholder('Name').press('Tab'); - await page.getByPlaceholder('Passwort').fill('cox'); - await page.getByRole('button', { name: 'Einloggen' }).click(); - await expect(page.locator('body')).toContainText('Login erfolgreich'); - await page.locator('li').filter({ hasText: 'Geplante Ausfahrten' }).click(); - await page.getByRole('link', { name: 'Geplante Ausfahrten' }).click(); - await page.locator('.relative').first().click(); - await page.locator('#sidebar #planned_starting_time').click(); - await page.locator('#sidebar #planned_starting_time').press('ArrowLeft'); - await page.locator('#sidebar #planned_starting_time').press('Tab'); - await page.locator('#sidebar #planned_starting_time').fill('14:00'); - await page.locator('#sidebar #planned_starting_time').press('Tab'); - await page.getByRole('spinbutton').fill('4'); - await page.getByRole('button', { name: 'Erstellen', exact: true }).click(); - await expect(page.locator('body')).toContainText('Ausfahrt erfolgreich erstellt.'); -}); diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index c2691b4..c1adb2d 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -209,7 +209,7 @@ {% if rower.is_real_guest %} (Gast) {% if allow_removing %} - Abmelden + Abmelden {% endif %} {% endif %}