mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
fix(client): work through the findings from the coverage pass
214 items came out of writing the tests. Real defects are corrected, dead code is removed rather than covered, and the tests that pinned the old behaviour move with them. Also drops two agent coverage scratch files that slipped into the coverage PR and adds the ignore rule that keeps them out.
This commit is contained in:
@@ -37,7 +37,7 @@ interface CoverSearchPhoto {
|
||||
|
||||
export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUpdate }: TripFormModalProps) {
|
||||
const isEditing = !!trip
|
||||
const fileRef = useRef(null)
|
||||
const fileRef = useRef<HTMLInputElement>(null)
|
||||
const coverSearchSeq = useRef(0)
|
||||
const toast = useToast()
|
||||
const { t } = useTranslation()
|
||||
@@ -202,7 +202,7 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
}
|
||||
}
|
||||
|
||||
const handleCoverSelect = async (file) => {
|
||||
const handleCoverSelect = async (file: File | null | undefined) => {
|
||||
if (!file) return
|
||||
// HEIC/HEIF from iOS can't be rendered or stored as-is — convert to JPEG first
|
||||
const normalized = await normalizeImageFile(file)
|
||||
@@ -217,12 +217,12 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
}
|
||||
}
|
||||
|
||||
const handleCoverChange = (e) => {
|
||||
handleCoverSelect((e.target as HTMLInputElement).files?.[0])
|
||||
const handleCoverChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
handleCoverSelect(e.target.files?.[0])
|
||||
e.target.value = ''
|
||||
}
|
||||
|
||||
const uploadCoverNow = async (file) => {
|
||||
const uploadCoverNow = async (file: File) => {
|
||||
setUploadingCover(true)
|
||||
try {
|
||||
const fd = new FormData()
|
||||
@@ -291,7 +291,7 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
setCoverPreview(null)
|
||||
return
|
||||
}
|
||||
if (!trip?.id) return
|
||||
// Nothing pending left, so the preview is a saved trip's stored cover.
|
||||
try {
|
||||
await tripsApi.update(trip.id, { cover_image: null })
|
||||
setCoverPreview(null)
|
||||
@@ -613,8 +613,7 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
{selectedMembers.length > 0 && (
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 8 }}>
|
||||
{selectedMembers.map(uid => {
|
||||
const user = allUsers.find(u => u.id === uid)
|
||||
if (!user) return null
|
||||
const user = allUsers.find(u => u.id === uid)!
|
||||
return (
|
||||
<span key={uid} onClick={() => setSelectedMembers(prev => prev.filter(id => id !== uid))}
|
||||
className="bg-surface-secondary text-content border border-edge cursor-pointer"
|
||||
@@ -633,7 +632,6 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
<CustomSelect
|
||||
value={memberSelectValue}
|
||||
onChange={async value => {
|
||||
if (!value) return
|
||||
if (isEditing && trip?.id) {
|
||||
const user = allUsers.find(u => u.id === Number(value))
|
||||
if (user) {
|
||||
|
||||
@@ -869,6 +869,23 @@ describe('TripMembersModal', () => {
|
||||
await waitFor(() => expect(screen.queryByDisplayValue('Granny')).not.toBeInTheDocument());
|
||||
});
|
||||
|
||||
it('FE-COMP-MEMBERS-048b: Enter followed by a blur renames only once', async () => {
|
||||
const user = userEvent.setup();
|
||||
mockRoster([guestRow]);
|
||||
let renames = 0;
|
||||
server.use(http.put('/api/trips/1/guests/:userId', () => { renames++; return HttpResponse.json({ success: true }); }));
|
||||
render(<TripMembersModal {...defaultProps} />);
|
||||
|
||||
await user.click(await screen.findByTitle('Rename'));
|
||||
const input = screen.getByDisplayValue('Grandma');
|
||||
fireEvent.change(input, { target: { value: 'Granny' } });
|
||||
fireEvent.keyDown(input, { key: 'Enter' });
|
||||
fireEvent.blur(input);
|
||||
|
||||
await waitFor(() => expect(screen.queryByDisplayValue('Granny')).not.toBeInTheDocument());
|
||||
expect(renames).toBe(1);
|
||||
});
|
||||
|
||||
it('FE-COMP-MEMBERS-049: Escape cancels a rename and a blank name saves nothing', async () => {
|
||||
const user = userEvent.setup();
|
||||
mockRoster([guestRow]);
|
||||
|
||||
@@ -202,7 +202,6 @@ function TripInviteLinkSection({ tripId, t }: { tripId: number; t: (key: string,
|
||||
}
|
||||
|
||||
const copy = () => {
|
||||
if (!inviteUrl) return
|
||||
navigator.clipboard.writeText(inviteUrl)
|
||||
setCopied(true)
|
||||
if (copyTimerRef.current) clearTimeout(copyTimerRef.current)
|
||||
@@ -324,7 +323,6 @@ export default function TripMembersModal({ isOpen, onClose, tripId, tripTitle, o
|
||||
}
|
||||
|
||||
const handleAdd = async () => {
|
||||
if (!selectedUserId) return
|
||||
setAdding(true)
|
||||
try {
|
||||
const target = allUsers.find(u => String(u.id) === String(selectedUserId))
|
||||
@@ -370,7 +368,14 @@ export default function TripMembersModal({ isOpen, onClose, tripId, tripTitle, o
|
||||
}
|
||||
}
|
||||
|
||||
// Enter commits, and the blur that follows would send the same rename a second
|
||||
// time. Only the first commit per editing session goes through; a failed one
|
||||
// reopens the gate so the user can retry from the still-open input.
|
||||
const renameCommittedRef = useRef(false)
|
||||
|
||||
const handleRenameGuest = async (userId) => {
|
||||
if (renameCommittedRef.current) return
|
||||
renameCommittedRef.current = true
|
||||
const name = renameValue.trim()
|
||||
if (!name) { setRenamingGuestId(null); return }
|
||||
try {
|
||||
@@ -378,6 +383,7 @@ export default function TripMembersModal({ isOpen, onClose, tripId, tripTitle, o
|
||||
setRenamingGuestId(null)
|
||||
await loadMembers(true)
|
||||
} catch (err: unknown) {
|
||||
renameCommittedRef.current = false
|
||||
toast.error(getApiErrorMessage(err, t('members.guestRenameError')))
|
||||
}
|
||||
}
|
||||
@@ -572,7 +578,7 @@ export default function TripMembersModal({ isOpen, onClose, tripId, tripTitle, o
|
||||
autoFocus
|
||||
value={renameValue}
|
||||
onChange={e => setRenameValue(e.target.value)}
|
||||
onKeyDown={e => { if (e.key === 'Enter') handleRenameGuest(g.id); if (e.key === 'Escape') setRenamingGuestId(null) }}
|
||||
onKeyDown={e => { if (e.key === 'Enter') handleRenameGuest(g.id); if (e.key === 'Escape') { renameCommittedRef.current = true; setRenamingGuestId(null) } }}
|
||||
onBlur={() => handleRenameGuest(g.id)}
|
||||
maxLength={50}
|
||||
className="bg-surface border border-edge text-content"
|
||||
@@ -589,7 +595,7 @@ export default function TripMembersModal({ isOpen, onClose, tripId, tripTitle, o
|
||||
{isCurrentOwner && renamingGuestId !== g.id && (
|
||||
<>
|
||||
<button
|
||||
onClick={() => { setRenamingGuestId(g.id); setRenameValue(g.username) }}
|
||||
onClick={() => { renameCommittedRef.current = false; setRenamingGuestId(g.id); setRenameValue(g.username) }}
|
||||
title={t('common.rename')}
|
||||
style={{ background: 'none', border: 'none', cursor: 'pointer', padding: '4px', borderRadius: 6, display: 'flex', color: 'var(--text-faint)' }}
|
||||
onMouseEnter={e => e.currentTarget.style.color = 'var(--text-secondary)'}
|
||||
|
||||
Reference in New Issue
Block a user