Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Company data tests1 #148

Merged
merged 21 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
import { defineConfig } from '@playwright/test';
export default defineConfig({
// // test for development version
// webServer: {
// command: 'while true; do npm run dev; done',
// url: 'http://localhost:5173',
// timeout: 10000,
// reuseExistingServer: true
// },
// use: {
// baseURL: 'http://localhost:5173/'
// },
// test for development version
webServer: {
command: 'docker compose up prima',
url: 'http://127.0.0.1:8080',
command: 'while true; do npm run dev; done',
url: 'http://localhost:5173',
timeout: 10000,
reuseExistingServer: true
},
use: {
baseURL: 'http://localhost:8080/'
baseURL: 'http://localhost:5173/'
},
// webServer: {
// command: 'docker compose up prima',
// url: 'http://127.0.0.1:8080',
// timeout: 10000,
// reuseExistingServer: true
// },
// use: {
// baseURL: 'http://localhost:8080/'
// },
testDir: './tests',
projects: [
{
name: 'setup db',
testMatch: /global\.setup\.ts/
testMatch: /db\.setup\.ts/
},
{
name: 'login',
testMatch: /login\.setup\.ts/,
dependencies: ['setup db']
},
{
name: 'user test',
testMatch: /(.+\.)?(test|spec)\.[jt]s/,
dependencies: ['setup db']
dependencies: ['setup db', 'login']
}
]
});
2 changes: 1 addition & 1 deletion src/routes/(user)/company/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const actions = {
}

if (isNaN(zone) || zone < 1) {
return fail(400, { error: 'Pflichtfahrgebiet nicht gesetzt' });
return fail(400, { error: 'Pflichtfahrgebiet nicht gesetzt.' });
}

let bestAddressGuess: AddressGuess | undefined = undefined;
Expand Down
8 changes: 4 additions & 4 deletions src/routes/(user)/company/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<div class="w-full h-full">
<Card.Header>
<Card.Title>Stammdaten ihres Unternehmens</Card.Title>
<Card.Title>Stammdaten Ihres Unternehmens</Card.Title>
</Card.Header>
<Card.Content class="w-full h-full">
{#if form?.error}
Expand All @@ -30,9 +30,9 @@
<Alert.Root class="mb-4">
<ExclamationTriangle class="h-4 w-4" />
<Alert.Title>Aktualisierung erfolgreich.</Alert.Title>
<Alert.Description
>Die Stammdaten ihres Unternehmens Ihres Unternehmens wurden aktualisiert.</Alert.Description
>
<Alert.Description>
Die Stammdaten Ihres Unternehmens wurden aktualisiert.
</Alert.Description>
</Alert.Root>
{/if}

Expand Down
83 changes: 83 additions & 0 deletions tests/companyData.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { expect, test } from '@playwright/test';
import { login, ENTREPENEUR } from './utils';

test('Set company data, incomplete 1', async ({ page }) => {
await login(page, ENTREPENEUR);
await expect(page.getByRole('heading', { name: 'Stammdaten Ihres Unternehmens' })).toBeVisible();

await page.getByLabel('Name').fill('Test');
await page.getByRole('button', { name: 'Übernehmen' }).click();

await expect(page.getByText('Adresse zu kurz.')).toBeVisible();
});

test('Set company data, incomplete 2', async ({ page }) => {
await login(page, ENTREPENEUR);

await page.getByLabel('Name').fill('Test');
await page.getByLabel('Unternehmenssitz').fill('Plantagenweg 3, 02827 Görlitz');
await page.getByRole('button', { name: 'Übernehmen' }).click();

await expect(
page.getByText('Die Eingabe muss mindestens 2 Zeichen enthalten.')
).not.toBeVisible();
await expect(page.getByText('Gemeinde nicht gesetzt.')).toBeVisible();
});

test('Set company data, incomplete 3', async ({ page }) => {
await login(page, ENTREPENEUR);

await page.getByLabel('Name').fill('Taxi Weißwasser');
await page
.getByLabel('Unternehmenssitz')
.fill('Werner-Seelenbinder-Straße 70A, 02943 Weißwasser/Oberlausitz');
await page.getByLabel('Pflichtfahrgebiet').selectOption({ label: 'Görlitz' });
await page.getByRole('button', { name: 'Übernehmen' }).click();

await expect(page.getByText('Gemeinde nicht gesetzt.')).toBeVisible();
});

test('Set company data, address not in community', async ({ page }) => {
await login(page, ENTREPENEUR);
await expect(page.getByRole('heading', { name: 'Stammdaten Ihres Unternehmens' })).toBeVisible();

await page.getByLabel('Name').fill('Taxi Weißwasser');
await page.getByLabel('Unternehmenssitz').fill('Plantagenweg 3, 02827 Görlitz');
await page.waitForTimeout(250);
await page.getByLabel('Pflichtfahrgebiet').selectOption({ label: 'Görlitz' });
await page.getByLabel('Gemeinde').selectOption({ label: 'Weißwasser/O.L.' });
await page.getByRole('button', { name: 'Übernehmen' }).click();

await expect(
page.getByText('Die Addresse liegt nicht in der ausgewählten Gemeinde.')
).toBeVisible();
});

test('Set company data, complete and consistent', async ({ page }) => {
await login(page, ENTREPENEUR);
await expect(page.getByRole('heading', { name: 'Stammdaten Ihres Unternehmens' })).toBeVisible();

await page.getByLabel('Name').fill('Taxi Weißwasser');
await page
.getByLabel('Unternehmenssitz')
.fill('Werner-Seelenbinder-Straße 70A, 02943 Weißwasser/Oberlausitz');
await page.waitForTimeout(250);
await page.getByLabel('Pflichtfahrgebiet').selectOption({ label: 'Weißwasser' });
await page.getByLabel('Gemeinde').selectOption({ label: 'Weißwasser/O.L.' });
await page.getByRole('button', { name: 'Übernehmen' }).click();

await expect(page.getByRole('heading', { name: 'Stammdaten Ihres Unternehmens' })).toBeVisible();

const checkData = async () => {
await expect(page.getByLabel('Name')).toHaveValue('Taxi Weißwasser');
await expect(page.getByLabel('Unternehmenssitz')).toHaveValue(
'Werner-Seelenbinder-Straße 70A, 02943 Weißwasser/Oberlausitz'
);
await expect(page.getByLabel('Pflichtfahrgebiet')).toHaveValue('2' /* Görlitz */);
await expect(page.getByLabel('Gemeinde')).toHaveValue('85' /* Weißwasser */);
};

await checkData();
await page.reload();
await checkData();
});
8 changes: 8 additions & 0 deletions tests/global.setup.ts → tests/db.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ setup('setup db', async () => {
const zonesQuery = fs.readFileSync(zonesSqlPath).toString();
await pool.query(zonesQuery);
console.log('zones added');

await sleep(1000);
});

function sleep(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
32 changes: 32 additions & 0 deletions tests/login.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect, test } from '@playwright/test';
import { Kysely, PostgresDialect, sql } from 'kysely';
import { dbConfig } from './config';
import pg from 'pg';
import { login, signup, MAINTAINER, ENTREPENEUR } from './utils';

test.describe.configure({ mode: 'serial' });

test('signup maintainer', async ({ page }) => {
await signup(page, MAINTAINER);
const db = new Kysely<unknown>({
dialect: new PostgresDialect({
pool: new pg.Pool({ ...dbConfig, database: 'prima' })
})
});
await sql`UPDATE auth_user SET is_maintainer = true WHERE email = 'master@example.com'`.execute(
db
);
db.destroy();
});

test('signup taxi', async ({ page }) => {
await signup(page, ENTREPENEUR);
});

test('activate taxi', async ({ page }) => {
await login(page, MAINTAINER);
await expect(page.getByRole('heading', { name: 'Unternehmer freischalten' })).toBeVisible();
await page.getByLabel('Email').fill(ENTREPENEUR.email);
await page.getByRole('button', { name: 'Unternehmer freischalten' }).click();
await expect(page.getByText('Freischalten erfolgreich!')).toBeVisible();
});
92 changes: 0 additions & 92 deletions tests/test.ts

This file was deleted.

35 changes: 35 additions & 0 deletions tests/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect, type Page } from '@playwright/test';

export type UserCredentials = {
email: string;
password: string;
};

export const MAINTAINER: UserCredentials = {
email: 'master@example.com',
password: 'longEnough1'
};

export const ENTREPENEUR: UserCredentials = {
email: 'taxi@example.com',
password: 'longEnough2'
};

export async function login(page: Page, credentials: UserCredentials) {
await page.goto('/login');
await expect(page.getByRole('heading', { name: 'Login' })).toBeVisible();
await page.getByLabel('Email').fill(credentials.email);
await page.getByLabel('Password').fill(credentials.password);
await page.getByRole('button', { name: 'Login' }).click();
}

export async function signup(page: Page, credentials: UserCredentials) {
await page.goto('/signup');
await expect(page.getByRole('heading', { name: 'Neuen Account erstellen' })).toBeVisible();
await page.getByLabel('Email').fill(credentials.email);
await page.getByLabel('Password').fill(credentials.password);
await page.getByRole('button', { name: 'Account erstellen' }).click();
await expect(
page.getByRole('heading', { name: 'Willkommen beim Projekt PrimaÖV!' })
).toBeVisible();
}