mascarpone/e2e/pages/journal.spec.ts

118 lines
5.1 KiB
TypeScript
Raw Normal View History

2025-11-27 13:45:21 -06:00
import { test, expect } from '@playwright/test';
import { login, verifyCreateUser, todate } from './util';
test('can add journal entries', async ({ page }) => {
await login(page);
const entryBox = page.getByPlaceholder(/new entry/i);
await entryBox.fill('banana banana banana');
await page.getByRole('button', { name: /add entry/i }).click();
await expect(entryBox).toBeEmpty();
await expect(page.getByText('banana banana banana')).toBeVisible();
});
test('journal entries autolink', async ({ page }) => {
await login(page);
await verifyCreateUser(page, { names: ['John Contact'] });
await page.getByRole('link', { name: 'Mascarpone' }).click();
await page.getByPlaceholder(/new entry/i).fill('met with [[John Contact]]');
await page.getByRole('button', { name: /add entry/i }).click();
await expect(page.locator('#journal').getByRole('link', { name: 'John Contact' })).toBeVisible();
});
test("changing a contact's names updates journal entries", async ({ page }) => {
await login(page);
await verifyCreateUser(page, { names: ['John Contact'] });
await verifyCreateUser(page, { names: ['Jack Contact'] });
await page.getByPlaceholder(/new entry/i).fill('met with [[JC]]');
await page.getByRole('button', { name: /add entry/i }).click();
const nav = page.getByRole('navigation');
const journal = page.locator('#journal');
await expect.soft(journal.getByRole('link', { name: 'JC' })).toHaveCount(0);
// add a new name
await nav.getByRole("link", { name: 'John Contact' }).click();
await page.getByRole('link', { name: /edit/i }).click();
await page.getByRole('textbox', { name: 'New name' }).fill('JC');
await page.getByRole('button', { name: 'Add', exact: true }).click();
await page.getByRole('button', { name: /save/i }).click();
await page.getByRole('link', { name: 'Mascarpone' }).click();
console.log(await journal.innerHTML());
await expect.soft(journal.getByRole('link', { name: 'JC' })).toHaveCount(1);
// delete an existing name
await nav.getByRole("link", { name: 'John Contact' }).click();
await page.getByRole('link', { name: /edit/i }).click();
await page.getByRole('button', { name: '×', disabled: false }).click();
await page.getByRole('button', { name: /save/i }).click();
await page.getByRole('link', { name: 'Mascarpone' }).click();
await expect.soft(journal.getByRole('link', { name: 'JC' })).toHaveCount(0);
// put it back, then...
await nav.getByRole("link", { name: 'John Contact' }).click();
await page.getByRole('link', { name: /edit/i }).click();
await page.getByRole('textbox', { name: 'New name' }).fill('JC');
await page.getByRole('button', { name: 'Add', exact: true }).click();
await page.getByRole('button', { name: /save/i }).click();
await page.getByRole('link', { name: 'Mascarpone' }).click();
await expect.soft(journal.getByRole('link', { name: 'JC' })).toHaveCount(1);
// ...add a name that makes it no longer n=1
await nav.getByRole("link", { name: 'Jack Contact' }).click();
await page.getByRole('link', { name: /edit/i }).click();
await page.getByRole('textbox', { name: 'New name' }).fill('JC');
await page.getByRole('button', { name: 'Add', exact: true }).click();
await page.getByRole('button', { name: /save/i }).click();
await expect.soft(journal.getByRole('link', { name: 'JC' })).toHaveCount(0);
// delete a name that makes it now n=1
await nav.getByRole("link", { name: 'John Contact' }).click();
await page.getByRole('link', { name: /edit/i }).click();
await page.getByRole('button', { name: '×', disabled: false }).click();
await page.getByRole('button', { name: /save/i }).click();
await page.getByRole('link', { name: 'Mascarpone' }).click();
await expect.soft(journal.getByRole('link', { name: 'JC' })).toHaveCount(1);
});
test('can edit existing journal entries on home page', async ({ page }) => {
await login(page);
await verifyCreateUser(page, { names: ['John Contact'] });
await page.getByRole('link', { name: 'Mascarpone' }).click();
await page.getByPlaceholder(/new entry/i).fill("[[John Contact]]'s banana banana banana");
await page.getByRole('button', { name: /add entry/i }).click();
await page.reload();
await page.getByRole('checkbox', { name: /edit/i }).click();
const textbox = page.locator('form').filter({
has: page.getByRole('button', { name: '✓' })
}).locator('textarea');
await textbox.fill('met with [[John Contact]]');
await page.getByRole('button', { name: '✓' }).click();
await page.getByRole('checkbox', { name: /edit/i }).click();
await expect(page.locator('#journal').getByRole('link', { name: 'John Contact' })).toHaveCount(1);
});
test('can have multiple links', async ({ page }) => {
await login(page);
await verifyCreateUser(page, { names: ['alice'] });
await verifyCreateUser(page, { names: ['bob'] });
await page.getByRole('link', { name: 'Mascarpone' }).click();
await page.getByPlaceholder(/new entry/i).fill('met with [[alice]] and [[bob]] and their kids');
await page.getByRole('button', { name: /add entry/i }).click();
const journal = page.locator('#journal');
await expect.soft(journal.getByRole('link', { name: 'alice' })).toHaveCount(1);
await expect.soft(journal.getByRole('link', { name: 'bob' })).toHaveCount(1);
});