Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ransome1 committed Apr 1, 2024
1 parent 01dd168 commit 97864c9
Show file tree
Hide file tree
Showing 28 changed files with 355 additions and 391 deletions.
28 changes: 14 additions & 14 deletions src/__tests__/__mock__/recurrence.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

2024-03-16 Line 1 rec:1d due:2024-03-17
2024-03-16 Line 1 rec:w due:2024-03-23
2024-03-16 Line 1 rec:2m due:2024-05-16
2024-03-16 Line 1 rec:+1d due:2024-03-18
2024-03-16 Line 1 rec:7w due:2024-05-04
2024-03-16 Line 1 due:2023-07-24 rec:+1b
2024-03-16 taxes are due in one year t:2022-03-30 due:2022-04-30 rec:+1y
2024-03-16 Water plants @home +quick due:2024-03-23 t:2024-03-13 rec:1w
2024-03-16 Line 1 rec:+1d t:2023-09-20
2024-03-16 Line 1 rec:1d pri:A due:2024-03-17
2024-03-16 (A) Do something rec:d t:2024-03-17 @SomeContext
2024-03-16 Do something rec:0d
2024-03-16 Do something rec:0d due:2024-03-16
2024-03-16 Do something rec:0d due:2024-03-16 t:2024-03-16
2024-04-01 Line 1 rec:1d due:2024-04-02
2024-04-01 Line 1 rec:w due:2024-04-08
2024-04-01 Line 1 rec:2m due:2024-06-01
2024-04-01 Line 1 rec:+1d due:2024-04-03
2024-04-01 Line 1 rec:7w due:2024-05-20
2024-04-01 Line 1 due:2023-07-24 rec:+1b
2024-04-01 taxes are due in one year t:2022-03-30 due:2022-04-30 rec:+1y
2024-04-01 Water plants @home +quick due:2024-04-08 t:2024-03-29 rec:1w
2024-04-01 Line 1 rec:+1d t:2023-09-20
2024-04-01 Line 1 rec:1d pri:A due:2024-04-02
2024-04-01 (A) Do something rec:d t:2024-04-02 @SomeContext
2024-04-01 Do something rec:0d
2024-04-01 Do something rec:0d due:2024-04-01
2024-04-01 Do something rec:0d due:2024-04-01 t:2024-04-01
13 changes: 3 additions & 10 deletions src/__tests__/__mock__/test.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
Line 1
Edited line
Multi line 1Multi line 2Multi line 3
Updated line
Append 1
Append 2
New line with relative threshold date t:June 3rd, 2005
Line4
Line5
Line6
Multi line 1Multi line 2Multi line 3
Line 2
Line 3
New line
8 changes: 4 additions & 4 deletions src/__tests__/main/ChangeCompleteState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ describe('Marking todo as complete and vice versa', () => {
jest.clearAllMocks();
});

test('Unfinished todo is being marked as complete', async () => {
const updatedTodoObject = await changeCompleteState('(C) +testProject5 test0 @testContext due:2023-01-02', true);
test('Unfinished todo is being marked as complete', () => {
const updatedTodoObject = changeCompleteState('(C) +testProject5 test0 @testContext due:2023-01-02', true);
expect(updatedTodoObject?.toString()).toEqual('x ' + date + ' ' + date + ' +testProject5 test0 @testContext due:2023-01-02 pri:C');
});

test('Finished todo is being marked as incomplete', async () => {
const updatedTodoObject = await changeCompleteState('x 2023-07-06 2023-07-01 +testProject2 test1 @testContext due:2023-12-12 pri:C', false);
test('Finished todo is being marked as incomplete', () => {
const updatedTodoObject = changeCompleteState('x 2023-07-06 2023-07-01 +testProject2 test1 @testContext due:2023-12-12 pri:C', false);
expect(updatedTodoObject?.toString()).toEqual('(C) 2023-07-01 +testProject2 test1 @testContext due:2023-12-12 pri:C');
});

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/main/CreateRecurringTodo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRecurringTodo } from '../../main/modules/ProcessDataRequest/Creat
import dayjs from 'dayjs';

jest.mock('../../main/modules/ProcessDataRequest/CreateTodoObjects', () => ({
lines: [''],
linesInFile: [''],
}));

jest.mock('../../main/config', () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/main/Date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { extractSpeakingDates, replaceSpeakingDatesWithAbsoluteDates } from '../
import dayjs from 'dayjs';

jest.mock('../../main/modules/File/Write', () => ({
writeTodoObjectToFile: jest.fn(),
writeContentToFile: jest.fn(),
}));

jest.mock('../../main/config', () => ({
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/main/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('createFile', () => {
jest.clearAllMocks();
});

it('should call addFile after successfully creating a file', async () => {
it('should call addFile after successfully creating a file', async() => {
(dialog.showSaveDialog as jest.Mock).mockResolvedValueOnce({
canceled: false,
filePath: './src/__tests__/__mock__/fileDialog.txt',
Expand All @@ -90,11 +90,11 @@ describe('createFile', () => {
filters: [{ name: 'Text files', extensions: ['txt'] }, { name: 'All files', extensions: ['*'] }],
});

expect(fs.writeFile).toHaveBeenCalledWith('./src/__tests__/__mock__/fileDialog.txt', '');
expect(fs.writeFile).toHaveBeenCalledWith('./src/__tests__/__mock__/fileDialog.txt', '', 'utf8');
expect(addFile).toHaveBeenCalledWith('./src/__tests__/__mock__/fileDialog.txt', null);
});

it('should not call addFile when file creation is canceled', async () => {
it('should not call addFile when file creation is canceled', async() => {
(dialog.showSaveDialog as jest.Mock).mockResolvedValueOnce({
canceled: true,
filePath: undefined,
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/main/Filters.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applyFilters } from '../../main/modules/Filters/Filters';
import { applyAttributes } from '../../main/modules/Filters/Filters';

describe('Should filter todos based on passed filters', () => {
const todoObjects = [
Expand All @@ -9,7 +9,7 @@ describe('Should filter todos based on passed filters', () => {

test('should return all todo objects if no filters are provided', () => {
const filters = null;
const result = applyFilters(todoObjects, filters);
const result = applyAttributes(todoObjects, filters);
expect(result).toEqual(todoObjects);
});

Expand All @@ -22,7 +22,7 @@ describe('Should filter todos based on passed filters', () => {
{ id: 2, body: 'Test', created: null, complete: true, completed: null, priority: null, contexts: null, projects: ['Project 2'], due: '2023-02-01', dueString: '2023-02-01', t: null, tString: null, rec: null, hidden: false, pm: null, visible: false, string: '' },
{ id: 3, body: 'Test', created: null, complete: false, completed: null, priority: null, contexts: null, projects: ['Project 1'], due: '2023-03-01', dueString: '2023-03-01', t: null, tString: null, rec: null, hidden: false, pm: null, visible: true, string: '' },
];
const result = applyFilters(todoObjects, filters);
const result = applyAttributes(todoObjects, filters);
expect(result).toEqual(expected);
});

Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/main/ProcessTodoObjects.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs/promises';
import { createTodoObjects } from '../../main/modules/ProcessDataRequest/CreateTodoObjects';
import { applySearchString, countTodoObjects, sortAndGroupTodoObjects, flattenTodoObjects } from '../../main/modules/ProcessDataRequest/ProcessTodoObjects';
import { applySearchString } from '../../main/modules/Filters/Search';
import { countTodoObjects, sortAndGroupTodoObjects, flattenTodoObjects } from '../../main/modules/ProcessDataRequest/ProcessTodoObjects';

jest.mock('../../main/config', () => ({
config: {
Expand Down
Loading

0 comments on commit 97864c9

Please sign in to comment.