Skip to content

Commit

Permalink
Refactored Sugar implementation, fixed and added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ransome1 committed Aug 27, 2023
1 parent 4b99863 commit bb418af
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 323 deletions.
File renamed without changes.
157 changes: 0 additions & 157 deletions assets/.$architecture.drawio.bkp

This file was deleted.

8 changes: 4 additions & 4 deletions src/__tests__/__mock__/recurrence.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

2023-08-26 Line 1 rec:1d due:2023-08-27
2023-08-26 Line 1 rec:2m due:2023-10-26
2023-08-26 Line 1 rec:+1d due:2023-08-28
2023-08-26 Line 1 rec:7w due:2023-10-14
2023-08-27 Line 1 rec:1d due:2023-08-28
2023-08-27 Line 1 rec:2m due:2023-10-27
2023-08-27 Line 1 rec:+1d due:2023-08-29
2023-08-27 Line 1 rec:7w due:2023-10-15
2023-07-21 Line 1 rec:+1b due:2023-07-24
2 changes: 1 addition & 1 deletion src/__tests__/__mock__/test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Line 1
Edited line
New line
2023-08-26 New line with creation date
2023-08-27 New line with creation date
68 changes: 60 additions & 8 deletions src/__tests__/main/CreateTodoObjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,41 @@ jest.mock('../../main/config', () => ({
},
}));

const fileContent = `(B) Test +project @context todo 1 due:2023-12-31 t:2024-03-24 h:1 test @anotherContext pm:4 and a strict rec:+2w\nx 2023-07-23 2023-07-21 Test todo 2\nTest todo 3 due:end of the year\nTest todo 4 t:first day of next year\n`;
const todoObjects = createTodoObjects(fileContent);

describe('Create todo objects', () => {

beforeEach(() => {
jest.clearAllMocks();
});

test('should create todo objects from file content', () => {
const fileContent = `(B) Test +project @context todo 1 due:2022-12-31 t:2024-03-24 h:1 test @anotherContext pm:4 and a strict rec:+2w\nx 2023-07-23 2023-07-21 Test todo 2\n`;
const todoObjects = createTodoObjects(fileContent);

expect(todoObjects).toHaveLength(2);
test('should create 4 todo objects', () => {
expect(todoObjects).toHaveLength(4);
});
test('should create a todo object', () => {
expect(todoObjects[0]).toEqual({
id: 0,
body: 'Test +project @context todo 1 due:2022-12-31 t:2024-03-24 h:1 test @anotherContext pm:4 and a strict rec:+2w',
body: 'Test +project @context todo 1 due:2023-12-31 t:2024-03-24 h:1 test @anotherContext pm:4 and a strict rec:+2w',
created: null,
complete: false,
completed: null,
priority: "B",
contexts: ['context', 'anotherContext'],
projects: ['project'],
due: '2022-12-31',
due: '2023-12-31',
dueString: '2023-12-31',
t: '2024-03-24',
tString: '2024-03-24',
rec: '+2w',
hidden: true,
pm: "4",
string: '(B) Test +project @context todo 1 due:2022-12-31 t:2024-03-24 h:1 test @anotherContext pm:4 and a strict rec:+2w',
string: '(B) Test +project @context todo 1 due:2023-12-31 t:2024-03-24 h:1 test @anotherContext pm:4 and a strict rec:+2w',
});
});

test('should create a finished todo object', () => {
expect(todoObjects[1]).toEqual({
id: 1,
body: 'Test todo 2',
Expand All @@ -47,11 +55,55 @@ describe('Create todo objects', () => {
contexts: [],
projects: [],
due: null,
dueString: null,
t: null,
tString: null,
rec: null,
hidden: false,
pm: null,
string: 'x 2023-07-23 2023-07-21 Test todo 2',
});
});

test('should create a todo object with speaking due date', () => {
expect(todoObjects[2]).toEqual({
id: 2,
body: 'Test todo 3 due:end of the year',
created: null,
complete: false,
completed: null,
priority: null,
contexts: [],
projects: [],
due: '2023-12-31',
dueString: 'end of the year',
t: null,
tString: null,
rec: null,
hidden: false,
pm: null,
string: 'Test todo 3 due:end of the year',
});
});

test('should create a todo object with speaking t date', () => {
expect(todoObjects[3]).toEqual({
id: 3,
body: 'Test todo 4 t:first day of next year',
created: null,
complete: false,
completed: null,
priority: null,
contexts: [],
projects: [],
due: null,
dueString: null,
t: '2024-01-01',
tString: 'first day of next year',
rec: null,
hidden: false,
pm: null,
string: 'Test todo 4 t:first day of next year',
});
});
});
Loading

0 comments on commit bb418af

Please sign in to comment.