feat: implement home board for upcoming shifts and events
Introduced a new home board feature that displays shifts needing volunteers and upcoming events for the next two weeks. Updated the admin interface to show relevant shift details, including capacity and occupancy. Enhanced data fetching to support this feature and modified related components for better user experience. Added tests to ensure functionality works as expected.
This commit is contained in:
1 parent
bf661673c9
commit
7cfb984d63
7 files changed
+1962
-381
No files matched your search
+1174
File diff suppressed because it is too large.
Load diff
+48
-15
@@ -19,6 +19,10 @@
|
|||||||
return document.querySelectorAll('input[data-pick="' + name + '"]:checked');
|
return document.querySelectorAll('input[data-pick="' + name + '"]:checked');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var boxesFor = function (name) {
|
||||||
|
return document.querySelectorAll('input[data-pick="' + name + '"]');
|
||||||
|
};
|
||||||
|
|
||||||
var fill = function (link) {
|
var fill = function (link) {
|
||||||
form.querySelectorAll('[data-picked]').forEach(function (input) {
|
form.querySelectorAll('[data-picked]').forEach(function (input) {
|
||||||
input.remove();
|
input.remove();
|
||||||
@@ -44,21 +48,47 @@
|
|||||||
var pick = link.getAttribute('data-confirm-pick');
|
var pick = link.getAttribute('data-confirm-pick');
|
||||||
if (!pick) return;
|
if (!pick) return;
|
||||||
var chosen = chosenFor(pick);
|
var chosen = chosenFor(pick);
|
||||||
|
var kept = [];
|
||||||
|
var blocked = 0;
|
||||||
var weekly = false;
|
var weekly = false;
|
||||||
chosen.forEach(function (box) {
|
chosen.forEach(function (box) {
|
||||||
var input = document.createElement('input');
|
if (box.getAttribute('data-removable') === 'false') {
|
||||||
input.type = 'hidden';
|
blocked += 1;
|
||||||
input.name = pick + '[]';
|
return;
|
||||||
input.value = box.value;
|
}
|
||||||
input.setAttribute('data-picked', '');
|
kept.push(box);
|
||||||
form.appendChild(input);
|
|
||||||
if (box.getAttribute('data-weekly') === 'true') weekly = true;
|
if (box.getAttribute('data-weekly') === 'true') weekly = true;
|
||||||
});
|
});
|
||||||
detail.textContent = chosen.length === 1 ? '1 selected' : chosen.length + ' selected';
|
|
||||||
detail.hidden = false;
|
|
||||||
var weeklyNote = text(link, 'data-confirm-note-weekly');
|
var weeklyNote = text(link, 'data-confirm-note-weekly');
|
||||||
if (weekly && weeklyNote) {
|
var notes = [];
|
||||||
note.textContent = weeklyNote;
|
if (kept.length === 0 && blocked > 0) {
|
||||||
|
body.textContent = 'Cancel this shift, or wait until it has ended, before removing it.';
|
||||||
|
submit.hidden = true;
|
||||||
|
submit.disabled = true;
|
||||||
|
cancel.textContent = 'Close';
|
||||||
|
chosen.forEach(function (box) {
|
||||||
|
if (box.getAttribute('data-weekly') === 'true') weekly = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
kept.forEach(function (box) {
|
||||||
|
var input = document.createElement('input');
|
||||||
|
input.type = 'hidden';
|
||||||
|
input.name = pick + '[]';
|
||||||
|
input.value = box.value;
|
||||||
|
input.setAttribute('data-picked', '');
|
||||||
|
form.appendChild(input);
|
||||||
|
});
|
||||||
|
if (blocked > 0) notes.push('The others stay until they are cancelled or have ended.');
|
||||||
|
}
|
||||||
|
if (blocked > 0 && kept.length > 0) {
|
||||||
|
detail.textContent = kept.length + ' of ' + chosen.length + ' can be removed';
|
||||||
|
} else {
|
||||||
|
detail.textContent = chosen.length === 1 ? '1 selected' : chosen.length + ' selected';
|
||||||
|
}
|
||||||
|
detail.hidden = false;
|
||||||
|
if (weekly && weeklyNote) notes.push(weeklyNote);
|
||||||
|
if (notes.length > 0) {
|
||||||
|
note.textContent = notes.join(' ');
|
||||||
note.hidden = false;
|
note.hidden = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -79,10 +109,13 @@
|
|||||||
document.querySelectorAll('[data-pick-all]').forEach(function (all) {
|
document.querySelectorAll('[data-pick-all]').forEach(function (all) {
|
||||||
var name = all.getAttribute('data-pick-all');
|
var name = all.getAttribute('data-pick-all');
|
||||||
if (!name) return;
|
if (!name) return;
|
||||||
var boxes = document.querySelectorAll('input[data-pick="' + name + '"]');
|
var boxes = boxesFor(name);
|
||||||
var checked = chosenFor(name);
|
var checked = 0;
|
||||||
all.checked = boxes.length > 0 && checked.length === boxes.length;
|
boxes.forEach(function (box) {
|
||||||
all.indeterminate = checked.length > 0 && checked.length < boxes.length;
|
if (box.checked) checked += 1;
|
||||||
|
});
|
||||||
|
all.checked = boxes.length > 0 && checked === boxes.length;
|
||||||
|
all.indeterminate = checked > 0 && checked < boxes.length;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,7 +138,7 @@
|
|||||||
var name = all.getAttribute('data-pick-all');
|
var name = all.getAttribute('data-pick-all');
|
||||||
if (!name) return;
|
if (!name) return;
|
||||||
var checked = all.checked;
|
var checked = all.checked;
|
||||||
document.querySelectorAll('input[data-pick="' + name + '"]').forEach(function (box) {
|
boxesFor(name).forEach(function (box) {
|
||||||
box.checked = checked;
|
box.checked = checked;
|
||||||
});
|
});
|
||||||
syncPicks();
|
syncPicks();
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
(function () {
|
||||||
|
var form = document.querySelector('[data-export-range]');
|
||||||
|
if (!form) return;
|
||||||
|
var from = form.querySelector('input[name="from"]');
|
||||||
|
var to = form.querySelector('input[name="to"]');
|
||||||
|
var buttons = form.querySelectorAll('[data-range]');
|
||||||
|
if (!from || !to) return;
|
||||||
|
|
||||||
|
var select = function (name) {
|
||||||
|
buttons.forEach(function (button) {
|
||||||
|
button.setAttribute('aria-pressed', button.getAttribute('data-range') === name ? 'true' : 'false');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
buttons.forEach(function (button) {
|
||||||
|
button.addEventListener('click', function () {
|
||||||
|
var name = button.getAttribute('data-range');
|
||||||
|
if (name === 'this' || name === 'last') {
|
||||||
|
from.value = button.getAttribute('data-from') || '';
|
||||||
|
to.value = button.getAttribute('data-to') || '';
|
||||||
|
}
|
||||||
|
select(name || 'custom');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var markCustom = function () {
|
||||||
|
select('custom');
|
||||||
|
};
|
||||||
|
from.addEventListener('input', markCustom);
|
||||||
|
to.addEventListener('input', markCustom);
|
||||||
|
})();
|
||||||
+17
-6
@@ -32,7 +32,7 @@ import {
|
|||||||
getAdminEvent,
|
getAdminEvent,
|
||||||
getAdminShift,
|
getAdminShift,
|
||||||
getAdminTemplate,
|
getAdminTemplate,
|
||||||
listAdminEvents,
|
listHomeBoard,
|
||||||
readEventRemoval,
|
readEventRemoval,
|
||||||
readShiftRemoval,
|
readShiftRemoval,
|
||||||
readSignupRemoval,
|
readSignupRemoval,
|
||||||
@@ -285,7 +285,9 @@ function showHome(
|
|||||||
const session = requireSession(c, services);
|
const session = requireSession(c, services);
|
||||||
if (session instanceof Response) return session;
|
if (session instanceof Response) return session;
|
||||||
const notice = knownNotice(c.req.query('notice'));
|
const notice = knownNotice(c.req.query('notice'));
|
||||||
const backup = describeBackup(backupDirectory(services.config.dataDir), services.now());
|
const now = services.now();
|
||||||
|
const backup = describeBackup(backupDirectory(services.config.dataDir), now);
|
||||||
|
const board = listHomeBoard(services.db, now, services.config.defaultTimeZone);
|
||||||
return html(
|
return html(
|
||||||
c,
|
c,
|
||||||
services,
|
services,
|
||||||
@@ -293,7 +295,9 @@ function showHome(
|
|||||||
<AdminHome
|
<AdminHome
|
||||||
config={services.config}
|
config={services.config}
|
||||||
name={session.name}
|
name={session.name}
|
||||||
events={listAdminEvents(services.db)}
|
events={board.events}
|
||||||
|
shifts={board.shifts}
|
||||||
|
now={now}
|
||||||
csrf={session.csrf}
|
csrf={session.csrf}
|
||||||
notice={notice}
|
notice={notice}
|
||||||
exportFrom={range?.from}
|
exportFrom={range?.from}
|
||||||
@@ -779,6 +783,7 @@ function showNewTemplate(c: Context, services: AdminServices, values?: TemplateV
|
|||||||
csrf={session.csrf}
|
csrf={session.csrf}
|
||||||
values={values ?? blankTemplate(localToday(event.tz, services.now()))}
|
values={values ?? blankTemplate(localToday(event.tz, services.now()))}
|
||||||
eventId={event.id}
|
eventId={event.id}
|
||||||
|
eventTitle={event.title}
|
||||||
error={error}
|
error={error}
|
||||||
submitLabel="Save template"
|
submitLabel="Save template"
|
||||||
/>,
|
/>,
|
||||||
@@ -806,8 +811,9 @@ function showTemplate(c: Context, services: AdminServices, values?: TemplateValu
|
|||||||
const session = requireSession(c, services);
|
const session = requireSession(c, services);
|
||||||
if (session instanceof Response) return session;
|
if (session instanceof Response) return session;
|
||||||
const eventId = idFrom(c);
|
const eventId = idFrom(c);
|
||||||
|
const event = getAdminEvent(services.db, eventId);
|
||||||
const template = getAdminTemplate(services.db, eventId, templateIdFrom(c));
|
const template = getAdminTemplate(services.db, eventId, templateIdFrom(c));
|
||||||
if (!template) return missing(c, services);
|
if (!event || !template) return missing(c, services);
|
||||||
return html(
|
return html(
|
||||||
c,
|
c,
|
||||||
services,
|
services,
|
||||||
@@ -829,6 +835,7 @@ function showTemplate(c: Context, services: AdminServices, values?: TemplateValu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
eventId={eventId}
|
eventId={eventId}
|
||||||
|
eventTitle={event.title}
|
||||||
ended={!template.active}
|
ended={!template.active}
|
||||||
error={error}
|
error={error}
|
||||||
submitLabel="Save template"
|
submitLabel="Save template"
|
||||||
@@ -1104,6 +1111,8 @@ function showNewShift(c: Context, services: AdminServices, values?: ShiftValues,
|
|||||||
action={appPath(services.config, `/admin/events/${event.id}/shifts`)}
|
action={appPath(services.config, `/admin/events/${event.id}/shifts`)}
|
||||||
csrf={session.csrf}
|
csrf={session.csrf}
|
||||||
values={values ?? { role: '', date: '', start: '09:00', end: '12:00', capacity: '1' }}
|
values={values ?? { role: '', date: '', start: '09:00', end: '12:00', capacity: '1' }}
|
||||||
|
eventId={event.id}
|
||||||
|
eventTitle={event.title}
|
||||||
error={error}
|
error={error}
|
||||||
submitLabel="Create shift"
|
submitLabel="Create shift"
|
||||||
/>,
|
/>,
|
||||||
@@ -1135,6 +1144,7 @@ function showShift(
|
|||||||
walkIn?: WalkInState,
|
walkIn?: WalkInState,
|
||||||
shiftId = idFrom(c),
|
shiftId = idFrom(c),
|
||||||
confirm?: ConfirmPrompt,
|
confirm?: ConfirmPrompt,
|
||||||
|
editError?: string,
|
||||||
) {
|
) {
|
||||||
const session = requireSession(c, services);
|
const session = requireSession(c, services);
|
||||||
if (session instanceof Response) return session;
|
if (session instanceof Response) return session;
|
||||||
@@ -1174,6 +1184,7 @@ function showShift(
|
|||||||
contacts={showWalkIn ? loadContacts(services.db, '').people : []}
|
contacts={showWalkIn ? loadContacts(services.db, '').people : []}
|
||||||
moves={confirmed ? { targets, tokens } : undefined}
|
moves={confirmed ? { targets, tokens } : undefined}
|
||||||
confirm={confirm}
|
confirm={confirm}
|
||||||
|
editError={editError}
|
||||||
/>,
|
/>,
|
||||||
{ account: session, status },
|
{ account: session, status },
|
||||||
);
|
);
|
||||||
@@ -1249,10 +1260,10 @@ async function submitShift(c: Context, services: AdminServices): Promise<Respons
|
|||||||
const id = idFrom(c);
|
const id = idFrom(c);
|
||||||
const values = shiftValuesFrom(session.body);
|
const values = shiftValuesFrom(session.body);
|
||||||
const parsed = parseShift(values);
|
const parsed = parseShift(values);
|
||||||
if (!parsed.ok) return showShift(c, services, parsed.error, 400);
|
if (!parsed.ok) return showShift(c, services, undefined, 400, undefined, id, undefined, parsed.error);
|
||||||
try {
|
try {
|
||||||
const saved = updateShift(services.db, session.coordinatorId, id, parsed.value, services.now(), mailIdentity(services.db, services.config));
|
const saved = updateShift(services.db, session.coordinatorId, id, parsed.value, services.now(), mailIdentity(services.db, services.config));
|
||||||
if (!saved.ok) return showShift(c, services, saved.error, 400);
|
if (!saved.ok) return showShift(c, services, undefined, 400, undefined, id, undefined, saved.error);
|
||||||
return c.redirect(appPath(services.config, `/admin/shifts/${id}?notice=saved`), 303);
|
return c.redirect(appPath(services.config, `/admin/shifts/${id}?notice=saved`), 303);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return saveFailed(c, services, session, err);
|
return saveFailed(c, services, session, err);
|
||||||
|
|||||||
+574
-356
File diff suppressed because it is too large.
Load diff
+71
-1
@@ -8,10 +8,12 @@ import type { MailShift } from '../mail/templates.js';
|
|||||||
import type { MailIdentity } from '../mail/types.js';
|
import type { MailIdentity } from '../mail/types.js';
|
||||||
import { confirmedPersonOnShift, confirmedPersonShiftIds, reserveSignup, type ReserveInput, type ReserveResult } from '../signup.js';
|
import { confirmedPersonOnShift, confirmedPersonShiftIds, reserveSignup, type ReserveInput, type ReserveResult } from '../signup.js';
|
||||||
import { isUniqueConstraint } from '../sqlite-error.js';
|
import { isUniqueConstraint } from '../sqlite-error.js';
|
||||||
import { assertSameDayShift, assertValidTimeZone, formatInstantInZone, formatUtc, localShiftToUtc, LocalTimeError } from '../time.js';
|
import { addLocalDays, assertSameDayShift, assertValidTimeZone, formatInstantInZone, formatUtc, localShiftToUtc, LocalTimeError, todayInZone } from '../time.js';
|
||||||
|
|
||||||
const MANAGE_TOKEN_TTL_HOURS = 24 * 7;
|
const MANAGE_TOKEN_TTL_HOURS = 24 * 7;
|
||||||
const REPLACED_LINK = 'This link replaces the earlier one. The previous link no longer works.';
|
const REPLACED_LINK = 'This link replaces the earlier one. The previous link no longer works.';
|
||||||
|
/** Today through this many days ahead. The event shift list uses the same window. */
|
||||||
|
export const DESK_WINDOW_DAYS = 14;
|
||||||
|
|
||||||
export type AdminEventSummary = {
|
export type AdminEventSummary = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -21,6 +23,22 @@ export type AdminEventSummary = {
|
|||||||
shiftCount: number;
|
shiftCount: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type HomeShift = {
|
||||||
|
id: number;
|
||||||
|
eventId: number;
|
||||||
|
eventTitle: string;
|
||||||
|
role: string;
|
||||||
|
date: string;
|
||||||
|
timeLabel: string;
|
||||||
|
capacity: number;
|
||||||
|
occupied: number;
|
||||||
|
full: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HomeEvent = AdminEventSummary & {
|
||||||
|
nextShift: { date: string; timeLabel: string } | null;
|
||||||
|
};
|
||||||
|
|
||||||
export type AdminShiftSummary = {
|
export type AdminShiftSummary = {
|
||||||
id: number;
|
id: number;
|
||||||
role: string;
|
role: string;
|
||||||
@@ -149,6 +167,58 @@ export function listAdminEvents(db: Database.Database): AdminEventSummary[] {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Open and full shifts in the next two weeks, plus the next open shift on each event. */
|
||||||
|
export function listHomeBoard(db: Database.Database, now: string, timeZone: string): { shifts: HomeShift[]; events: HomeEvent[] } {
|
||||||
|
const today = todayInZone(timeZone, Temporal.Instant.from(now));
|
||||||
|
const cutoff = addLocalDays(today, DESK_WINDOW_DAYS);
|
||||||
|
const rows = db
|
||||||
|
.prepare(
|
||||||
|
`SELECT s.id AS id, s.role AS role, s.starts_at_utc AS starts_at_utc, s.capacity AS capacity,
|
||||||
|
e.id AS event_id, e.title AS title, e.tz AS tz,
|
||||||
|
COALESCE(SUM(CASE WHEN su.status = 'confirmed' THEN su.group_size ELSE 0 END), 0) AS occupied
|
||||||
|
FROM shifts s
|
||||||
|
JOIN events e ON e.id = s.event_id
|
||||||
|
LEFT JOIN signups su ON su.shift_id = s.id
|
||||||
|
WHERE s.cancelled = 0 AND s.ends_at_utc > ?
|
||||||
|
GROUP BY s.id
|
||||||
|
ORDER BY s.starts_at_utc, s.id`,
|
||||||
|
)
|
||||||
|
.all(now) as Array<{
|
||||||
|
id: number;
|
||||||
|
role: string;
|
||||||
|
starts_at_utc: string;
|
||||||
|
capacity: number;
|
||||||
|
event_id: number;
|
||||||
|
title: string;
|
||||||
|
tz: string;
|
||||||
|
occupied: number;
|
||||||
|
}>;
|
||||||
|
const nextByEvent = new Map<number, { date: string; timeLabel: string }>();
|
||||||
|
const shifts: HomeShift[] = [];
|
||||||
|
for (const row of rows) {
|
||||||
|
const local = formatInstantInZone(row.starts_at_utc, row.tz);
|
||||||
|
if (!nextByEvent.has(row.event_id)) nextByEvent.set(row.event_id, { date: local.date, timeLabel: local.timeLabel });
|
||||||
|
if (local.date < today || local.date > cutoff) continue;
|
||||||
|
const capacity = Number(row.capacity);
|
||||||
|
const occupied = Number(row.occupied);
|
||||||
|
shifts.push({
|
||||||
|
id: row.id,
|
||||||
|
eventId: row.event_id,
|
||||||
|
eventTitle: row.title,
|
||||||
|
role: row.role,
|
||||||
|
date: local.date,
|
||||||
|
timeLabel: local.timeLabel,
|
||||||
|
capacity,
|
||||||
|
occupied,
|
||||||
|
full: occupied >= capacity,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
shifts,
|
||||||
|
events: listAdminEvents(db).map((event) => ({ ...event, nextShift: nextByEvent.get(event.id) ?? null })),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function getAdminEvent(db: Database.Database, id: number): AdminEvent | null {
|
export function getAdminEvent(db: Database.Database, id: number): AdminEvent | null {
|
||||||
const event = db
|
const event = db
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|||||||
+47
-3
@@ -223,6 +223,44 @@ describe('coordinator sign-in', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('coordinator screens', () => {
|
describe('coordinator screens', () => {
|
||||||
|
it('shows the next two weeks of shifts above equal event and download cells', async () => {
|
||||||
|
const { app, db } = await buildApp();
|
||||||
|
const cookie = await signIn(app, db);
|
||||||
|
const eventId = await createEvent(app, cookie, 'Weekly pantry', true);
|
||||||
|
const hiddenId = await createEvent(app, cookie, 'Holiday food drive', false);
|
||||||
|
const todayId = await addShift(app, cookie, eventId, { role: 'Pantry helper', date: '2026-10-14', capacity: '6', start: '16:00', end: '18:00' });
|
||||||
|
const laterId = await addShift(app, cookie, eventId, { role: 'Pantry helper', date: '2026-10-27', capacity: '6', start: '16:00', end: '18:00' });
|
||||||
|
const fullId = await addShift(app, cookie, eventId, { role: 'Sorting crew', date: '2026-10-24', capacity: '1', start: '09:00', end: '11:00' });
|
||||||
|
await addShift(app, cookie, eventId, { role: 'Edge shift', date: '2026-10-28', capacity: '2' });
|
||||||
|
await addShift(app, cookie, eventId, { role: 'Later shift', date: '2026-10-29', capacity: '2' });
|
||||||
|
await addShift(app, cookie, hiddenId, { role: 'Packing', date: '2026-10-20', capacity: '3' });
|
||||||
|
for (let index = 0; index < 4; index += 1) reserve(db, todayId, `Pat ${index}`, `pat${index}@example.invalid`, `home-open-${index}`);
|
||||||
|
reserve(db, laterId, 'Ada One', 'ada1@example.invalid', 'home-later-1');
|
||||||
|
reserve(db, laterId, 'Ada Two', 'ada2@example.invalid', 'home-later-2');
|
||||||
|
reserve(db, fullId, 'Full Person', 'full@example.invalid', 'home-full');
|
||||||
|
|
||||||
|
const html = await (await app.request('/admin', { headers: { cookie } })).text();
|
||||||
|
expect(html).toContain('Wednesday, October 14, 2026');
|
||||||
|
expect(html).toContain('Shifts that need volunteers');
|
||||||
|
expect(html).toContain('Next 2 weeks');
|
||||||
|
expect(html).toContain('Today, 4:00 PM');
|
||||||
|
expect(html).toContain('2 open · 4 of 6');
|
||||||
|
expect(html).toContain('Tue, Oct 27, 4:00 PM');
|
||||||
|
expect(html).toContain('Needs 4 · 2 of 6');
|
||||||
|
expect(html).toContain('Sat, Oct 24 Sorting crew is full.');
|
||||||
|
expect(html).toContain('Wed, Oct 28, 9:00 AM');
|
||||||
|
expect(html).not.toContain('Later shift');
|
||||||
|
expect(html).toContain('class="desk-split"');
|
||||||
|
expect(html).toContain('Next shift today at 4:00 PM · 5 shifts');
|
||||||
|
expect(html).toContain('>Public<');
|
||||||
|
expect(html).toContain('>Hidden<');
|
||||||
|
expect(html).toContain('Next shift Tue, Oct 20 at 9:00 AM · 1 shift');
|
||||||
|
expect(html).toContain('value="2026-10-01"');
|
||||||
|
expect(html).toContain('value="2026-10-31"');
|
||||||
|
expect(html).toContain('Download spreadsheet');
|
||||||
|
expect(html).toContain('href="/admin/contacts"');
|
||||||
|
});
|
||||||
|
|
||||||
it('keeps unpublished events and the roster off the public site', async () => {
|
it('keeps unpublished events and the roster off the public site', async () => {
|
||||||
const { app, db } = await buildApp();
|
const { app, db } = await buildApp();
|
||||||
const cookie = await signIn(app, db);
|
const cookie = await signIn(app, db);
|
||||||
@@ -278,6 +316,8 @@ describe('coordinator screens', () => {
|
|||||||
const rosterHtml = await roster.text();
|
const rosterHtml = await roster.text();
|
||||||
expect(rosterHtml).toContain('pat@example.invalid');
|
expect(rosterHtml).toContain('pat@example.invalid');
|
||||||
expect(rosterHtml).toContain('Sam Example');
|
expect(rosterHtml).toContain('Sam Example');
|
||||||
|
expect(rosterHtml).toContain('Edit details');
|
||||||
|
expect(rosterHtml).toContain('class="event-edit"');
|
||||||
const publicShift = await (await app.request(`/s/${shiftId}`)).text();
|
const publicShift = await (await app.request(`/s/${shiftId}`)).text();
|
||||||
expect(publicShift).not.toContain('pat@example.invalid');
|
expect(publicShift).not.toContain('pat@example.invalid');
|
||||||
expect(publicShift).not.toContain('Sam Example');
|
expect(publicShift).not.toContain('Sam Example');
|
||||||
@@ -324,6 +364,10 @@ describe('coordinator screens', () => {
|
|||||||
expect(db.prepare("SELECT status AS status FROM signups WHERE email_norm = 'sam@example.invalid'").get()).toEqual({ status: 'cancelled' });
|
expect(db.prepare("SELECT status AS status FROM signups WHERE email_norm = 'sam@example.invalid'").get()).toEqual({ status: 'cancelled' });
|
||||||
expect(count(db, 'SELECT COUNT(*) AS n FROM signups')).toBe(2);
|
expect(count(db, 'SELECT COUNT(*) AS n FROM signups')).toBe(2);
|
||||||
expect(await (await app.request('/')).text()).not.toContain('Ladle');
|
expect(await (await app.request('/')).text()).not.toContain('Ladle');
|
||||||
|
const closedAdmin = await (await app.request(`/admin/shifts/${shiftId}`, { headers: { cookie } })).text();
|
||||||
|
expect(closedAdmin).toContain('Cancelled. The roster stays until you remove it.');
|
||||||
|
expect(closedAdmin).not.toContain('Edit details');
|
||||||
|
expect(closedAdmin).toContain('Remove this shift');
|
||||||
const closedPage = await (await app.request(`/s/${shiftId}`)).text();
|
const closedPage = await (await app.request(`/s/${shiftId}`)).text();
|
||||||
expect(closedPage).toContain('This shift is closed');
|
expect(closedPage).toContain('This shift is closed');
|
||||||
expect(closedPage).not.toContain('<form');
|
expect(closedPage).not.toContain('<form');
|
||||||
@@ -693,7 +737,7 @@ describe('coordinator screens', () => {
|
|||||||
expect((await postForm(app, `/admin/shifts/${eveningId}/cancel`, cookie, {})).status).toBe(303);
|
expect((await postForm(app, `/admin/shifts/${eveningId}/cancel`, cookie, {})).status).toBe(303);
|
||||||
|
|
||||||
const html = await (await app.request(`/admin/events/${eventId}`, { headers: { cookie } })).text();
|
const html = await (await app.request(`/admin/events/${eventId}`, { headers: { cookie } })).text();
|
||||||
const moreAt = html.indexOf('See 2 more shifts');
|
const moreAt = html.indexOf('Show 2 more shifts');
|
||||||
expect(moreAt).toBeGreaterThan(0);
|
expect(moreAt).toBeGreaterThan(0);
|
||||||
const before = html.slice(0, moreAt);
|
const before = html.slice(0, moreAt);
|
||||||
const after = html.slice(moreAt);
|
const after = html.slice(moreAt);
|
||||||
@@ -714,14 +758,14 @@ describe('coordinator screens', () => {
|
|||||||
await addShift(app, cookie, soon, { role: 'Ladle', date: '2026-10-16', capacity: '2' });
|
await addShift(app, cookie, soon, { role: 'Ladle', date: '2026-10-16', capacity: '2' });
|
||||||
const short = await (await app.request(`/admin/events/${soon}`, { headers: { cookie } })).text();
|
const short = await (await app.request(`/admin/events/${soon}`, { headers: { cookie } })).text();
|
||||||
expect(short).toContain('Ladle');
|
expect(short).toContain('Ladle');
|
||||||
expect(short).not.toContain('See 1 more shift');
|
expect(short).not.toContain('Show 1 more shift');
|
||||||
expect(short).not.toContain('shift-more');
|
expect(short).not.toContain('shift-more');
|
||||||
|
|
||||||
const distant = await createEvent(app, cookie, 'Holiday', true);
|
const distant = await createEvent(app, cookie, 'Holiday', true);
|
||||||
await addShift(app, cookie, distant, { role: 'Early', date: '2026-11-04', capacity: '2' });
|
await addShift(app, cookie, distant, { role: 'Early', date: '2026-11-04', capacity: '2' });
|
||||||
await addShift(app, cookie, distant, { role: 'Later', date: '2026-11-18', capacity: '2' });
|
await addShift(app, cookie, distant, { role: 'Later', date: '2026-11-18', capacity: '2' });
|
||||||
const far = await (await app.request(`/admin/events/${distant}`, { headers: { cookie } })).text();
|
const far = await (await app.request(`/admin/events/${distant}`, { headers: { cookie } })).text();
|
||||||
const farMore = far.indexOf('See 1 more shift');
|
const farMore = far.indexOf('Show 1 more shift');
|
||||||
expect(farMore).toBeGreaterThan(0);
|
expect(farMore).toBeGreaterThan(0);
|
||||||
expect(far.slice(0, farMore)).toContain('Early');
|
expect(far.slice(0, farMore)).toContain('Early');
|
||||||
expect(far.slice(farMore)).toContain('Later');
|
expect(far.slice(farMore)).toContain('Later');
|
||||||
|
|||||||
Reference in new issue
Block a user