190 lines
7.3 KiB
TypeScript
190 lines
7.3 KiB
TypeScript
import { test, expect } from './fixtures';
|
|
import {
|
|
mockApi,
|
|
TEST_GYM_OWNED,
|
|
TEST_TRAINEE_DETAIL_NICK,
|
|
TEST_TRAINEE_NICK,
|
|
TEST_USER,
|
|
TEST_USER_WITH_SOCIALS,
|
|
} from './mock-api';
|
|
|
|
function trainerMe() {
|
|
return {
|
|
user: TEST_USER,
|
|
memberships: [{ gymId: TEST_GYM_OWNED.id, roles: ['TRAINER'], gym: TEST_GYM_OWNED }],
|
|
};
|
|
}
|
|
|
|
async function login(page: import('@playwright/test').Page) {
|
|
await page.goto('/login');
|
|
await page.locator('input[type="email"]').fill('test@fitos.pl');
|
|
await page.locator('input[type="password"]').fill('haslo123');
|
|
await page.getByRole('button', { name: 'Zaloguj' }).click();
|
|
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
|
}
|
|
|
|
test('profil: podgląd nicku i social media', async ({ page }) => {
|
|
mockApi(page, { me: { user: TEST_USER_WITH_SOCIALS, memberships: [] } });
|
|
await login(page);
|
|
await page.getByRole('link', { name: 'Profil' }).click();
|
|
await page.getByRole('link', { name: 'Dane osobowe' }).click();
|
|
await expect(page.getByRole('heading', { name: 'Profil — dane osobowe' })).toBeVisible();
|
|
|
|
// nick jako wiersz „Nick” w karcie „Podstawowe dane”
|
|
await expect(page.getByText('fitfan')).toBeVisible();
|
|
// social media jako klikalne linki (platforma + własna etykieta dla OTHER)
|
|
const instagram = page.getByRole('link', { name: 'Instagram' });
|
|
await expect(instagram).toHaveAttribute('href', 'https://instagram.com/fitfan');
|
|
await expect(page.getByRole('link', { name: 'Blog' })).toHaveAttribute(
|
|
'href',
|
|
'https://example.com/blog',
|
|
);
|
|
});
|
|
|
|
test('profil: ustawienie nicku i social media w edycji (per sekcja)', async ({ page }) => {
|
|
mockApi(page, { me: { user: TEST_USER, memberships: [] } });
|
|
await login(page);
|
|
await page.getByRole('link', { name: 'Profil' }).click();
|
|
await page.getByRole('link', { name: 'Dane osobowe' }).click();
|
|
await expect(page.getByRole('heading', { name: 'Profil — dane osobowe' })).toBeVisible();
|
|
|
|
// 3 karty podglądu, każda z własnym „Edytuj”
|
|
const basicCard = page.locator('[data-slot="card"]', {
|
|
has: page.getByRole('heading', { name: 'Podstawowe dane' }),
|
|
});
|
|
const socialCard = page.locator('[data-slot="card"]', {
|
|
has: page.getByRole('heading', { name: 'Social media' }),
|
|
});
|
|
await expect(basicCard.getByRole('button', { name: 'Edytuj' })).toBeVisible();
|
|
await expect(socialCard.getByRole('button', { name: 'Edytuj' })).toBeVisible();
|
|
|
|
// nick — sekcja „Podstawowe dane”
|
|
await basicCard.getByRole('button', { name: 'Edytuj' }).click();
|
|
const basicDialog = page.getByRole('dialog');
|
|
await basicDialog.getByPlaceholder('np. fitfan').fill('fitfan');
|
|
await basicDialog.getByRole('button', { name: 'Zapisz' }).click();
|
|
await expect(page.getByText('Dane podstawowe zapisane')).toBeVisible();
|
|
// po zapisie podgląd pokazuje nick (mock /me jest stateful)
|
|
await expect(page.getByText('fitfan')).toBeVisible();
|
|
|
|
// social media — osobna sekcja z własnym zapisem
|
|
await socialCard.getByRole('button', { name: 'Edytuj' }).click();
|
|
const socialDialog = page.getByRole('dialog');
|
|
// wpis social media: domyślna platforma Instagram + URL
|
|
await socialDialog.getByRole('button', { name: 'Dodaj social media' }).click();
|
|
await socialDialog.getByPlaceholder('https://…').fill('https://instagram.com/fitfan');
|
|
|
|
// drugi wpis: platforma „Inne” z własną etykietą
|
|
await socialDialog.getByRole('button', { name: 'Dodaj social media' }).click();
|
|
const platformSelects = socialDialog.locator('select[aria-label="Platforma"]');
|
|
await platformSelects.nth(1).selectOption('OTHER');
|
|
await expect(socialDialog.getByPlaceholder('Etykieta')).toBeVisible();
|
|
await socialDialog.getByPlaceholder('Etykieta').fill('Blog');
|
|
await socialDialog.getByPlaceholder('https://…').nth(1).fill('https://example.com/blog');
|
|
|
|
await socialDialog.getByRole('button', { name: 'Zapisz' }).click();
|
|
await expect(page.getByText('Social media zapisane')).toBeVisible();
|
|
|
|
// po zapisie podgląd pokazuje linki
|
|
await expect(page.getByRole('link', { name: 'Instagram' })).toBeVisible();
|
|
await expect(page.getByRole('link', { name: 'Blog' })).toBeVisible();
|
|
});
|
|
|
|
test('podopieczni: nick na karcie i w detalu ze social media', async ({ page }) => {
|
|
mockApi(page, {
|
|
me: trainerMe(),
|
|
trainees: { trainees: [TEST_TRAINEE_NICK] },
|
|
traineeDetail: TEST_TRAINEE_DETAIL_NICK,
|
|
});
|
|
await login(page);
|
|
await page.getByRole('link', { name: 'Podopieczni' }).click();
|
|
await expect(page.getByRole('heading', { name: 'Podopieczni' })).toBeVisible();
|
|
|
|
// nick jako główna nazwa karty
|
|
await expect(page.getByRole('button', { name: 'annanowak' })).toBeVisible();
|
|
await page.getByRole('button', { name: 'annanowak' }).click();
|
|
await expect(page.getByRole('heading', { name: 'annanowak' })).toBeVisible();
|
|
|
|
// social media jako klikalne linki w detalu
|
|
const tiktok = page.getByRole('link', { name: 'TikTok' });
|
|
await expect(tiktok).toHaveAttribute('href', 'https://tiktok.com/@annanowak');
|
|
await expect(page.getByRole('link', { name: 'Blog' })).toHaveAttribute(
|
|
'href',
|
|
'https://example.com/blog',
|
|
);
|
|
});
|
|
|
|
test('komunikator: nick rozmówcy w liście i w wątku', async ({ page }) => {
|
|
mockApi(page, {
|
|
me: { user: TEST_USER, memberships: [] },
|
|
conversations: {
|
|
conversations: [
|
|
{
|
|
coachingId: 'coaching-1',
|
|
role: 'trainer',
|
|
other: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak', nickname: 'annanowak' },
|
|
lastMessage: {
|
|
body: 'Dobrze się czuję',
|
|
createdAt: '2026-08-24T10:00:00.000Z',
|
|
senderId: 'trainee-1',
|
|
},
|
|
unreadCount: 0,
|
|
},
|
|
],
|
|
},
|
|
messageThread: {
|
|
role: 'trainer',
|
|
other: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak', nickname: 'annanowak' },
|
|
messages: [
|
|
{
|
|
id: 'msg-1',
|
|
senderId: 'trainee-1',
|
|
body: 'Dobrze się czuję',
|
|
createdAt: '2026-08-24T10:00:00.000Z',
|
|
attachment: null,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
await login(page);
|
|
await page.getByRole('link', { name: 'Komunikator' }).click();
|
|
await expect(page.getByRole('heading', { name: 'Komunikator' })).toBeVisible();
|
|
|
|
// nick w liście rozmów
|
|
await expect(page.getByRole('button', { name: /annanowak/ })).toBeVisible();
|
|
await page.getByRole('button', { name: /annanowak/ }).click();
|
|
// nick jako nagłówek wątku
|
|
await expect(page.getByRole('heading', { name: 'annanowak' })).toBeVisible();
|
|
});
|
|
|
|
test('zaproszenia: nick drugiej strony', async ({ page }) => {
|
|
mockApi(page, {
|
|
me: { user: TEST_USER, memberships: [] },
|
|
invitations: {
|
|
invitations: [
|
|
{
|
|
id: 'inv-1',
|
|
direction: 'received',
|
|
other: {
|
|
id: 'trainer-1',
|
|
firstName: 'Marek',
|
|
lastName: 'Trener',
|
|
nickname: 'marekt',
|
|
email: 'marek@test.local',
|
|
phone: null,
|
|
},
|
|
invitedAt: '2026-08-20T00:00:00.000Z',
|
|
expiresAt: '2026-08-27T00:00:00.000Z',
|
|
},
|
|
],
|
|
},
|
|
});
|
|
await login(page);
|
|
await page.getByRole('link', { name: 'Zaproszenia' }).click();
|
|
await expect(page.getByRole('heading', { name: 'Zaproszenia' })).toBeVisible();
|
|
|
|
// nick zamiast imienia i nazwiska
|
|
await expect(page.getByText('marekt')).toBeVisible();
|
|
await expect(page.getByText('Marek Trener')).not.toBeVisible();
|
|
});
|