Skip to content

Commit

Permalink
Removed some warning during row creation, added title tags to navigat…
Browse files Browse the repository at this point in the history
…ion items for mouseover descriptions, removed Type warnings and errors from render components, switched peggy to Typescript, got eslint to work.
  • Loading branch information
ransome1 committed Jan 17, 2025
1 parent ea74a5e commit b2033ba
Show file tree
Hide file tree
Showing 97 changed files with 8,614 additions and 7,393 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
out
.gitignore
15 changes: 15 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'@electron-toolkit/eslint-config-ts/recommended',
'@electron-toolkit/eslint-config-prettier'
],
rules: {
// Disable prop-types globally since you're using TypeScript
'react/prop-types': 'off',
// If you want to enforce explicit return types on functions in TypeScript
'@typescript-eslint/explicit-function-return-type': 'warn' // Or 'error' if you prefer stricter rules
}
}
8 changes: 3 additions & 5 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { resolve } from 'path'
import react from '@vitejs/plugin-react'

export default {
main: {
},
preload: {
},
main: {},
preload: {},
renderer: {
resolve: {
alias: {
Expand All @@ -14,4 +12,4 @@ export default {
},
plugins: [react()]
}
}
}
9 changes: 0 additions & 9 deletions eslint.config.js

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"type": "module",
"scripts": {
"format": "prettier --write .",
"lint": "eslint ./src --fix",
"lint": "eslint ./src/renderer --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
"typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false",
"typecheck:web": "tsc --noEmit -p tsconfig.web.json --composite false",
"typecheck": "yarn typecheck:node && yarn typecheck:web",
Expand All @@ -40,7 +40,7 @@
"build:unpack": "yarn build && electron-builder --dir",
"mas": "yarn build && electron-builder build -m mas --universal --publish never",
"masdev": "yarn build && electron-builder build -m mas-dev --universal --publish never",
"peggy": "peggy --format es --output ./src/main/modules/Filters/FilterLang.js ./src/main/modules/Filters/FilterLang.pegjs"
"peggy": "peggy --format es --dts --output ./src/main/modules/Filters/FilterLang.ts ./src/main/modules/Filters/FilterLang.pegjs"
},
"dependencies": {
"@emotion/react": "^11.13.5",
Expand Down Expand Up @@ -70,11 +70,12 @@
"@types/node": "^22.10.6",
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"@typescript-eslint/parser": "^8.20.0",
"@vitejs/plugin-react": "^4.3.1",
"electron": "^34.0.0",
"electron-builder": "^25.1.8",
"electron-vite": "^2.3.0",
"eslint": "^9.18.0",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.3",
"material-ui-popup-state": "^5.3.3",
"peggy": "^4.2.0",
Expand Down
26 changes: 13 additions & 13 deletions src/__tests__/main/Active.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import { getActiveFile } from '../../main/modules/File/Active';
import { getActiveFile } from '../../main/modules/File/Active'

jest.mock('../../main/config', () => ({
config: {
get: jest.fn((key) => {
if(key === 'files') {
if (key === 'files') {
return [
{
active: false,
todoFileName: 'test1.txt',
todoFilePath: '/test1.txt',
todoFileBookmark: null,
doneFilePath: 'done.txt',
doneFileBookmark: null,
doneFileBookmark: null
},
{
active: true,
todoFileName: 'test2.txt',
todoFilePath: '/test2.txt',
todoFileBookmark: null,
doneFilePath: 'done.txt',
doneFileBookmark: null,
doneFileBookmark: null
}
];
]
}
}),
set: jest.fn(),
},
}));
set: jest.fn()
}
}))

describe('Get active file', () => {
test('Should return the active file', () => {
const activeFile = getActiveFile();
const activeFile = getActiveFile()
expect(activeFile).toEqual({
active: true,
todoFileName: 'test2.txt',
todoFilePath: '/test2.txt',
todoFileBookmark: null,
doneFilePath: 'done.txt',
doneFileBookmark: null,
});
});
});
doneFileBookmark: null
})
})
})
97 changes: 63 additions & 34 deletions src/__tests__/main/Archive.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,82 @@
import { archiveTodos } from '../../main/modules/File/Archive';
import fs from 'fs';
import { archiveTodos } from '../../main/modules/File/Archive'
import fs from 'fs'

jest.mock('electron', () => ({
app: {
setBadgeCount: jest.fn(),
},
}));
setBadgeCount: jest.fn()
}
}))

jest.mock('../../main/main', () => ({
mainWindow: {
webContents: {
send: jest.fn(),
},
},
}));
send: jest.fn()
}
}
}))

jest.mock('../../main/config', () => ({
config: {
get: jest.fn(() => {
return [
{ active: false, todoFilePath: './src/__tests__/__mock__/test1.txt', todoFileName: 'test1.txt', todoFileBookmark: null, doneFilePath: './src/__tests__/__mock__/done.txt', doneFileBookmark: null },
{ active: true, todoFilePath: './src/__tests__/__mock__/archiving.txt', todoFileName: 'archiving.txt', todoFileBookmark: null, doneFilePath: './src/__tests__/__mock__/done.txt', doneFileBookmark: null },
{ active: false, todoFilePath: './src/__tests__/__mock__/test3.txt', todoFileName: 'test3.txt', todoFileBookmark: null, doneFilePath: './src/__tests__/__mock__/done.txt', doneFileBookmark: null },
];
{
active: false,
todoFilePath: './src/__tests__/__mock__/test1.txt',
todoFileName: 'test1.txt',
todoFileBookmark: null,
doneFilePath: './src/__tests__/__mock__/done.txt',
doneFileBookmark: null
},
{
active: true,
todoFilePath: './src/__tests__/__mock__/archiving.txt',
todoFileName: 'archiving.txt',
todoFileBookmark: null,
doneFilePath: './src/__tests__/__mock__/done.txt',
doneFileBookmark: null
},
{
active: false,
todoFilePath: './src/__tests__/__mock__/test3.txt',
todoFileName: 'test3.txt',
todoFileBookmark: null,
doneFilePath: './src/__tests__/__mock__/done.txt',
doneFileBookmark: null
}
]
}),
set: jest.fn(),
},
}));
set: jest.fn()
}
}))

jest.mock('../../main/modules/Menu', () => ({
createMenu: jest.fn(),
}));
createMenu: jest.fn()
}))

describe('Archiving', () => {
beforeEach(() => {
jest.clearAllMocks();
fs.writeFileSync('./src/__tests__/__mock__/archiving.txt', `Unfinished todo 1\nx 2022-02-01 Finished todo 3\nUnfinished todo 2\nx 2022-02-08 Finished todo 1\nUnfinished todo 3\nx 2022-02-17 Finished todo 2`, 'utf8');
fs.writeFileSync('./src/__tests__/__mock__/done.txt', `x 2022-02-02 todo from done.txt 1\nx 2022-02-03 todo from done.txt 2\nx 2022-02-04 todo from done.txt 3\nx 2022-02-05 todo from done.txt 4`, 'utf8');
});
beforeEach(() => {
jest.clearAllMocks()
fs.writeFileSync(
'./src/__tests__/__mock__/archiving.txt',
`Unfinished todo 1\nx 2022-02-01 Finished todo 3\nUnfinished todo 2\nx 2022-02-08 Finished todo 1\nUnfinished todo 3\nx 2022-02-17 Finished todo 2`,
'utf8'
)
fs.writeFileSync(
'./src/__tests__/__mock__/done.txt',
`x 2022-02-02 todo from done.txt 1\nx 2022-02-03 todo from done.txt 2\nx 2022-02-04 todo from done.txt 3\nx 2022-02-05 todo from done.txt 4`,
'utf8'
)
})

afterAll(() => {
fs.unlinkSync('./src/__tests__/__mock__/archiving.txt');
fs.unlinkSync('./src/__tests__/__mock__/done.txt');
});
afterAll(() => {
fs.unlinkSync('./src/__tests__/__mock__/archiving.txt')
fs.unlinkSync('./src/__tests__/__mock__/done.txt')
})

test('Should collect data from todo and done file and merge it properly', () => {
archiveTodos();
const fileContent = fs.readFileSync('./src/__tests__/__mock__/done.txt', 'utf8');
const expectedContent = `x 2022-02-02 todo from done.txt 1\nx 2022-02-03 todo from done.txt 2\nx 2022-02-04 todo from done.txt 3\nx 2022-02-05 todo from done.txt 4\nx 2022-02-01 Finished todo 3\nx 2022-02-08 Finished todo 1\nx 2022-02-17 Finished todo 2`;
setTimeout(() => expect(fileContent).toEqual(expectedContent), 1000);
});
});
test('Should collect data from todo and done file and merge it properly', () => {
archiveTodos()
const fileContent = fs.readFileSync('./src/__tests__/__mock__/done.txt', 'utf8')
const expectedContent = `x 2022-02-02 todo from done.txt 1\nx 2022-02-03 todo from done.txt 2\nx 2022-02-04 todo from done.txt 3\nx 2022-02-05 todo from done.txt 4\nx 2022-02-01 Finished todo 3\nx 2022-02-08 Finished todo 1\nx 2022-02-17 Finished todo 2`
setTimeout(() => expect(fileContent).toEqual(expectedContent), 1000)
})
})
124 changes: 101 additions & 23 deletions src/__tests__/main/Attributes.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,86 @@
import { attributes, updateAttributes } from '../../main/modules/Attributes';
import { attributes, updateAttributes } from '../../main/modules/Attributes'

const todoObjects = [
{ lineNumber: 1, created: null, priority: 'A', projects: ['Project 1'], contexts: ['Context 1'], due: '2023-01-01', dueString: '2023-01-01', complete: false, completed: null, t: '2024-02-01', tString: '2024-02-01', rec: null, pm: null, body: null, hidden: false, string: '', notify: false, },
{ lineNumber: 2, created: '2026-01-01', priority: null, projects: ['Project 2'], contexts: null, due: '2023-02-01', dueString: '2023-02-01', complete: false, completed: null, t: null, tString: null, rec: null, pm: null, body: null, hidden: false, string: '', notify: false, },
{ lineNumber: 3, created: null, priority: null, projects: ['Project 1'], contexts: null, due: '2023-03-01', dueString: '2023-03-01', complete: false, completed: null, t: null, tString: null, rec: '2b', pm: null, body: null, hidden: false, string: '', notify: true, },
{ lineNumber: 4, created: '2026-01-01', priority: 'C', projects: ['Project 2'], contexts: ['Context 1'], due: '2023-04-01', dueString: '2023-04-01', complete: false, completed: null, t: '2024-02-01', tString: '2024-02-01', rec: null, pm: null, body: null, hidden: false, string: '', notify: false, },
];
{
lineNumber: 1,
created: null,
priority: 'A',
projects: ['Project 1'],
contexts: ['Context 1'],
due: '2023-01-01',
dueString: '2023-01-01',
complete: false,
completed: null,
t: '2024-02-01',
tString: '2024-02-01',
rec: null,
pm: null,
body: null,
hidden: false,
string: '',
notify: false
},
{
lineNumber: 2,
created: '2026-01-01',
priority: null,
projects: ['Project 2'],
contexts: null,
due: '2023-02-01',
dueString: '2023-02-01',
complete: false,
completed: null,
t: null,
tString: null,
rec: null,
pm: null,
body: null,
hidden: false,
string: '',
notify: false
},
{
lineNumber: 3,
created: null,
priority: null,
projects: ['Project 1'],
contexts: null,
due: '2023-03-01',
dueString: '2023-03-01',
complete: false,
completed: null,
t: null,
tString: null,
rec: '2b',
pm: null,
body: null,
hidden: false,
string: '',
notify: true
},
{
lineNumber: 4,
created: '2026-01-01',
priority: 'C',
projects: ['Project 2'],
contexts: ['Context 1'],
due: '2023-04-01',
dueString: '2023-04-01',
complete: false,
completed: null,
t: '2024-02-01',
tString: '2024-02-01',
rec: null,
pm: null,
body: null,
hidden: false,
string: '',
notify: false
}
]

describe('Set of filters must create a respective set of attributes and its counts', () => {
test('Should create attributes based on todo objects', () => {

const sorting = [
{ id: '1', value: 'priority', invert: false },
{ id: '2', value: 'projects', invert: false },
Expand All @@ -19,22 +90,29 @@ describe('Set of filters must create a respective set of attributes and its coun
{ id: '6', value: 'completed', invert: false },
{ id: '7', value: 'created', invert: false },
{ id: '8', value: 'rec', invert: false },
{ id: '9', value: 'pm', invert: false },
];
{ id: '9', value: 'pm', invert: false }
]

const expectedAttributes = {
priority: { 'A': { count: 1, notify: false}, 'C': { count: 1, notify: false} },
projects: { 'Project 1': { count: 2, notify: false}, 'Project 2': { count: 2, notify: false} },
contexts: { 'Context 1': { count: 2, notify: false} },
due: { '2023-01-01': { count: 1, notify: false}, '2023-02-01': { count: 1, notify: false}, '2023-03-01': { count: 1, notify: true}, '2023-04-01': { count: 1, notify: false} },
t: { '2024-02-01': { count: 2, notify: false} },
rec: { '2b': { count: 1, notify: false} },
priority: { A: { count: 1, notify: false }, C: { count: 1, notify: false } },
projects: {
'Project 1': { count: 2, notify: false },
'Project 2': { count: 2, notify: false }
},
contexts: { 'Context 1': { count: 2, notify: false } },
due: {
'2023-01-01': { count: 1, notify: false },
'2023-02-01': { count: 1, notify: false },
'2023-03-01': { count: 1, notify: true },
'2023-04-01': { count: 1, notify: false }
},
t: { '2024-02-01': { count: 2, notify: false } },
rec: { '2b': { count: 1, notify: false } },
pm: {},
created: { '2026-01-01': { count: 2, notify: false} },
completed: {},
};
updateAttributes(todoObjects, sorting, false);
expect(attributes).toEqual(expectedAttributes);
});

});
created: { '2026-01-01': { count: 2, notify: false } },
completed: {}
}
updateAttributes(todoObjects, sorting, false)
expect(attributes).toEqual(expectedAttributes)
})
})
Loading

0 comments on commit b2033ba

Please sign in to comment.