mascarpone/e2e/pages/journal.spec.ts

141 lines
6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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');
let load = page.waitForResponse('/journal_entry');
await page.getByRole('button', { name: /add entry/i }).click();
await load;
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]]');
let load = page.waitForResponse('/journal_entry');
await page.getByRole('button', { name: /add entry/i }).click();
await load;
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]]');
let load = page.waitForResponse('/journal_entry');
await page.getByRole('button', { name: /add entry/i }).click();
await load;
const nav = page.getByRole('navigation');
const journal = page.locator('#journal');
await expect.soft(journal.getByRole('link', { name: 'JC' })).toHaveCount(0);
// add a new name
if (await page.locator('#sidebar-show-hide').isVisible()) {
await page.locator('#sidebar-show-hide').click();
}
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' }).nth(1).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);
// delete an existing name
if (await page.locator('#sidebar-show-hide').isVisible()) {
await page.locator('#sidebar-show-hide').click();
}
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...
if (await page.locator('#sidebar-show-hide').isVisible()) {
await page.locator('#sidebar-show-hide').click();
}
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' }).nth(1).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
if (await page.locator('#sidebar-show-hide').isVisible()) {
await page.locator('#sidebar-show-hide').click();
}
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' }).nth(1).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
if (await page.locator('#sidebar-show-hide').isVisible()) {
await page.locator('#sidebar-show-hide').click();
}
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");
let load = page.waitForResponse('/journal_entry');
await page.getByRole('button', { name: /add entry/i }).click();
await load;
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');
let load = page.waitForResponse('/journal_entry');
await page.getByRole('button', { name: /add entry/i }).click();
await load;
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);
});