-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from bartkessels/feature/notes
Feature/notes
- Loading branch information
Showing
39 changed files
with
864 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createNoteUiModel, NoteUiModel } from 'src/components/models/note.ui-model'; | ||
import { Note } from 'src/domain/models/note'; | ||
import 'src/extensions/extensions'; | ||
|
||
describe('createNoteUiModel', () => { | ||
it('should create a NoteUiModel with the correct properties', () => { | ||
const note: Note = { | ||
path: 'path/to/note.md', | ||
name: 'note.md', | ||
createdOn: new Date('2023-10-01T00:00:00Z') | ||
}; | ||
|
||
const noteUiModel: NoteUiModel = createNoteUiModel(note); | ||
|
||
expect(noteUiModel.note).toBe(note); | ||
expect(noteUiModel.displayDate).toBe(note.createdOn.toLocaleTimeString()); | ||
expect(noteUiModel.displayName).toBe('note'); | ||
expect(noteUiModel.displayFilePath).toBe(note.path); | ||
}); | ||
|
||
it('should remove the markdown extension from the displayName', () => { | ||
const note: Note = { | ||
path: 'path/to/note.md', | ||
name: 'note.md', | ||
createdOn: new Date('2023-10-01T00:00:00Z') | ||
}; | ||
|
||
const noteUiModel: NoteUiModel = createNoteUiModel(note); | ||
|
||
expect(noteUiModel.displayName).toBe('note'); | ||
}); | ||
|
||
it('should format the displayDate correctly', () => { | ||
const note: Note = { | ||
path: 'path/to/note.md', | ||
name: 'note.md', | ||
createdOn: new Date(2023, 9, 2, 12, 23) | ||
}; | ||
|
||
const noteUiModel: NoteUiModel = createNoteUiModel(note); | ||
|
||
expect(noteUiModel.displayDate).toBe('12:23:00 PM'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Note} from 'src/domain/models/note'; | ||
|
||
export interface NoteUiModel { | ||
note: Note; | ||
displayDate: string; | ||
displayName: string; | ||
displayFilePath: string; | ||
} | ||
|
||
export function createNoteUiModel(note: Note): NoteUiModel { | ||
return <NoteUiModel>{ | ||
note: note, | ||
displayDate: note.createdOn.toLocaleTimeString(), | ||
displayName: note.name.removeMarkdownExtension(), | ||
displayFilePath: note.path | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import {renderHook} from '@testing-library/react'; | ||
import {Enhancer} from 'src/domain/enhancers/enhancer'; | ||
import {NoteUiModel} from 'src/components/models/note.ui-model'; | ||
import {NotesEnhancerContext, useNotesEnhancer} from './notes-enhancer.context'; | ||
|
||
describe('NotesEnhancerContext', () => { | ||
const mockEnhancer = { | ||
enhance: jest.fn() | ||
} as unknown as Enhancer<NoteUiModel[]>; | ||
|
||
it('provides the enhancer instance', () => { | ||
const wrapper = ({children}: { children: React.ReactNode }) => ( | ||
<NotesEnhancerContext.Provider value={mockEnhancer}> | ||
{children} | ||
</NotesEnhancerContext.Provider> | ||
); | ||
|
||
const {result} = renderHook(() => useNotesEnhancer(), {wrapper}); | ||
|
||
expect(result.current).toBe(mockEnhancer); | ||
}); | ||
|
||
it('returns null when no enhancer is provided', () => { | ||
const {result} = renderHook(() => useNotesEnhancer()); | ||
|
||
expect(result.current).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {createContext, useContext} from 'react'; | ||
import {Enhancer} from 'src/domain/enhancers/enhancer'; | ||
import {NoteUiModel} from 'src/components/models/note.ui-model'; | ||
|
||
export const NotesEnhancerContext = createContext<Enhancer<NoteUiModel[]> | null>(null); | ||
export const useNotesEnhancer = (): Enhancer<NoteUiModel[]> | null => { | ||
return useContext(NotesEnhancerContext); | ||
} |
Oops, something went wrong.