Skip to content

Commit 2008912

Browse files
committed
test: - Reduce test burden when adding new Task fields
The "show all component except one" pattern was becoming a bit of a burden when adding new components or changing their order. This changes the pattern to instead show one component at a time, which is rather more readable and easier to maintain.
1 parent 3c9383b commit 2008912

File tree

1 file changed

+37
-176
lines changed

1 file changed

+37
-176
lines changed

β€Žtests/TaskLineRenderer.test.ts

Lines changed: 37 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { DateParser } from '../src/Query/DateParser';
1010
import { QueryLayoutOptions } from '../src/QueryLayoutOptions';
1111
import type { Task } from '../src/Task';
1212
import { TaskRegularExpressions } from '../src/Task';
13-
import type { TaskLayoutComponent } from '../src/TaskLayout';
13+
import { type TaskLayoutComponent, taskLayoutComponents } from '../src/TaskLayout';
1414
import type { TextRenderer } from '../src/TaskLineRenderer';
1515
import { TaskLineRenderer } from '../src/TaskLineRenderer';
1616
import { fromLine } from './TestHelpers';
@@ -176,12 +176,23 @@ describe('task line rendering - global filter', () => {
176176
});
177177

178178
describe('task line rendering - layout options', () => {
179-
const testLayoutOptions = async (expectedComponents: string[], hiddenComponents: TaskLayoutComponent[]) => {
179+
const testLayoutOptions = async (expectedComponents: string[], shownComponents: TaskLayoutComponent[]) => {
180180
const task = TaskBuilder.createFullyPopulatedTask();
181181
const taskLayoutOptions = new TaskLayoutOptions();
182-
hiddenComponents.forEach((hiddenComponent) => {
183-
taskLayoutOptions.hide(hiddenComponent);
182+
183+
// Hide every layout component:
184+
taskLayoutComponents.forEach((component) => {
185+
taskLayoutOptions.hide(component);
184186
});
187+
188+
// Re-enable description
189+
taskLayoutOptions.setVisibility('description', true);
190+
191+
// Re-enable the requested components:
192+
shownComponents.forEach((hiddenComponent) => {
193+
taskLayoutOptions.setVisibility(hiddenComponent, true);
194+
});
195+
185196
const listItem = await renderListItem(task, taskLayoutOptions);
186197
const renderedComponents = getListItemComponents(listItem);
187198
expect(renderedComponents).toEqual(expectedComponents);
@@ -203,122 +214,32 @@ describe('task line rendering - layout options', () => {
203214
' πŸ†” abcdef',
204215
' ^dcf64c',
205216
],
206-
[],
217+
taskLayoutComponents,
207218
);
208219
});
209220

210-
it('renders without priority', async () => {
211-
await testLayoutOptions(
212-
[
213-
'Do exercises #todo #health',
214-
' πŸ” every day when done',
215-
' βž• 2023-07-01',
216-
' πŸ›« 2023-07-02',
217-
' ⏳ 2023-07-03',
218-
' πŸ“… 2023-07-04',
219-
' ❌ 2023-07-06',
220-
' βœ… 2023-07-05',
221-
' ⛔️ 123456,abc123',
222-
' πŸ†” abcdef',
223-
' ^dcf64c',
224-
],
225-
['priority'],
226-
);
221+
it('renders with priority', async () => {
222+
await testLayoutOptions(['Do exercises #todo #health', ' πŸ”Ό'], ['priority']);
227223
});
228224

229-
it('renders without recurrence rule', async () => {
230-
await testLayoutOptions(
231-
[
232-
'Do exercises #todo #health',
233-
' πŸ”Ό',
234-
' βž• 2023-07-01',
235-
' πŸ›« 2023-07-02',
236-
' ⏳ 2023-07-03',
237-
' πŸ“… 2023-07-04',
238-
' ❌ 2023-07-06',
239-
' βœ… 2023-07-05',
240-
' ⛔️ 123456,abc123',
241-
' πŸ†” abcdef',
242-
' ^dcf64c',
243-
],
244-
['recurrenceRule'],
245-
);
225+
it('renders with recurrence rule', async () => {
226+
await testLayoutOptions(['Do exercises #todo #health', ' πŸ” every day when done'], ['recurrenceRule']);
246227
});
247228

248-
it('renders without created date', async () => {
249-
await testLayoutOptions(
250-
[
251-
'Do exercises #todo #health',
252-
' πŸ”Ό',
253-
' πŸ” every day when done',
254-
' πŸ›« 2023-07-02',
255-
' ⏳ 2023-07-03',
256-
' πŸ“… 2023-07-04',
257-
' ❌ 2023-07-06',
258-
' βœ… 2023-07-05',
259-
' ⛔️ 123456,abc123',
260-
' πŸ†” abcdef',
261-
' ^dcf64c',
262-
],
263-
['createdDate'],
264-
);
229+
it('renders with created date', async () => {
230+
await testLayoutOptions(['Do exercises #todo #health', ' βž• 2023-07-01'], ['createdDate']);
265231
});
266232

267-
it('renders without start date', async () => {
268-
await testLayoutOptions(
269-
[
270-
'Do exercises #todo #health',
271-
' πŸ”Ό',
272-
' πŸ” every day when done',
273-
' βž• 2023-07-01',
274-
' ⏳ 2023-07-03',
275-
' πŸ“… 2023-07-04',
276-
' ❌ 2023-07-06',
277-
' βœ… 2023-07-05',
278-
' ⛔️ 123456,abc123',
279-
' πŸ†” abcdef',
280-
' ^dcf64c',
281-
],
282-
['startDate'],
283-
);
233+
it('renders with start date', async () => {
234+
await testLayoutOptions(['Do exercises #todo #health', ' πŸ›« 2023-07-02'], ['startDate']);
284235
});
285236

286-
it('renders without scheduled date', async () => {
287-
await testLayoutOptions(
288-
[
289-
'Do exercises #todo #health',
290-
' πŸ”Ό',
291-
' πŸ” every day when done',
292-
' βž• 2023-07-01',
293-
' πŸ›« 2023-07-02',
294-
' πŸ“… 2023-07-04',
295-
' ❌ 2023-07-06',
296-
' βœ… 2023-07-05',
297-
' ⛔️ 123456,abc123',
298-
' πŸ†” abcdef',
299-
' ^dcf64c',
300-
],
301-
['scheduledDate'],
302-
);
237+
it('renders with scheduled date', async () => {
238+
await testLayoutOptions(['Do exercises #todo #health', ' ⏳ 2023-07-03'], ['scheduledDate']);
303239
});
304240

305-
it('renders without due date', async () => {
306-
await testLayoutOptions(
307-
[
308-
'Do exercises #todo #health',
309-
' πŸ”Ό',
310-
' πŸ” every day when done',
311-
' βž• 2023-07-01',
312-
' πŸ›« 2023-07-02',
313-
' ⏳ 2023-07-03',
314-
' ❌ 2023-07-06',
315-
' βœ… 2023-07-05',
316-
' ⛔️ 123456,abc123',
317-
' πŸ†” abcdef',
318-
' ^dcf64c',
319-
],
320-
['dueDate'],
321-
);
241+
it('renders with due date', async () => {
242+
await testLayoutOptions(['Do exercises #todo #health', ' πŸ“… 2023-07-04'], ['dueDate']);
322243
});
323244

324245
it('renders a done task correctly with the default layout', async () => {
@@ -337,84 +258,24 @@ describe('task line rendering - layout options', () => {
337258
' πŸ†” abcdef',
338259
' ^dcf64c',
339260
],
340-
[],
261+
taskLayoutComponents,
341262
);
342263
});
343264

344-
it('renders without done date', async () => {
345-
await testLayoutOptions(
346-
[
347-
'Do exercises #todo #health',
348-
' πŸ”Ό',
349-
' πŸ” every day when done',
350-
' βž• 2023-07-01',
351-
' πŸ›« 2023-07-02',
352-
' ⏳ 2023-07-03',
353-
' πŸ“… 2023-07-04',
354-
' ❌ 2023-07-06',
355-
' ⛔️ 123456,abc123',
356-
' πŸ†” abcdef',
357-
' ^dcf64c',
358-
],
359-
['doneDate'],
360-
);
265+
it('renders with done date', async () => {
266+
await testLayoutOptions(['Do exercises #todo #health', ' βœ… 2023-07-05'], ['doneDate']);
361267
});
362268

363-
it('renders without cancelled date', async () => {
364-
await testLayoutOptions(
365-
[
366-
'Do exercises #todo #health',
367-
' πŸ”Ό',
368-
' πŸ” every day when done',
369-
' βž• 2023-07-01',
370-
' πŸ›« 2023-07-02',
371-
' ⏳ 2023-07-03',
372-
' πŸ“… 2023-07-04',
373-
' βœ… 2023-07-05',
374-
' ⛔️ 123456,abc123',
375-
' πŸ†” abcdef',
376-
' ^dcf64c',
377-
],
378-
['cancelledDate'],
379-
);
269+
it('renders with cancelled date', async () => {
270+
await testLayoutOptions(['Do exercises #todo #health', ' ❌ 2023-07-06'], ['cancelledDate']);
380271
});
381272

382-
it('renders without id', async () => {
383-
await testLayoutOptions(
384-
[
385-
'Do exercises #todo #health',
386-
' πŸ”Ό',
387-
' πŸ” every day when done',
388-
' βž• 2023-07-01',
389-
' πŸ›« 2023-07-02',
390-
' ⏳ 2023-07-03',
391-
' πŸ“… 2023-07-04',
392-
' ❌ 2023-07-06',
393-
' βœ… 2023-07-05',
394-
' ⛔️ 123456,abc123',
395-
' ^dcf64c',
396-
],
397-
['id'],
398-
);
273+
it('renders with id', async () => {
274+
await testLayoutOptions(['Do exercises #todo #health', ' πŸ†” abcdef'], ['id']);
399275
});
400276

401-
it('renders without depends on', async () => {
402-
await testLayoutOptions(
403-
[
404-
'Do exercises #todo #health',
405-
' πŸ”Ό',
406-
' πŸ” every day when done',
407-
' βž• 2023-07-01',
408-
' πŸ›« 2023-07-02',
409-
' ⏳ 2023-07-03',
410-
' πŸ“… 2023-07-04',
411-
' ❌ 2023-07-06',
412-
' βœ… 2023-07-05',
413-
' πŸ†” abcdef',
414-
' ^dcf64c',
415-
],
416-
['blockedBy'],
417-
);
277+
it('renders with depends on', async () => {
278+
await testLayoutOptions(['Do exercises #todo #health', ' ⛔️ 123456,abc123'], ['blockedBy']);
418279
});
419280

420281
const testLayoutOptionsFromLine = async (taskLine: string, expectedComponents: string[]) => {

0 commit comments

Comments
Β (0)