Skip to content

Commit 1de4416

Browse files
committed
test: Extract helper function to remove repetition
1 parent 27fb6bb commit 1de4416

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

β€Žtests/Task.test.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,45 +1134,37 @@ describe('order of recurring tasks', () => {
11341134
resetSettings();
11351135
});
11361136

1137-
it('should put new task before old, by default', () => {
1137+
function togglingInUsersOrderShouldGive(line: string, expectedLines: string[]) {
11381138
// Arrange
1139-
const task = fromLine({ line: '- [ ] this is a recurring task πŸ” every day' });
1139+
const task = fromLine({ line: line });
11401140

11411141
// Act
11421142
const lines = task.toggleWithRecurrenceInUsersOrder().map((t) => t.toFileLineString());
11431143

11441144
// Assert
1145-
expect(lines).toStrictEqual([
1145+
expect(lines).toStrictEqual(expectedLines);
1146+
}
1147+
1148+
it('should put new task before old, by default', () => {
1149+
togglingInUsersOrderShouldGive('- [ ] this is a recurring task πŸ” every day', [
11461150
'- [ ] this is a recurring task πŸ” every day',
11471151
'- [x] this is a recurring task πŸ” every day βœ… 2023-05-16',
11481152
]);
11491153
});
11501154

11511155
it('should honour new-task-before-old setting', () => {
1152-
// Arrange
11531156
updateSettings({ recurrenceOnNextLine: false });
1154-
const task = fromLine({ line: '- [ ] this is a recurring task πŸ” every day' });
1155-
1156-
// Act
1157-
const lines = task.toggleWithRecurrenceInUsersOrder().map((t) => t.toFileLineString());
11581157

1159-
// Assert
1160-
expect(lines).toStrictEqual([
1158+
togglingInUsersOrderShouldGive('- [ ] this is a recurring task πŸ” every day', [
11611159
'- [ ] this is a recurring task πŸ” every day',
11621160
'- [x] this is a recurring task πŸ” every day βœ… 2023-05-16',
11631161
]);
11641162
});
11651163

11661164
it('should honour old-task-before-new setting', () => {
1167-
// Arrange
11681165
updateSettings({ recurrenceOnNextLine: true });
1169-
const task = fromLine({ line: '- [ ] this is a recurring task πŸ” every day' });
11701166

1171-
// Act
1172-
const lines = task.toggleWithRecurrenceInUsersOrder().map((t) => t.toFileLineString());
1173-
1174-
// Assert
1175-
expect(lines).toStrictEqual([
1167+
togglingInUsersOrderShouldGive('- [ ] this is a recurring task πŸ” every day', [
11761168
'- [x] this is a recurring task πŸ” every day βœ… 2023-05-16',
11771169
'- [ ] this is a recurring task πŸ” every day',
11781170
]);

0 commit comments

Comments
Β (0)