Skip to content

Commit 9d98dbc

Browse files
committed
test: Remove repetitious tests to reduce work of adding new date fields
1 parent 075172c commit 9d98dbc

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

tests/TaskLineRenderer.test.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ describe('task line rendering - classes and data attributes', () => {
364364

365365
it('should render date component with its class and data attribute with "today" value', async () => {
366366
const today = DateParser.parseDate('today').format(TaskRegularExpressions.dateFormat);
367+
// This test ensures that all date fields are handled correctly.
367368
await testComponentClasses(`- [ ] Full task ⏫ ➕ ${today}`, 'task-created', 'taskCreated: today');
368369
await testComponentClasses(`- [ ] Full task ⏫ 📅 ${today}`, 'task-due', 'taskDue: today');
369370
await testComponentClasses(`- [ ] Full task ⏫ ⏳ ${today}`, 'task-scheduled', 'taskScheduled: today');
@@ -372,64 +373,36 @@ describe('task line rendering - classes and data attributes', () => {
372373
await testComponentClasses(`- [-] Canc task ❌ ${today}`, 'task-cancelled', 'taskCancelled: today');
373374
});
374375

376+
// Now that we know that 'today' is correctly added to all date fields, the remaining tests
377+
// only need to test a single date field.
375378
it('should render date component with its class and data attribute with "future-1d" value', async () => {
376379
const future = DateParser.parseDate('tomorrow').format(TaskRegularExpressions.dateFormat);
377-
await testComponentClasses(`- [ ] Full task ⏫ ➕ ${future}`, 'task-created', 'taskCreated: future-1d');
378380
await testComponentClasses(`- [ ] Full task ⏫ 📅 ${future}`, 'task-due', 'taskDue: future-1d');
379-
await testComponentClasses(`- [ ] Full task ⏫ ⏳ ${future}`, 'task-scheduled', 'taskScheduled: future-1d');
380-
await testComponentClasses(`- [ ] Full task ⏫ 🛫 ${future}`, 'task-start', 'taskStart: future-1d');
381-
await testComponentClasses(`- [x] Done task ✅ ${future}`, 'task-done', 'taskDone: future-1d');
382-
await testComponentClasses(`- [-] Canc task ❌ ${future}`, 'task-cancelled', 'taskCancelled: future-1d');
383381
});
384382

385383
it('should render date component with its class and data attribute with "future-7d" value', async () => {
386384
const future = DateParser.parseDate('in 7 days').format(TaskRegularExpressions.dateFormat);
387-
await testComponentClasses(`- [ ] Full task ⏫ ➕ ${future}`, 'task-created', 'taskCreated: future-7d');
388385
await testComponentClasses(`- [ ] Full task ⏫ 📅 ${future}`, 'task-due', 'taskDue: future-7d');
389-
await testComponentClasses(`- [ ] Full task ⏫ ⏳ ${future}`, 'task-scheduled', 'taskScheduled: future-7d');
390-
await testComponentClasses(`- [ ] Full task ⏫ 🛫 ${future}`, 'task-start', 'taskStart: future-7d');
391-
await testComponentClasses(`- [x] Done task ✅ ${future}`, 'task-done', 'taskDone: future-7d');
392-
await testComponentClasses(`- [-] Canc task ❌ ${future}`, 'task-cancelled', 'taskCancelled: future-7d');
393386
});
394387

395388
it('should render date component with its class and data attribute with "past-1d" value', async () => {
396389
const past = DateParser.parseDate('yesterday').format(TaskRegularExpressions.dateFormat);
397-
await testComponentClasses(`- [ ] Full task ⏫ ➕ ${past}`, 'task-created', 'taskCreated: past-1d');
398390
await testComponentClasses(`- [ ] Full task ⏫ 📅 ${past}`, 'task-due', 'taskDue: past-1d');
399-
await testComponentClasses(`- [ ] Full task ⏫ ⏳ ${past}`, 'task-scheduled', 'taskScheduled: past-1d');
400-
await testComponentClasses(`- [ ] Full task ⏫ 🛫 ${past}`, 'task-start', 'taskStart: past-1d');
401-
await testComponentClasses(`- [x] Done task ✅ ${past}`, 'task-done', 'taskDone: past-1d');
402-
await testComponentClasses(`- [-] Canc task ❌ ${past}`, 'task-cancelled', 'taskCancelled: past-1d');
403391
});
404392

405393
it('should render date component with its class and data attribute with "past-7d" value', async () => {
406394
const past = DateParser.parseDate('7 days ago').format(TaskRegularExpressions.dateFormat);
407-
await testComponentClasses(`- [ ] Full task ⏫ ➕ ${past}`, 'task-created', 'taskCreated: past-7d');
408395
await testComponentClasses(`- [ ] Full task ⏫ 📅 ${past}`, 'task-due', 'taskDue: past-7d');
409-
await testComponentClasses(`- [ ] Full task ⏫ ⏳ ${past}`, 'task-scheduled', 'taskScheduled: past-7d');
410-
await testComponentClasses(`- [ ] Full task ⏫ 🛫 ${past}`, 'task-start', 'taskStart: past-7d');
411-
await testComponentClasses(`- [x] Done task ✅ ${past}`, 'task-done', 'taskDone: past-7d');
412-
await testComponentClasses(`- [-] Canc task ❌ ${past}`, 'task-cancelled', 'taskCancelled: past-7d');
413396
});
414397

415398
it('should render date component with its class and data attribute with "future-far"', async () => {
416399
const future = DateParser.parseDate('in 8 days').format(TaskRegularExpressions.dateFormat);
417-
await testComponentClasses(`- [ ] Full task ⏫ ➕ ${future}`, 'task-created', 'taskCreated: future-far');
418400
await testComponentClasses(`- [ ] Full task ⏫ 📅 ${future}`, 'task-due', 'taskDue: future-far');
419-
await testComponentClasses(`- [ ] Full task ⏫ ⏳ ${future}`, 'task-scheduled', 'taskScheduled: future-far');
420-
await testComponentClasses(`- [ ] Full task ⏫ 🛫 ${future}`, 'task-start', 'taskStart: future-far');
421-
await testComponentClasses(`- [x] Done task ✅ ${future}`, 'task-done', 'taskDone: future-far');
422-
await testComponentClasses(`- [-] Canc task ❌ ${future}`, 'task-cancelled', 'taskCancelled: future-far');
423401
});
424402

425403
it('should render date component with its class and data attribute with "past-far" values', async () => {
426404
const past = DateParser.parseDate('8 days ago').format(TaskRegularExpressions.dateFormat);
427-
await testComponentClasses(`- [ ] Full task ⏫ ➕ ${past}`, 'task-created', 'taskCreated: past-far');
428405
await testComponentClasses(`- [ ] Full task ⏫ 📅 ${past}`, 'task-due', 'taskDue: past-far');
429-
await testComponentClasses(`- [ ] Full task ⏫ ⏳ ${past}`, 'task-scheduled', 'taskScheduled: past-far');
430-
await testComponentClasses(`- [ ] Full task ⏫ 🛫 ${past}`, 'task-start', 'taskStart: past-far');
431-
await testComponentClasses(`- [x] Done task ✅ ${past}`, 'task-done', 'taskDone: past-far');
432-
await testComponentClasses(`- [-] Canc task ❌ ${past}`, 'task-cancelled', 'taskCancelled: past-far');
433406
});
434407

435408
it('should not add data attributes for invalid dates', async () => {

0 commit comments

Comments
 (0)