Added behavior journal, adjusted layout, and added some colors
This commit is contained in:
1 parent
b1b89ad334
commit
3237cd7601
31 files changed
+2135
-275
No files matched your search
@@ -0,0 +1,138 @@
|
||||
// Optional browser check. Requires Playwright in a disposable frontend install; see docs/BEHAVIOR_JOURNAL.md.
|
||||
import assert from 'node:assert/strict';
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { once } from 'node:events';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { chromium } from 'playwright';
|
||||
Object.assign(process.env, {
|
||||
POSTGRES_HOST: '127.0.0.1', POSTGRES_PORT: '55439', POSTGRES_DB: 'behavior_test', POSTGRES_USER: 'postgres',
|
||||
POSTGRES_PASSWORD: 'behavior_test_only', PORT: '55440', FRONTEND_URL: 'http://127.0.0.1:55441',
|
||||
VITE_API_BASE_URL: 'http://127.0.0.1:55440/api',
|
||||
MILESTONE_REMINDERS_ENABLED: 'false', MEDICATION_REMINDERS_ENABLED: 'false', WEIGHT_REMINDERS_ENABLED: 'false',
|
||||
});
|
||||
const { db } = await import('../../backend/dist/db/client.js');
|
||||
const children = [];
|
||||
let browser;
|
||||
let page;
|
||||
async function start(path, args, marker) {
|
||||
let output = '';
|
||||
const child = spawn(process.execPath, [fileURLToPath(path), ...args], { cwd: fileURLToPath(new URL('../', import.meta.url)), env: process.env, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
children.push(child);
|
||||
child.stdout.on('data', (data) => { output += data; }); child.stderr.on('data', (data) => { output += data; });
|
||||
for (let i = 0; i < 100 && !output.includes(marker); i++) await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
assert.ok(output.includes(marker), output);
|
||||
}
|
||||
try {
|
||||
const workspace = 100000 + Math.floor(Math.random() * 1000000000);
|
||||
const user = randomUUID(), bird = randomUUID(), secondBird = randomUUID(), token = randomUUID();
|
||||
await db.query(`INSERT INTO workspaces (id, name, workspace_type, rescue_verification_status) VALUES ($1, 'Browser test', 'rescue', 'approved')`, [workspace]);
|
||||
await db.query(`INSERT INTO users (id, email, name, education_opt_out) VALUES ($1, $2, 'Browser tester', TRUE)`, [user, `${user}@example.test`]);
|
||||
await db.query(`INSERT INTO workspace_members (workspace_id, user_id, invite_email, name, role, accepted_at) VALUES ($1, $2, $3, 'Browser tester', 'owner', NOW())`, [workspace, user, `${user}@example.test`]);
|
||||
await db.query(`INSERT INTO auth_sessions (user_id, active_workspace_id, token_hash, expires_at) VALUES ($1, $2, $3, NOW() + INTERVAL '1 hour')`, [user, workspace, createHash('sha256').update(token).digest('hex')]);
|
||||
await db.query(`INSERT INTO birds (id, workspace_id, name, species) VALUES ($1, $2, 'Piper', 'Parrot'), ($3, $2, 'Willow', 'Parrot')`, [bird, workspace, secondBird]);
|
||||
const type = (await db.query(`SELECT id FROM behavior_types WHERE is_default ORDER BY name LIMIT 1`)).rows[0].id;
|
||||
for (const timestamp of ['2026-10-01T03:59:59Z', '2026-10-01T04:00:00Z', '2026-11-01T05:30:00Z', '2026-11-01T06:30:00Z']) {
|
||||
await db.query(`INSERT INTO behavior_occurrences (bird_id, behavior_type_id, occurred_at) VALUES ($1, $2, $3)`, [bird, type, timestamp]);
|
||||
}
|
||||
await start(new URL('../../backend/dist/app.js', import.meta.url), [], 'listening');
|
||||
await start(new URL('../node_modules/vite/bin/vite.js', import.meta.url), ['--host', '127.0.0.1', '--port', '55441'], 'Local:');
|
||||
browser = await chromium.launch({ headless: true });
|
||||
const context = await browser.newContext({ timezoneId: 'America/New_York', viewport: { width: 1280, height: 1000 } });
|
||||
page = await context.newPage();
|
||||
const errors = []; page.on('pageerror', (e) => errors.push(e.message));
|
||||
await page.addInitScript((value) => localStorage.setItem('flockpal_auth_token', value), token);
|
||||
await page.clock.setFixedTime(new Date('2026-10-05T16:00:00Z'));
|
||||
await page.goto('http://127.0.0.1:55441');
|
||||
await page.getByRole('button', { name: 'Flock', exact: true }).click();
|
||||
await page.locator('.bird-card-select').filter({ hasText: 'Piper' }).click();
|
||||
await page.getByRole('tab', { name: 'Behavior Journal' }).click();
|
||||
const journal = page.getByRole('tabpanel', { name: 'Behavior Journal' });
|
||||
await journal.getByText('1 occurrence this month', { exact: true }).waitFor();
|
||||
await journal.getByRole('button', { name: 'Record behavior' }).click();
|
||||
assert.match(await journal.getByLabel('Date and time', { exact: true }).inputValue(), /^2026-10-05T12:00(:00)?$/);
|
||||
await journal.getByLabel('Behavior', { exact: true }).selectOption('custom');
|
||||
await journal.getByLabel('Custom behavior name').fill('Wing stretching');
|
||||
await journal.getByLabel('Description (optional)').fill('Wings extended');
|
||||
await journal.getByLabel('Date and time', { exact: true }).fill('2026-10-05T23:30:12');
|
||||
await journal.getByLabel('Duration in seconds (optional)').fill('90');
|
||||
await journal.getByLabel('Intensity (optional)').selectOption('3');
|
||||
await journal.getByLabel('Notes (optional)').fill('Observed after play');
|
||||
await journal.getByRole('button', { name: 'Save occurrence' }).click();
|
||||
await journal.getByText('Occurrence saved.', { exact: true }).waitFor();
|
||||
await journal.getByRole('button', { name: 'Record behavior' }).click();
|
||||
await journal.getByLabel('Behavior', { exact: true }).selectOption({ label: 'Wing stretching' });
|
||||
await journal.getByLabel('Date and time', { exact: true }).fill('2026-10-05T22:00');
|
||||
await journal.getByRole('button', { name: 'Save occurrence' }).click();
|
||||
await journal.getByText('3 occurrences this month', { exact: true }).waitFor();
|
||||
const day = journal.getByRole('button', { name: '10/5/2026: 2 occurrences', exact: true });
|
||||
await day.click(); assert.equal(await journal.locator('details').count(), 2);
|
||||
const entry = journal.locator('details').filter({ hasText: 'Observed after play' });
|
||||
await entry.locator('summary').click();
|
||||
await entry.getByRole('button', { name: 'Edit', exact: true }).click();
|
||||
await journal.getByLabel('Notes (optional)').fill('Edited observation');
|
||||
await journal.getByRole('button', { name: 'Save occurrence' }).click();
|
||||
await journal.getByText('Edited observation', { exact: true }).first().waitFor();
|
||||
await journal.getByLabel('Show behavior', { exact: true }).selectOption({ label: 'Wing stretching' });
|
||||
await journal.getByText('2 occurrences this month', { exact: true }).waitFor();
|
||||
await journal.getByRole('button', { name: 'Next month' }).click();
|
||||
await journal.getByText('0 occurrences this month', { exact: true }).waitFor();
|
||||
await journal.getByLabel('Show behavior', { exact: true }).selectOption('');
|
||||
await journal.getByText('2 occurrences this month', { exact: true }).waitFor();
|
||||
await journal.getByRole('button', { name: '11/1/2026: 2 occurrences', exact: true }).click();
|
||||
assert.equal(await journal.locator('details').count(), 2); // Both sides of fall-back belong to Nov 1.
|
||||
await journal.locator('details').first().locator('summary').click();
|
||||
await journal.locator('details').first().getByRole('button', { name: 'Edit', exact: true }).click();
|
||||
await journal.getByLabel('Notes (optional)').fill('Later repeated hour retained');
|
||||
await journal.getByRole('button', { name: 'Save occurrence' }).click();
|
||||
await journal.getByText('Occurrence saved.', { exact: true }).waitFor();
|
||||
const repeated = (await db.query(`SELECT occurred_at FROM behavior_occurrences WHERE bird_id = $1 AND notes = 'Later repeated hour retained'`, [bird])).rows[0];
|
||||
assert.equal(repeated.occurred_at.toISOString(), '2026-11-01T06:30:00.000Z');
|
||||
|
||||
await journal.getByRole('button', { name: 'Previous month' }).click();
|
||||
await journal.getByRole('button', { name: 'Previous month' }).click();
|
||||
await journal.getByText('1 occurrence this month', { exact: true }).waitFor(); // UTC Oct 1 before local midnight.
|
||||
await journal.getByRole('button', { name: 'Next month' }).click();
|
||||
await journal.getByRole('button', { name: '10/5/2026: 2 occurrences', exact: true }).click();
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await journal.scrollIntoViewIfNeeded();
|
||||
await page.screenshot({ path: '/tmp/flockpal-behavior-mobile.png', fullPage: true });
|
||||
assert.equal(await journal.evaluate((element) => element.scrollWidth <= element.clientWidth + 1), true, 'Journal must fit mobile width');
|
||||
const editedEntry = journal.locator('details').filter({ hasText: 'Edited observation' });
|
||||
await editedEntry.locator('summary').click();
|
||||
page.once('dialog', (dialog) => dialog.accept());
|
||||
await editedEntry.getByRole('button', { name: 'Delete', exact: true }).click();
|
||||
await journal.getByText('Occurrence deleted.', { exact: true }).waitFor();
|
||||
await journal.getByRole('button', { name: '10/5/2026: 1 occurrences', exact: true }).waitFor();
|
||||
await journal.getByLabel('Bird', { exact: true }).selectOption(secondBird);
|
||||
await journal.getByText('0 occurrences this month', { exact: true }).waitFor();
|
||||
await journal.getByLabel('Bird', { exact: true }).selectOption(bird);
|
||||
await journal.getByText('2 occurrences this month', { exact: true }).waitFor();
|
||||
await page.setViewportSize({ width: 1280, height: 1000 });
|
||||
await journal.scrollIntoViewIfNeeded();
|
||||
await page.screenshot({ path: '/tmp/flockpal-behavior-desktop.png', fullPage: true });
|
||||
const utcContext = await browser.newContext({ timezoneId: 'UTC', viewport: { width: 1280, height: 1000 } });
|
||||
const utcPage = await utcContext.newPage();
|
||||
await utcPage.addInitScript((value) => localStorage.setItem('flockpal_auth_token', value), token);
|
||||
await utcPage.clock.setFixedTime(new Date('2026-10-05T16:00:00Z'));
|
||||
await utcPage.goto('http://127.0.0.1:55441');
|
||||
await utcPage.getByRole('button', { name: 'Flock', exact: true }).click();
|
||||
await utcPage.locator('.bird-card-select').filter({ hasText: 'Piper' }).click();
|
||||
await utcPage.getByRole('tab', { name: 'Behavior Journal' }).click();
|
||||
const utcJournal = utcPage.getByRole('tabpanel', { name: 'Behavior Journal' });
|
||||
await utcJournal.getByText('3 occurrences this month', { exact: true }).waitFor();
|
||||
await utcJournal.getByRole('button', { name: '10/1/2026: 2 occurrences', exact: true }).waitFor();
|
||||
await utcContext.close();
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('PASS: browser create/custom type/edit/delete, bird/behavior filters, month navigation, multiple events/day, local midnight and DST, and mobile layout.');
|
||||
} catch (error) {
|
||||
if (page) {
|
||||
console.error(await page.locator('.behavior-journal').innerText().catch(() => 'Journal unavailable'));
|
||||
await page.screenshot({ path: '/tmp/flockpal-behavior-failure.png', fullPage: true });
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
if (browser) await browser.close();
|
||||
for (const child of children.reverse()) if (child.exitCode === null) { const done = once(child, 'exit'); child.kill('SIGTERM'); await done; }
|
||||
await db.close();
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// Optional browser integration check; use the disposable setup in docs/BIRD_MEMBERSHIP.md.
|
||||
import assert from 'node:assert/strict';
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { once } from 'node:events';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { chromium } from 'playwright';
|
||||
Object.assign(process.env, {
|
||||
POSTGRES_HOST: '127.0.0.1', POSTGRES_PORT: '55439', POSTGRES_DB: 'behavior_test', POSTGRES_USER: 'postgres',
|
||||
POSTGRES_PASSWORD: 'behavior_test_only', PORT: '55440', FRONTEND_URL: 'http://127.0.0.1:55441',
|
||||
VITE_API_BASE_URL: 'http://127.0.0.1:55440/api',
|
||||
MILESTONE_REMINDERS_ENABLED: 'false', MEDICATION_REMINDERS_ENABLED: 'false', WEIGHT_REMINDERS_ENABLED: 'false',
|
||||
});
|
||||
const { db } = await import('../../backend/dist/db/client.js');
|
||||
const children = [];
|
||||
let browser;
|
||||
async function start(path, args, marker) {
|
||||
let output = '';
|
||||
const child = spawn(process.execPath, [fileURLToPath(path), ...args], { cwd: fileURLToPath(new URL('../', import.meta.url)), env: process.env, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
children.push(child);
|
||||
child.stdout.on('data', (data) => { output += data; }); child.stderr.on('data', (data) => { output += data; });
|
||||
for (let i = 0; i < 100 && !output.includes(marker); i++) await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
assert.ok(output.includes(marker), output);
|
||||
}
|
||||
try {
|
||||
const accounts = [];
|
||||
const baseId = 100000 + Math.floor(Math.random() * 1000000000);
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const workspace = baseId + i, user = randomUUID(), token = randomUUID(), email = `${user}@example.test`;
|
||||
await db.query(`INSERT INTO workspaces (id, name, workspace_type, rescue_verification_status) VALUES ($1, $2, 'rescue', 'approved')`, [workspace, `Browser membership ${i}`]);
|
||||
await db.query(`INSERT INTO users (id, email, name, education_opt_out) VALUES ($1, $2, 'Browser tester', TRUE)`, [user, email]);
|
||||
await db.query(`INSERT INTO workspace_members (workspace_id, user_id, invite_email, name, role, accepted_at) VALUES ($1, $2, $3, 'Browser tester', 'owner', NOW())`, [workspace, user, email]);
|
||||
await db.query(`INSERT INTO auth_sessions (user_id, active_workspace_id, token_hash, expires_at) VALUES ($1, $2, $3, NOW() + INTERVAL '1 hour')`, [user, workspace, createHash('sha256').update(token).digest('hex')]);
|
||||
accounts.push({ workspace, token });
|
||||
}
|
||||
const [source, destination] = accounts;
|
||||
const bird = randomUUID(), tagId = `FP-${randomUUID()}`;
|
||||
await db.query(`INSERT INTO birds (id, workspace_id, name, tag_id, species) VALUES ($1, $2, 'Piper', $3, 'Parrot')`, [bird, source.workspace, tagId]);
|
||||
await db.query(`INSERT INTO weight_records (bird_id, weight_grams, recorded_on) VALUES ($1, 120, CURRENT_DATE)`, [bird]);
|
||||
await db.query(`INSERT INTO flock_notes (workspace_id, bird_id, title, body) VALUES ($1, $2, 'Existing note', 'Enjoys morning play')`, [source.workspace, bird]);
|
||||
await start(new URL('../../backend/dist/app.js', import.meta.url), [], 'listening');
|
||||
await start(new URL('../node_modules/vite/bin/vite.js', import.meta.url), ['--host', '127.0.0.1', '--port', '55441'], 'Local:');
|
||||
browser = await chromium.launch({ headless: true });
|
||||
const sourcePage = await browser.newPage({ viewport: { width: 1280, height: 1000 } });
|
||||
await sourcePage.addInitScript((value) => localStorage.setItem('flockpal_auth_token', value), source.token);
|
||||
await sourcePage.goto('http://127.0.0.1:55441', { waitUntil: 'domcontentloaded' });
|
||||
await sourcePage.getByRole('button', { name: 'Flock', exact: true }).click();
|
||||
await sourcePage.locator('.bird-card-select').filter({ hasText: 'Piper' }).click();
|
||||
await sourcePage.getByRole('button', { name: 'Edit details for Piper' }).click();
|
||||
sourcePage.once('dialog', async (dialog) => { assert.match(dialog.message(), /history will be retained/); await dialog.accept(); });
|
||||
await sourcePage.getByRole('button', { name: 'Remove from flock', exact: true }).click();
|
||||
await sourcePage.locator('.bird-card-select').filter({ hasText: 'Piper' }).waitFor({ state: 'detached' });
|
||||
assert.equal((await db.query(`SELECT workspace_id FROM birds WHERE id = $1`, [bird])).rows[0].workspace_id, null);
|
||||
const page = await browser.newPage({ viewport: { width: 390, height: 844 } });
|
||||
const pageErrors = []; page.on('pageerror', (error) => pageErrors.push(error.message));
|
||||
await page.addInitScript((value) => localStorage.setItem('flockpal_auth_token', value), destination.token);
|
||||
await page.goto('http://127.0.0.1:55441', { waitUntil: 'domcontentloaded' });
|
||||
await page.getByRole('button', { name: 'Flock', exact: true }).click();
|
||||
await page.getByRole('button', { name: 'Add bird', exact: true }).click();
|
||||
const bandInput = page.getByLabel('Band ID, if known', { exact: true });
|
||||
await bandInput.fill(tagId.slice(0, -1));
|
||||
await page.getByText('Checking band ID for existing history…').waitFor({ state: 'hidden' });
|
||||
assert.equal(await page.getByRole('button', { name: 'Add bird with existing history' }).count(), 0);
|
||||
await bandInput.fill(` ${tagId.toLowerCase()} `);
|
||||
const claimButton = page.getByRole('button', { name: 'Add bird with existing history' });
|
||||
await claimButton.waitFor();
|
||||
assert.equal(await page.getByRole('button', { name: 'Save bird profile', exact: true }).isDisabled(), true);
|
||||
const notice = page.getByRole('status').filter({ hasText: 'This band ID matches' });
|
||||
assert.equal(await notice.evaluate((element) => element.scrollWidth <= element.clientWidth), true);
|
||||
await notice.screenshot({ path: '/tmp/flockpal-existing-history-notice.png' });
|
||||
page.once('dialog', async (dialog) => { assert.match(dialog.message(), /history will be brought in/); await dialog.dismiss(); });
|
||||
await claimButton.click();
|
||||
assert.equal((await db.query(`SELECT workspace_id FROM birds WHERE id = $1`, [bird])).rows[0].workspace_id, null);
|
||||
// Only a band ID is needed: no replacement name or species should be required to claim history.
|
||||
assert.equal(await page.getByLabel('Bird name', { exact: true }).inputValue(), '');
|
||||
page.on('dialog', (dialog) => dialog.accept());
|
||||
await claimButton.click();
|
||||
await page.getByRole('tab', { name: 'Weight', exact: true }).waitFor();
|
||||
assert.equal((await db.query(`SELECT workspace_id FROM birds WHERE id = $1`, [bird])).rows[0].workspace_id, destination.workspace);
|
||||
assert.equal((await db.query(`SELECT COUNT(*)::int AS count FROM birds WHERE LOWER(tag_id) = LOWER($1)`, [tagId])).rows[0].count, 1);
|
||||
await page.getByRole('tab', { name: 'Notes', exact: true }).click();
|
||||
await page.getByText('Enjoys morning play', { exact: true }).waitFor();
|
||||
await page.getByRole('tab', { name: 'Timeline', exact: true }).click();
|
||||
await page.getByText('Joined flock with history', { exact: true }).first().waitFor();
|
||||
assert.deepEqual(pageErrors, []);
|
||||
console.log('PASS: desktop removal retains history; mobile exact band match notice, cancellation, confirmation, claim without replacement fields, and restored notes/timeline.');
|
||||
} finally {
|
||||
if (browser) await browser.close();
|
||||
for (const child of children.reverse()) if (child.exitCode === null) { const done = once(child, 'exit'); child.kill('SIGTERM'); await done; }
|
||||
await db.close();
|
||||
}
|
||||
Reference in new issue
Block a user