diff --git a/.claude/skills/commit.md b/.claude/skills/commit.md index 32810bc..9eaff50 100644 --- a/.claude/skills/commit.md +++ b/.claude/skills/commit.md @@ -20,6 +20,7 @@ When using Claude Code to commit changes: ## Examples ### Initial Commit + ```bash git add src/components/NewFeature.tsx make commit @@ -29,6 +30,7 @@ make commit ``` ### Amend Commit + ```bash git commit --amend # Edit the commit message to add: @@ -42,4 +44,4 @@ git commit --amend - Keep subject line under 50 characters - Use body to explain "why" not just "what" - Reference related issues if applicable -- Ensure commit passes linting and tests before pushing \ No newline at end of file +- Ensure commit passes linting and tests before pushing diff --git a/jest.js b/jest.js index ce9bb7e..521fa43 100644 --- a/jest.js +++ b/jest.js @@ -1,17 +1,24 @@ import '@localization/config'; // import './__mocks__/zustand'; +if (typeof localStorage !== 'undefined') { + localStorage.clear(); +} jest.useFakeTimers(); jest.mock('zustand'); // Mocking Date -class MockDate extends Date { - constructor() { - super('2020-05-14T11:01:58.135'); // add whatever date you'll expect to get +const RealDate = Date; +class MockDate extends RealDate { + constructor(date) { + if (date) return new RealDate(date); + return new RealDate('2020-05-14T11:01:58.135Z'); } } +// @ts-ignore global.Date = MockDate; +Date.now = () => new RealDate('2020-05-14T11:01:58.135Z').getTime(); // Mocking Draft.js jest.mock('draft-js', () => ({ diff --git a/src/components/Window/__tests__/Windows.test.tsx b/src/components/Window/__tests__/Windows.test.tsx index 50b8908..9c2f197 100644 --- a/src/components/Window/__tests__/Windows.test.tsx +++ b/src/components/Window/__tests__/Windows.test.tsx @@ -1,24 +1,64 @@ import { fireEvent, render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; import Window from '../Window'; -import { ProgramType } from '@processStore'; +import { ProgramType, processStore, WindowSize } from '@processStore'; +import React from 'react'; +import { act } from '@testing-library/react-hooks'; + +// Shared variable to capture props +let capturedDraggableProps: any; +let capturedResizableProps: any; + +// Mock DraggableProvider and ResizableBox to trigger callbacks and capture props +jest.mock('@providers', () => ({ + DraggableProvider: (props: any) => { + capturedDraggableProps = props; + return ( +
- x -
-+ x +
++ - +
++ o +
+- x -
++ x +
++ - +
++ o +
+- - -
+- o -
++ x +
++ - +
++ o +
+- x -
-+ x +
++ - +
++ o +
+- x -
-+ x +
++ - +
++ o +
+- x -
-+ x +
++ - +
++ o +
++ All iCloud +
++ 0 + + notes +
++ ποΈ +
++ No notes yet +
++ ποΈ +
++ Select or create a note +
- Title + All iCloud
- 14/05/2020 -
- -> - Description -
+ 3 + + notes+ Pinned +
++ Grocery List π +
++ 4/19/25 +
++ Milk, Eggs, Bread... +
++ April +
++ New Note +
++ 4/20/25 +
++ Teaching Holistic Health π§ββοΈ +
++ 4/20/25 +
++ Brainstorm for first in-class session... +
++ 4/20/2025 + + at + + 10:00 AM +
++ 2 + + words +
++ Aa +
++ Pinned +
++ Grocery List π +
++ 4/19/25 +
++ Milk, Eggs, Bread... +
++ April +
++ Teaching Holistic Health π§ββοΈ +
++ 4/20/25 +
++ Brainstorm for first in-class session... +
++ 4/19/2025 + + at + + 03:30 PM +
++ 3 + + words +
++ All iCloud +
++ 2 + + notes +
++ Aa +
++ 4/19/2025 + + at + + 03:30 PM +
++ 3 + + words +
+- Title + All iCloud
- 14/05/2020 -
- -> - Description -
+ 2 + + notes- Title + Aa
-
+
+ 4/20/2025 + + at + + 10:00 AM +
++ 219 + + words +
+Amit Raikwar
Your password is required to enable Touch ID
@@ -406,11 +406,11 @@ exports[`UserLogin should show spinner on click on login button 1`] = `Amit Raikwar
Your password is required to enable Touch ID
diff --git a/src/store/appStore/selector/Notes/Notes.selector.ts b/src/store/appStore/selector/Notes/Notes.selector.ts index ab04587..e52ec34 100644 --- a/src/store/appStore/selector/Notes/Notes.selector.ts +++ b/src/store/appStore/selector/Notes/Notes.selector.ts @@ -1,12 +1,29 @@ import { AppStoreState } from '../../appStore'; -const notesSelector = (state: AppStoreState) => ({ - notes: state.Notes.notes, - getCurrentId: () => Object.keys(state.Notes.notes).length, - selectedNote: (id: string) => state.Notes.notes[id], - addNote: state.Notes.addNote, - deleteNote: state.Notes.deleteNote, - editNote: state.Notes.editNote, -}); +const notesSelector = (state: AppStoreState) => { + const notesList = Object.values(state.Notes.notes); + + // Pinned notes first, then both groups sorted by updatedAt desc + const byDate = ( + a: { updatedAt?: string; date: string }, + b: { updatedAt?: string; date: string }, + ) => + new Date(b.updatedAt ?? b.date).getTime() - + new Date(a.updatedAt ?? a.date).getTime(); + + const pinned = notesList.filter((n) => n.pinned).sort(byDate); + const unpinned = notesList.filter((n) => !n.pinned).sort(byDate); + + return { + notes: state.Notes.notes, + notesList: [...pinned, ...unpinned], + getCurrentId: () => Object.keys(state.Notes.notes).length, + selectedNote: (id: string) => state.Notes.notes[id], + addNote: state.Notes.addNote, + deleteNote: state.Notes.deleteNote, + editNote: state.Notes.editNote, + pinNote: state.Notes.pinNote, + }; +}; export { notesSelector }; diff --git a/src/store/appStore/selector/Notes/__tests__/Notes.selector.test.ts b/src/store/appStore/selector/Notes/__tests__/Notes.selector.test.ts index 7bf1804..ac29e94 100644 --- a/src/store/appStore/selector/Notes/__tests__/Notes.selector.test.ts +++ b/src/store/appStore/selector/Notes/__tests__/Notes.selector.test.ts @@ -1,126 +1,100 @@ import { renderHook } from '@testing-library/react-hooks'; import { appStore } from '../../../appStore'; import { notesSelector } from '../Notes.selector'; +import { act } from '@testing-library/react'; describe('Notes selector', () => { - it('should return default notes state', () => { + const setupNotes = (count = 6) => { const { result } = renderHook(() => appStore(notesSelector)); + act(() => { + for (let i = 1; i <= count; i++) { + result.current.addNote({ + id: `note-${i}`, + title: `Note ${i}`, + description: `Description ${i}`, + content: `