* Fix no-shadow and consistent-function-scoping lint violations
Resolves all 11 no-shadow and 16 consistent-function-scoping oxlint
warnings and promotes both rules to errors in .oxlintrc.json.
no-shadow: renamed Drizzle callback params (sports→s, matches→m,
seasons→s) to avoid shadowing outer imports; removed shadowed
destructures (eq, inArray) from where callbacks; renamed inner
template→bracketTemplate, prev→currentTimers, season→ss, name→teamName
(with name: teamName fix to preserve semantics).
consistent-function-scoping: moved formatDate, getRankBadge,
getMovementIndicator, getPositionBadge, getStatusBadge, toDateStr,
elo (×2), weightedPick, sortByMatchNumber (×2) to module scope;
moved formatTime (×2), isValidLeagueName, getDraftTimes,
makeSeasonQueues to file scope in test files.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix no-non-null-assertion lint violations and promote to error
Eliminates all 208 no-non-null-assertion warnings across 38 files.
Promotes typescript/no-non-null-assertion from warn to error in
.oxlintrc.json.
Fix patterns applied:
- Map.get(key)! after .has() check → extract with get() + null guard
- Map.get(key)! on pre-populated count maps → ?? 0 default
- .set(id, map.get(id)! + 1) increment → ?? 0 before adding
- participant1Id!/participant2Id! on DB matches → ?? "" fallback
- array.find()! in tests → guard + throw or expect().toBeDefined()
- bracketTemplateCache.get(id)! → null guard extract
- Various nullable field accesses → optional chain or ?? default
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix prefer-add-event-listener, no-unassigned-import, require-module-specifiers
Resolves all 9 remaining non-console lint warnings and promotes all
three rules to errors in .oxlintrc.json.
- prefer-add-event-listener: converted onchange/onclick/onload
assignments to addEventListener in useDraftNotifications.ts and
admin.data-sync.tsx; stored changeHandler ref for proper cleanup
with removeEventListener
- no-unassigned-import: configured rule with allow list for legitimate
side-effect imports (*.css, @testing-library/jest-dom,
@testing-library/cypress/add-commands)
- require-module-specifiers: removed redundant `export {}` from
cypress/support/e2e.ts (file already has an import)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix TypeScript errors from no-non-null-assertion fixes
Two fixes introduced by the non-null assertion cleanup produced type
errors:
- scoring-event.ts: `?? ""` was wrong type for a participant object map;
restructured to explicit null guards so TypeScript can narrow correctly
- standings-sync/index.ts: `?? null` after name-match lookup lost the
truthy guarantee, causing TS18047 on the write-back block; added
`participant &&` guard before accessing its properties
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Add npm run typecheck as Stop hook in Claude settings
Runs a full project typecheck at the end of each Claude turn so type
errors surface as feedback before the next message.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
170 lines
5 KiB
TypeScript
170 lines
5 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { render, screen } from '@testing-library/react';
|
|
import { DraftGrid } from '../DraftGrid';
|
|
import { mockDraftSlots } from '~/test/fixtures/team';
|
|
|
|
function formatTime(seconds: number | undefined) {
|
|
if (seconds === undefined) return '--:--';
|
|
const mins = Math.floor(seconds / 60);
|
|
const secs = seconds % 60;
|
|
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
|
}
|
|
|
|
describe('DraftGrid Component', () => {
|
|
const mockGrid = [
|
|
[
|
|
{ pickNumber: 1, participant: { id: 'p1', name: 'Player 1' }, sport: { id: 's1', name: 'NFL' }, team: { id: 't1', name: 'Team 1' } },
|
|
null,
|
|
],
|
|
[
|
|
null,
|
|
{ pickNumber: 4, participant: { id: 'p2', name: 'Player 2' }, sport: { id: 's2', name: 'NBA' }, team: { id: 't2', name: 'Team 2' } },
|
|
],
|
|
];
|
|
|
|
describe('Rendering', () => {
|
|
it('should render team names in headers', () => {
|
|
render(
|
|
<DraftGrid
|
|
draftSlots={mockDraftSlots}
|
|
draftGrid={mockGrid}
|
|
currentPick={2}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText('Team 1')).toBeInTheDocument();
|
|
expect(screen.getByText('Team 2')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should render draft grid with correct structure', () => {
|
|
render(
|
|
<DraftGrid
|
|
draftSlots={mockDraftSlots}
|
|
draftGrid={mockGrid}
|
|
currentPick={2}
|
|
/>
|
|
);
|
|
|
|
// Should have cells for all picks
|
|
const cells = screen.getAllByTitle(/Overall Pick/i);
|
|
expect(cells.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should display picked players', () => {
|
|
render(
|
|
<DraftGrid
|
|
draftSlots={mockDraftSlots}
|
|
draftGrid={mockGrid}
|
|
currentPick={2}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText('Player 1')).toBeInTheDocument();
|
|
expect(screen.getByText('NFL')).toBeInTheDocument();
|
|
expect(screen.getByText('Player 2')).toBeInTheDocument();
|
|
expect(screen.getByText('NBA')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('Current Pick Highlighting', () => {
|
|
it('should highlight current pick with "On Clock" text', () => {
|
|
render(
|
|
<DraftGrid
|
|
draftSlots={mockDraftSlots}
|
|
draftGrid={mockGrid}
|
|
currentPick={2}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText('On Clock')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should apply correct styling to current pick', () => {
|
|
render(
|
|
<DraftGrid
|
|
draftSlots={mockDraftSlots}
|
|
draftGrid={mockGrid}
|
|
currentPick={2}
|
|
/>
|
|
);
|
|
|
|
const currentPickCell = screen.getByText('On Clock').parentElement;
|
|
expect(currentPickCell).toHaveClass('border-electric');
|
|
expect(currentPickCell).toHaveClass('bg-electric/15');
|
|
});
|
|
});
|
|
|
|
describe('Pick Numbering', () => {
|
|
it('should display round and pick numbers', () => {
|
|
render(
|
|
<DraftGrid
|
|
draftSlots={mockDraftSlots}
|
|
draftGrid={mockGrid}
|
|
currentPick={1}
|
|
/>
|
|
);
|
|
|
|
// Should show format like "1.01", "1.02", etc.
|
|
expect(screen.getByText(/1\.01/)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('Optional Features', () => {
|
|
it('should render with title when provided', () => {
|
|
render(
|
|
<DraftGrid
|
|
draftSlots={mockDraftSlots}
|
|
draftGrid={mockGrid}
|
|
currentPick={1}
|
|
title="Draft Board"
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText('Draft Board')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should display timers when provided', () => {
|
|
render(
|
|
<DraftGrid
|
|
draftSlots={mockDraftSlots}
|
|
draftGrid={mockGrid}
|
|
currentPick={1}
|
|
teamTimers={{ 'team-1': 120, 'team-2': 90 }}
|
|
formatTime={formatTime}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText('2:00')).toBeInTheDocument();
|
|
expect(screen.getByText('1:30')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('Snake Draft Order', () => {
|
|
it('should reverse picks on even rounds', () => {
|
|
const snakeGrid = [
|
|
[
|
|
{ pickNumber: 1, participant: { id: 'p1', name: 'Pick 1' }, sport: { id: 's1', name: 'NFL' }, team: { id: 't1', name: 'Team 1' } },
|
|
{ pickNumber: 2, participant: { id: 'p2', name: 'Pick 2' }, sport: { id: 's2', name: 'NBA' }, team: { id: 't2', name: 'Team 2' } },
|
|
],
|
|
[
|
|
{ pickNumber: 3, participant: { id: 'p3', name: 'Pick 4' }, sport: { id: 's1', name: 'MLB' }, team: { id: 't2', name: 'Team 2' } },
|
|
{ pickNumber: 4, participant: { id: 'p4', name: 'Pick 3' }, sport: { id: 's2', name: 'NHL' }, team: { id: 't1', name: 'Team 1' } },
|
|
],
|
|
];
|
|
|
|
render(
|
|
<DraftGrid
|
|
draftSlots={mockDraftSlots}
|
|
draftGrid={snakeGrid}
|
|
currentPick={5}
|
|
/>
|
|
);
|
|
|
|
// All picks should be visible
|
|
expect(screen.getByText('Pick 1')).toBeInTheDocument();
|
|
expect(screen.getByText('Pick 2')).toBeInTheDocument();
|
|
expect(screen.getByText('Pick 3')).toBeInTheDocument();
|
|
expect(screen.getByText('Pick 4')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|