🏡 index : ~doyle/chartered.git

author jordan <jordan@doyle.la> 2022-09-07 3:28:07.0 +01:00:00
committer GitHub <noreply@github.com> 2022-09-07 3:28:07.0 +01:00:00
commit
6723f088b334987a45f0abb6eceff72847805530 [patch]
tree
6476f3bbd7901392ac0a23c84ceab7378973aa0e
parent
6aa4df1a6a7fbcf5dc1b2877cd05d6e1b0b657a4
parent
43770d20014b87b0bb7784b40b0a0871961fbc79
download
6723f088b334987a45f0abb6eceff72847805530.tar.gz

Merge pull request #35 from w4/e2e-ui-tests

Add E2E UI tests in CI

Diff

 .github/workflows/integration-tests.yml | 40 ++++++++++++++++++++++++++++++++++++++++
 chartered-frontend/tests/test.ts        | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml
new file mode 100644
index 0000000..23d7a85 100644
--- /dev/null
+++ a/.github/workflows/integration-tests.yml
@@ -1,0 +1,40 @@
on: [push, pull_request]

name: CI - Integration Tests

jobs:
  e2e-ui-test:
    name: End-to-end UI tests
    runs-on: ubuntu-22.04 # needed for recent sqlite version
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - uses: actions/setup-node@v2
        with:
          node-version: '18'
      - uses: actions-rs/cargo@v1
        with:
          command: build
          args: -p chartered-web -p chartered-db --features sqlite
      - name: Install dependencies
        working-directory: ./chartered-frontend
        run: npm ci
      - name: Install Playwright
        working-directory: ./chartered-frontend
        run: npx playwright install --with-deps
      - name: Run tests
        working-directory: ./chartered-frontend
        run: |

          ../target/debug/chartered-web -c ../chartered-web/config-example.toml &
          sleep 5
          npm test
      - name: Upload test results
        if: always()
        uses: actions/upload-artifact@v2
        with:
          name: playwright-report
          path: playwright-report
diff --git a/chartered-frontend/tests/test.ts b/chartered-frontend/tests/test.ts
index 8fb4a4f..4928e8a 100644
--- a/chartered-frontend/tests/test.ts
+++ a/chartered-frontend/tests/test.ts
@@ -1,6 +1,37 @@
import { expect, test } from '@playwright/test';

test('index page has expected h1', async ({ page }) => {
test('redirect to login when unauthenticated', async ({ page }) => {
    await page.goto('/');
    expect(await page.textContent('h1')).toBe('Welcome to SvelteKit');
    expect(await page.textContent('h1')).toBe('chartered ✈️');
    expect(await page.textContent('button')).toBe('Login');
});

test('register button takes user to register page', async ({ page }) => {
    await page.goto('/');
    await page.locator('text=Register').click();
    await expect(page).toHaveURL(/.*register/);
    expect(await page.textContent('h1')).toBe('chartered ✈️');
    expect(await page.textContent('button')).toBe('Register');
});

test('can successfully register and login', async ({ page }) => {
    const username = Math.random().toString(36).substring(2,7);
    const password = 'aaaaaaaa';

    await page.goto('/');
    await page.locator('text=Register').click();

    await page.locator('input[id="username"]').fill(username);
    await page.locator('input[id="password"]').fill(password);
    await page.locator('text=Register').click();

    await expect(page.locator('[role="alert"]')).toHaveCount(0);

    await expect(page).toHaveURL(/.*login/);
    await page.locator('input[id="username"]').fill(username);
    await page.locator('input[id="password"]').fill(password);
    await page.locator('text=Username Password Login >> button').click();

    await expect(page).not.toHaveURL(/.*login/);
    expect(await page.textContent('h1')).toBe('Welcome to Chartered.');
});