Skip to content
Draft
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
2 changes: 1 addition & 1 deletion dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ define(['./workbox-5357ef54'], function (workbox) {
[
{
url: 'index.html',
revision: '0.3rdphr8mv9',
revision: '0.0d4ja86min8',
},
],
{},
Expand Down
33 changes: 33 additions & 0 deletions src/lib/results.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { renderResultByEventId } from './results';

describe('renderResultByEventId', () => {
it('should return empty string for null result', () => {
expect(renderResultByEventId('333', 'single', null as any)).toBe('');
});

it('should return empty string for undefined result', () => {
expect(renderResultByEventId('333', 'single', undefined as any)).toBe('');
});

it('should return empty string for NaN result', () => {
expect(renderResultByEventId('333', 'single', NaN)).toBe('');
});

it('should handle valid results correctly', () => {
// Test with a valid centisecond time (10.50 seconds = 1050 centiseconds)
const result = renderResultByEventId('333', 'single', 1050);
expect(result).toBe('10.50');
});

it('should handle 333fm average correctly', () => {
// Test with FMC average (30.00 moves = 3000)
const result = renderResultByEventId('333fm', 'average', 3000);
expect(result).toBe('30.00');
});

it('should handle 333fm single correctly', () => {
// Test with FMC single (30 moves)
const result = renderResultByEventId('333fm', 'single', 30);
expect(result).toBe(30);
});
});
5 changes: 5 additions & 0 deletions src/lib/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export const renderResultByEventId = (
rankingType: RankingType,
result: AttemptResult,
) => {
// Return empty string if result is null, undefined, or NaN
if (result == null || (typeof result === 'number' && isNaN(result))) {
return '';
}

if (eventId === '333fm') {
return rankingType === 'average' ? ((result as number) / 100).toFixed(2).toString() : result;
}
Expand Down
62 changes: 62 additions & 0 deletions src/lib/seedResult.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { EventId } from '@wca/helpers';
import { renderResultByEventId } from '@/lib/results';

// Mock the WCA helpers functions since we're testing null/undefined handling
jest.mock('@wca/helpers', () => ({
formatCentiseconds: jest.fn((time) => {
if (typeof time !== 'number' || isNaN(time)) {
return 'NaN';
}
return (time / 100).toFixed(2);
}),
formatMultiResult: jest.fn(() => 'MBLD Result'),
decodeMultiResult: jest.fn(() => ({ attempted: 1, solved: 1 })),
}));

describe('seedResult edge cases', () => {
beforeEach(() => {
jest.clearAllMocks();
});

describe('renderResultByEventId null/undefined handling', () => {
it('should return empty string when result is null', () => {
const result = renderResultByEventId('333' as EventId, 'single', null as any);
expect(result).toBe('');
});

it('should return empty string when result is undefined', () => {
const result = renderResultByEventId('333' as EventId, 'single', undefined as any);
expect(result).toBe('');
});

it('should return empty string when result is NaN', () => {
const result = renderResultByEventId('333' as EventId, 'single', NaN);
expect(result).toBe('');
});

it('should handle valid results correctly for 333', () => {
const result = renderResultByEventId('333' as EventId, 'single', 1050);
expect(result).toBe('10.50');
});

it('should handle 333fm average with null result', () => {
const result = renderResultByEventId('333fm' as EventId, 'average', null as any);
expect(result).toBe('');
});

it('should handle 333fm single with undefined result', () => {
const result = renderResultByEventId('333fm' as EventId, 'single', undefined as any);
expect(result).toBe('');
});

it('should handle 333fm average correctly with valid result', () => {
const result = renderResultByEventId('333fm' as EventId, 'average', 3000);
expect(result).toBe('30.00');
});

it('should handle 333fm single correctly with valid result', () => {
const result = renderResultByEventId('333fm' as EventId, 'single', 30);
expect(result).toBe(30);
});
});
});
19 changes: 16 additions & 3 deletions src/pages/Competition/Schedule/EventActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,18 @@ export function EventActivity({ competitionId, activity, persons }: EventGroupPr
}

if (['a', 'm'].includes(prevRound.format)) {
return renderResultByEventId(eventId, 'average', prevRoundResults.average);
const averageResult = prevRoundResults.average;
if (averageResult == null) {
return '';
}
return renderResultByEventId(eventId, 'average', averageResult);
}

return renderResultByEventId(eventId, 'single', prevRoundResults.best);
const bestResult = prevRoundResults.best;
if (bestResult == null) {
return '';
}
return renderResultByEventId(eventId, 'single', bestResult);
}

const averagePr = person.prAverage?.best;
Expand All @@ -129,10 +137,15 @@ export function EventActivity({ competitionId, activity, persons }: EventGroupPr
return '';
}

const resultValue = shouldShowAveragePr ? averagePr : singlePr;
if (resultValue == null) {
return '';
}

return renderResultByEventId(
eventId,
shouldShowAveragePr ? 'average' : 'single',
shouldShowAveragePr ? averagePr : singlePr,
resultValue,
);
},
[eventId, prevRound],
Expand Down