Skip to content

Commit c78095d

Browse files
committed
♻️ Extract mock data from tests (#2402)
1 parent 840d452 commit c78095d

File tree

2 files changed

+33
-42
lines changed

2 files changed

+33
-42
lines changed

src/test/lib/utils/contest_table_provider.test.ts

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,15 @@ describe('ContestTableProviderBase and implementations', () => {
239239
describe('Typical90 provider', () => {
240240
test('expects to filter tasks to include only typical90 contest', () => {
241241
const provider = new Typical90Provider(ContestType.TYPICAL90);
242-
const mockTypical90Tasks = [
243-
{ contest_id: 'typical90', task_id: 'typical90_a', task_table_index: '001' },
244-
{ contest_id: 'typical90', task_id: 'typical90_b', task_table_index: '002' },
245-
{ contest_id: 'typical90', task_id: 'typical90_j', task_table_index: '010' },
246-
{ contest_id: 'typical90', task_id: 'typical90_ck', task_table_index: '089' },
247-
{ contest_id: 'typical90', task_id: 'typical90_cl', task_table_index: '090' },
242+
const mixedTaskResults = [
243+
...mockTaskResults,
248244
{ contest_id: 'abc123', task_id: 'abc123_a', task_table_index: 'A' },
249245
{ contest_id: 'dp', task_id: 'dp_a', task_table_index: 'A' },
250246
];
251-
252-
const filtered = provider.filter(mockTypical90Tasks as any);
247+
const filtered = provider.filter(mixedTaskResults as TaskResults);
253248

254249
expect(filtered?.every((task) => task.contest_id === 'typical90')).toBe(true);
255-
expect(filtered?.length).toBe(5);
250+
expect(filtered?.length).toBe(filtered.length);
256251
expect(filtered).not.toContainEqual(expect.objectContaining({ contest_id: 'abc123' }));
257252
expect(filtered).not.toContainEqual(expect.objectContaining({ contest_id: 'dp' }));
258253
});
@@ -285,16 +280,8 @@ describe('ContestTableProviderBase and implementations', () => {
285280

286281
test('expects to generate correct table structure', () => {
287282
const provider = new Typical90Provider(ContestType.TYPICAL90);
288-
const mockTypical90Tasks = [
289-
{ contest_id: 'typical90', task_id: 'typical90_a', task_table_index: '001' },
290-
{ contest_id: 'typical90', task_id: 'typical90_b', task_table_index: '002' },
291-
{ contest_id: 'typical90', task_id: 'typical90_c', task_table_index: '003' },
292-
{ contest_id: 'typical90', task_id: 'typical90_j', task_table_index: '010' },
293-
{ contest_id: 'typical90', task_id: 'typical90_ck', task_table_index: '089' },
294-
{ contest_id: 'typical90', task_id: 'typical90_cl', task_table_index: '090' },
295-
];
296-
297-
const table = provider.generateTable(mockTypical90Tasks as any);
283+
const filtered = provider.filter(mockTaskResults as TaskResults);
284+
const table = provider.generateTable(filtered);
298285

299286
expect(table).toHaveProperty('typical90');
300287
expect(table.typical90).toHaveProperty('001');
@@ -325,41 +312,28 @@ describe('ContestTableProviderBase and implementations', () => {
325312

326313
test('expects to get contest round IDs correctly', () => {
327314
const provider = new Typical90Provider(ContestType.TYPICAL90);
328-
const mockTypical90Tasks = [
329-
{ contest_id: 'typical90', task_id: 'typical90_a', task_table_index: '001' },
330-
{ contest_id: 'typical90', task_id: 'typical90_b', task_table_index: '002' },
331-
{ contest_id: 'typical90', task_id: 'typical90_c', task_table_index: '003' },
332-
{ contest_id: 'typical90', task_id: 'typical90_j', task_table_index: '010' },
333-
{ contest_id: 'typical90', task_id: 'typical90_ck', task_table_index: '089' },
334-
{ contest_id: 'typical90', task_id: 'typical90_cl', task_table_index: '090' },
335-
];
336-
337-
const roundIds = provider.getContestRoundIds(mockTypical90Tasks as any);
315+
const filtered = provider.filter(mockTaskResults as TaskResults);
316+
const roundIds = provider.getContestRoundIds(filtered as TaskResults);
338317

339318
expect(roundIds).toEqual(['typical90']);
340319
});
341320

342321
test('expects to get header IDs for tasks correctly', () => {
343322
const provider = new Typical90Provider(ContestType.TYPICAL90);
344-
const mockTypical90Tasks = [
345-
{ contest_id: 'typical90', task_id: 'typical90_a', task_table_index: '001' },
346-
{ contest_id: 'typical90', task_id: 'typical90_b', task_table_index: '002' },
347-
{ contest_id: 'typical90', task_id: 'typical90_c', task_table_index: '003' },
323+
const taskResults = [
324+
...mockTaskResults,
348325
{ contest_id: 'typical90', task_id: 'typical90_d', task_table_index: '004' },
349326
{ contest_id: 'typical90', task_id: 'typical90_e', task_table_index: '005' },
350-
{ contest_id: 'typical90', task_id: 'typical90_j', task_table_index: '010' },
351-
{ contest_id: 'typical90', task_id: 'typical90_ck', task_table_index: '089' },
352-
{ contest_id: 'typical90', task_id: 'typical90_cl', task_table_index: '090' },
353327
];
354-
355-
const headerIds = provider.getHeaderIdsForTask(mockTypical90Tasks as any);
328+
const filtered = provider.filter(taskResults as TaskResults);
329+
const headerIds = provider.getHeaderIdsForTask(filtered as TaskResults);
356330

357331
expect(headerIds).toEqual(['001', '002', '003', '004', '005', '010', '089', '090']);
358332
});
359333

360334
test('expects to handle empty task results', () => {
361335
const provider = new Typical90Provider(ContestType.TYPICAL90);
362-
const filtered = provider.filter([]);
336+
const filtered = provider.filter([] as TaskResults);
363337

364338
expect(filtered).toEqual([]);
365339
});
@@ -749,8 +723,8 @@ describe('prepareContestProviderPresets', () => {
749723
expect(typeof presets.ABCLatest20Rounds).toBe('function');
750724
expect(typeof presets.ABC319Onwards).toBe('function');
751725
expect(typeof presets.ABC212ToABC318).toBe('function');
752-
expect(typeof presets.dps).toBe('function');
753726
expect(typeof presets.Typical90).toBe('function');
727+
expect(typeof presets.dps).toBe('function');
754728
});
755729

756730
test('expects each preset to create independent instances', () => {

src/test/lib/utils/test_cases/contest_table_provider.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ function createTaskResultWithTaskTableIndex(
7575
*/
7676
const createContestTasks = (
7777
contestId: string,
78-
taskConfigs: Array<{ taskTableIndex: string; statusName: string }>,
78+
taskConfigs: Array<{ taskId?: string; taskTableIndex: string; statusName: string }>,
7979
) => {
8080
return taskConfigs.map((config) => {
81-
const taskId = `${contestId}_${config.taskTableIndex.toLowerCase()}`;
81+
const taskId = config.taskId || `${contestId}_${config.taskTableIndex.toLowerCase()}`;
8282

8383
return createTaskResultWithTaskTableIndex(
8484
contestId,
@@ -125,6 +125,17 @@ const [abc319_a, abc319_b, abc319_c, abc319_d, abc319_e, abc319_f, abc319_g] = c
125125
],
126126
);
127127

128+
// Typical 90 Problems: 6 tasks (001, 002, 003, 010, 089 and 090)
129+
const [typical90_001, typical90_002, typical90_003, typical90_010, typical90_089, typical90_090] =
130+
createContestTasks('typical90', [
131+
{ taskId: 'typical90_a', taskTableIndex: '001', statusName: AC },
132+
{ taskId: 'typical90_b', taskTableIndex: '002', statusName: TRYING },
133+
{ taskId: 'typical90_c', taskTableIndex: '003', statusName: PENDING },
134+
{ taskId: 'typical90_j', taskTableIndex: '010', statusName: AC },
135+
{ taskId: 'typical90_ck', taskTableIndex: '089', statusName: TRYING },
136+
{ taskId: 'typical90_cl', taskTableIndex: '090', statusName: PENDING },
137+
]);
138+
128139
/**
129140
* Creates an array of contest task results with sequential contest numbers.
130141
*
@@ -228,4 +239,10 @@ export const taskResultsForContestTableProvider: TaskResults = [
228239
abc395_g,
229240
abc396_g,
230241
abc397_g,
242+
typical90_001,
243+
typical90_002,
244+
typical90_003,
245+
typical90_010,
246+
typical90_089,
247+
typical90_090,
231248
];

0 commit comments

Comments
 (0)