Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions client/e2e/tests/40-shift-page-edit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { test, expect, type APIRequestContext } from "@playwright/test";
import type { RowDataPacket } from "mysql2";

import {
cleanupAllTestData,
closePool,
getPool,
insertFullShift,
insertVolunteer,
insertVolunteerShift,
} from "../helpers/db";
import { buildSessionCookieHeader } from "../helpers/session";
import {
FUTURE_SHIFT,
makeTestVolunteer,
signInAsBuiltinAdmin,
} from "../fixtures/test-data";

// Item 5 (#731, Mew 2026-11-29): edit a shift from its page. Moving it stamps
// rescheduled_at and emails the people on it; #466: shift_instance is unique
// per type, not across all types.
const volunteer = makeTestVolunteer({
shiftboardId: 9_000_700,
playaName: "E2E Rescheduled",
worldName: "Re Scheduled",
email: "e2e-rescheduled@test.local",
passcode: "6000",
});
const ADMIN = 1;
const day = FUTURE_SHIFT.startTime.slice(0, 10);
const path = `/api/shifts/types/${FUTURE_SHIFT.shiftNameId}/times/${FUTURE_SHIFT.shiftTimesId}`;
const patch = (request: APIRequestContext, body: object) =>
request.patch(path, {
headers: { cookie: buildSessionCookieHeader(ADMIN) },
data: JSON.stringify(body),
});
const queued = async () => {
const [rows] = await getPool().query<RowDataPacket[]>(
"SELECT category FROM op_email_queue WHERE `to` = ? ORDER BY id",
[volunteer.email]
);
return rows.map((r) => r.category);
};

test.describe("edit a shift from its page (#731)", () => {
test.beforeAll(async () => {
await cleanupAllTestData();
await insertFullShift(FUTURE_SHIFT);
await insertVolunteer(volunteer);
await insertVolunteerShift(
volunteer.shiftboardId,
FUTURE_SHIFT.timePositionId
);
await getPool().execute("DELETE FROM op_email_queue WHERE `to` = ?", [
volunteer.email,
]);
});

test.afterAll(async () => {
await getPool().execute("DELETE FROM op_email_queue WHERE `to` = ?", [
volunteer.email,
]);
await cleanupAllTestData();
await closePool();
});

test("moving it stamps rescheduled_at and emails the people on it", async ({
request,
}) => {
expect((await patch(request, { notes: "same time" })).status()).toBe(200);
expect(await queued()).toEqual([]);

expect((await patch(request, { startTime: "11:00" })).status()).toBe(200);
const [[row]] = await getPool().query<RowDataPacket[]>(
"SELECT rescheduled_at, start_time FROM op_shift_times WHERE shift_times_id = ?",
[FUTURE_SHIFT.shiftTimesId]
);
expect(row.rescheduled_at).not.toBeNull();
expect(row.start_time).toBe(`${day} 11:00`);
expect(await queued()).toEqual(["shift-rescheduled"]);
});

test("shift instance names are unique per type, not across types (#466)", async () => {
const db = getPool();
await db.execute(
"UPDATE op_shift_times SET shift_instance = 'E2E shared instance' WHERE shift_times_id = ?",
[FUTURE_SHIFT.shiftTimesId]
);
// another type may reuse the name…
await db.execute(
`INSERT IGNORE INTO op_shift_name (shift_name_id, shift_name, shift_category_id, off_playa, delete_shift, create_shift)
VALUES (9000702, 'E2E other type', ?, 0, 0, 1)`,
[FUTURE_SHIFT.categoryId]
);
await db.execute(
`INSERT INTO op_shift_times (shift_times_id, shift_name_id, shift_instance, start_time, end_time, remove_shift_time, add_shift_time)
VALUES (9000701, 9000702, 'E2E shared instance', ?, ?, 0, 1)`,
[FUTURE_SHIFT.startTime, FUTURE_SHIFT.endTime]
);
await db.execute(
"DELETE FROM op_shift_times WHERE shift_times_id = 9000701"
);
await db.execute("DELETE FROM op_shift_name WHERE shift_name_id = 9000702");
// …the same type may not
await expect(
db.execute(
`INSERT INTO op_shift_times (shift_times_id, shift_name_id, shift_instance, start_time, end_time, remove_shift_time, add_shift_time)
VALUES (9000701, ?, 'E2E shared instance', ?, ?, 0, 1)`,
[FUTURE_SHIFT.shiftNameId, FUTURE_SHIFT.startTime, FUTURE_SHIFT.endTime]
)
).rejects.toThrow(/Duplicate/);
});

test("SuperAdmin edits notes and slots from the shift page", async ({
page,
}) => {
test.setTimeout(120_000);
await signInAsBuiltinAdmin(page);
await page.goto(`/shifts/${FUTURE_SHIFT.shiftTimesId}/volunteers`);
await page.getByRole("button", { name: "Edit this shift" }).click();
const dialog = page.getByRole("dialog");
await dialog.getByLabel("Notes").fill("E2E bring water");
await dialog.getByLabel("Slots").fill("7");
await dialog.getByRole("button", { name: "Save" }).click();
await expect(dialog).toBeHidden();
await expect(page.getByText("E2E bring water")).toBeVisible();
const [[row]] = await getPool().query<RowDataPacket[]>(
`SELECT st.notes, stp.slots FROM op_shift_times st
JOIN op_shift_time_position stp ON stp.shift_times_id = st.shift_times_id
WHERE st.shift_times_id = ?`,
[FUTURE_SHIFT.shiftTimesId]
);
expect(row).toMatchObject({ notes: "E2E bring water", slots: 7 });
});
});
1 change: 1 addition & 0 deletions client/src/app/emails/Emails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Hero } from "@/components/layout/Hero";
import { EMAIL_TEMPLATES } from "@/lib/emailTemplates";

const FIELD_HELP: Record<string, string> = {
before: 'the old day and time, e.g. "2027-08-28 09:00–12:00"',
by: 'who did it, e.g. "by Chipper"',
decision: 'the choice made, e.g. "Census Lab"',
form: "the form's title",
Expand Down
30 changes: 29 additions & 1 deletion client/src/app/shifts/[timeId]/volunteers/ShiftVolunteers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import {
Chat as ChatIcon,
Edit as EditIcon,
Groups3 as Groups3Icon,
ManageAccounts as ManageAccountsIcon,
MoreHoriz as MoreHorizIcon,
Expand Down Expand Up @@ -38,6 +39,7 @@ import useSWRMutation from "swr/mutation";

import { FormattedText } from "@/components/general/FormattedText";
import { ShiftVolunteersDialogAdd } from "@/app/shifts/[timeId]/volunteers/ShiftVolunteersDialogAdd";
import { ShiftVolunteersDialogEdit } from "@/app/shifts/[timeId]/volunteers/ShiftVolunteersDialogEdit";
import { ShiftVolunteersDialogRemove } from "@/app/shifts/[timeId]/volunteers/ShiftVolunteersDialogRemove";
import { ShiftVolunteersDialogReview } from "@/app/shifts/[timeId]/volunteers/ShiftVolunteersDialogReview";
import { BreadcrumbsNav } from "@/components/general/BreadcrumbsNav";
Expand Down Expand Up @@ -69,7 +71,11 @@ import { useIsOnPlaya } from "@/hooks/useIsOnPlaya";
import { useNow } from "@/hooks/useNow";
import { DeveloperModeContext } from "@/state/developer-mode/context";
import { SessionContext } from "@/state/session/context";
import { checkIsAdmin, checkIsAuthenticated } from "@/utils/checkIsRoleExist";
import {
checkIsAdmin,
checkIsAuthenticated,
checkIsSuperAdmin,
} from "@/utils/checkIsRoleExist";
import { confirmUncheckIn } from "@/utils/confirmUncheckIn";
import { fetcherGet, fetcherTrigger } from "@/utils/fetcher";
import { formatDateName, formatTime } from "@/utils/formatDateTime";
Expand Down Expand Up @@ -151,6 +157,7 @@ export const ShiftVolunteers = ({
},
});
const [isDialogOpen, setIsDialogOpen] = useState(false);
const [isEditOpen, setIsEditOpen] = useState(false);

// fetching, mutation, and revalidation
// ------------------------------------------------------------
Expand Down Expand Up @@ -307,6 +314,7 @@ export const ShiftVolunteers = ({
isAuthenticatedSession
);
const isAdmin = checkIsAdmin(accountType, roleList);
const isSuperAdmin = checkIsSuperAdmin(accountType, roleList);

const handleCheckInToggle = async ({
shift: { positionName, timePositionId },
Expand Down Expand Up @@ -763,6 +771,26 @@ export const ShiftVolunteers = ({
<br />
{dataShiftVolunteersItem.shift.typeName}
</Typography>
{isSuperAdmin && (
<>
<Button
onClick={() => setIsEditOpen(true)}
size="small"
startIcon={<EditIcon />}
sx={{ mb: 2 }}
variant="outlined"
>
Edit this shift
</Button>
<ShiftVolunteersDialogEdit
data={dataShiftVolunteersItem}
handleDialogClose={() => setIsEditOpen(false)}
handleSaved={() => mutateShiftVolunteersItem()}
isDialogOpen={isEditOpen}
timeId={Number(timeIdParam)}
/>
</>
)}
</Box>
{!isShiftCanceled && (
// Add-this-shift is the primary action and sits on top (Chipper
Expand Down
Loading
Loading