diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 00000000..2d79f46b --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,65 @@ +name: Playwright Tests +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v5 + with: + node-version: '24.3.0' + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.12.0 + with: + mongodb-version: 4.4 + - name: Set up JDK 21 + uses: actions/setup-java@v5 + with: + java-version: 21 + distribution: 'temurin' + cache: 'maven' + # - name: Install mongosh and import start data in database + # run: | + # sudo apt-get install gnupg + # wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-7.0.asc + # echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list + # sudo apt-get update + # sudo apt-get install -y mongodb-mongosh + # mongosh --version + # mongosh localhost:27017/myconext playwright/loadusers.js + - name: Set up cache + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- +# - name: Build with Maven +# run: mvn clean install --file pom.xml + - name: Run myconext-server + run : cd myconext-server && mvn spring-boot:run -Dspring-boot.run.profiles=dev && sleep 30 & + - name: Run account-gui + run: cd account-gui && yarn install && yarn dev && sleep 10 & + - name: Run myconext-gui + run: cd myconext-gui && yarn install && yarn dev && sleep 10 & + - name: Run servicedesk-gui + run: cd servicedesk-gui && yarn install && yarn dev && sleep 10 & + - name: Run public-gui + run: cd public-gui && yarn install && yarn dev && sleep 10 & + - name: Install dependencies for plarwright + run: cd playwright && npm install -g yarn && yarn + - name: Install Playwright Browsers + run: cd playwright && yarn playwright install --with-deps + - name: Run Playwright tests + run: cd playwright && yarn playwright test + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/README.md b/README.md index 3ec92d63..4ec0d641 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,18 @@ yarn install yarn dev ``` +Browse to the [application homepage](http://localhost:3003/). + +### The public-gui + +The myconext public gui can also be build with Svelte and to get initially started: + +``` +cd public-gui +yarn install +yarn dev +``` + Browse to the [application homepage](http://localhost:3002). ### Build diff --git a/playwright/.github/workflows/playwright.yml b/playwright/.github/workflows/playwright.yml new file mode 100644 index 00000000..a94b6417 --- /dev/null +++ b/playwright/.github/workflows/playwright.yml @@ -0,0 +1,27 @@ +name: Playwright Tests +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - name: Install dependencies + run: npm install -g yarn && yarn + - name: Install Playwright Browsers + run: yarn playwright install --with-deps + - name: Run Playwright tests + run: yarn playwright test + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/playwright/.gitignore b/playwright/.gitignore new file mode 100644 index 00000000..335bd46d --- /dev/null +++ b/playwright/.gitignore @@ -0,0 +1,8 @@ + +# Playwright +node_modules/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ +/playwright/.auth/ diff --git a/playwright/loadusers.js b/playwright/loadusers.js new file mode 100644 index 00000000..c6bf4c6f --- /dev/null +++ b/playwright/loadusers.js @@ -0,0 +1,11 @@ +const filePath = "./myconext-server/src/test/resources/users.json"; + +try { + const fileContent = fs.readFileSync(filePath, 'utf8'); + const users = JSON.parse(fileContent); + const result = db.users.insertMany(users); + + print(`Successfully inserted ${result.insertedCount} documents into the 'users' collection.`); +} catch (e) { + print(`Error loading or inserting data: ${e.message}`); +} diff --git a/playwright/package.json b/playwright/package.json new file mode 100644 index 00000000..f6be642c --- /dev/null +++ b/playwright/package.json @@ -0,0 +1,11 @@ +{ + "name": "playwright", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "devDependencies": { + "@playwright/test": "^1.56.1", + "@types/node": "^24.9.1" + }, + "scripts": {} +} diff --git a/playwright/playwright.config.ts b/playwright/playwright.config.ts new file mode 100644 index 00000000..6dfc0d9b --- /dev/null +++ b/playwright/playwright.config.ts @@ -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: './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://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, + // }, +}); diff --git a/playwright/tests/myconext-gui-check-for-404s.spec.ts b/playwright/tests/myconext-gui-check-for-404s.spec.ts new file mode 100644 index 00000000..4427cc4f --- /dev/null +++ b/playwright/tests/myconext-gui-check-for-404s.spec.ts @@ -0,0 +1,53 @@ +import { expect, Page, test } from "@playwright/test" + +async function getAllLinksFromPage(page: Page) { + // getByRole('link') only matches visible links + // + // if you want to check all links, you can use a CSS selector + // like 'locator("a")' + const links = page.getByRole("link") + + const allLinks = await links.all() + const allLinkHrefs = await Promise.all( + allLinks.map((link) => link.getAttribute("href")) + ) + const validHrefs = allLinkHrefs.reduce((links, link) => { + expect.soft(link, "link has no a proper href").not.toBeFalsy() + + if (link && !link?.startsWith("mailto:") && !link?.startsWith("#")) + links.add(new URL(link, page.url()).href) + return links + }, new Set()) + + return validHrefs +} + +test.describe("No 404s on Checkly pages", () => { + test(`The docs have no 404s`, async ({ page }, testInfo) => { + await page.goto("http://localhost:3002") + const linkUrls = await getAllLinksFromPage(page) + + for (const url of linkUrls) { + await test.step(`Checking link: ${url}`, async () => { + try { + // Note that some hosters / firewalls will block plain requests (Cloudflare, etc.) + // if that's the case for you, consider using `page.goto` + // or excluding particular URLs from the test + const response = await page.request.get(url) + + expect + .soft(response.ok(), `${url} has no green status code`) + .toBeTruthy() + } catch { + expect.soft(null, `${url} has no green status code`).toBeTruthy() + } + }) + } + + testInfo.attach("checked-links.txt", { + body: Array.from(linkUrls).join("\n"), + }) + }) +}) + +// Source: https://github.com/checkly/playwright-examples/blob/main/404-detection/tests/no-404s.spec.ts \ No newline at end of file diff --git a/playwright/tests/myconext-gui-check-home-page.spec.ts b/playwright/tests/myconext-gui-check-home-page.spec.ts new file mode 100644 index 00000000..0fdf5b29 --- /dev/null +++ b/playwright/tests/myconext-gui-check-home-page.spec.ts @@ -0,0 +1,10 @@ +import { test, expect } from '@playwright/test'; + +test('check generale page', async ({ page }) => { + await page.goto('http://localhost:3002'); + await page.getByRole('link', {name: 'EN'}).click(); + await expect(page.getByRole('heading', { name: 'eduID', exact: true })).toBeVisible(); + await expect(page.getByRole('button', { name: 'My eduID' })).toBeVisible(); + await expect(page.getByRole('button', { name: 'Create an eduID' }).first()).toBeVisible(); + +}); \ No newline at end of file diff --git a/playwright/yarn.lock b/playwright/yarn.lock new file mode 100644 index 00000000..d250dd94 --- /dev/null +++ b/playwright/yarn.lock @@ -0,0 +1,41 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@playwright/test@^1.56.1": + version "1.56.1" + resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.56.1.tgz#6e3bf3d0c90c5cf94bf64bdb56fd15a805c8bd3f" + integrity sha512-vSMYtL/zOcFpvJCW71Q/OEGQb7KYBPAdKh35WNSkaZA75JlAO8ED8UN6GUNTm3drWomcbcqRPFqQbLae8yBTdg== + dependencies: + playwright "1.56.1" + +"@types/node@^24.9.1": + version "24.9.1" + resolved "https://registry.yarnpkg.com/@types/node/-/node-24.9.1.tgz#b7360b3c789089e57e192695a855aa4f6981a53c" + integrity sha512-QoiaXANRkSXK6p0Duvt56W208du4P9Uye9hWLWgGMDTEoKPhuenzNcC4vGUmrNkiOKTlIrBoyNQYNpSwfEZXSg== + dependencies: + undici-types "~7.16.0" + +fsevents@2.3.2: + version "2.3.2" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + +playwright-core@1.56.1: + version "1.56.1" + resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.56.1.tgz#24a66481e5cd33a045632230aa2c4f0cb6b1db3d" + integrity sha512-hutraynyn31F+Bifme+Ps9Vq59hKuUCz7H1kDOcBs+2oGguKkWTU50bBWrtz34OUWmIwpBTWDxaRPXrIXkgvmQ== + +playwright@1.56.1: + version "1.56.1" + resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.56.1.tgz#62e3b99ddebed0d475e5936a152c88e68be55fbf" + integrity sha512-aFi5B0WovBHTEvpM3DzXTUaeN6eN0qWnTkKx4NQaH4Wvcmc153PdaY2UBdSYKaGYw+UyWXSVyxDUg5DoPEttjw== + dependencies: + playwright-core "1.56.1" + optionalDependencies: + fsevents "2.3.2" + +undici-types@~7.16.0: + version "7.16.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-7.16.0.tgz#ffccdff36aea4884cbfce9a750a0580224f58a46" + integrity sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==