diff --git a/src/types.ts b/src/types.ts index 91392c5..14331f2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,7 +17,6 @@ export interface IBookAnnotation { ZANNOTATIONCREATIONDATE: number; ZANNOTATIONMODIFICATIONDATE: number; ZANNOTATIONSTYLE: 0 | 1 | 2 | 3 | 4 | 5; - ZANNOTATIONDELETED: 0 | 1; } export interface IHighlight { diff --git a/test/mocks/aggregateWrappedTextBlockData.ts b/test/mocks/aggregateWrappedTextBlockData.ts deleted file mode 100644 index c0d068b..0000000 --- a/test/mocks/aggregateWrappedTextBlockData.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { ICombinedBooksAndHighlights } from "src/types" - -export const aggregateWrappedTextBlockData: ICombinedBooksAndHighlights = { - "bookTitle": "Apple iPhone - User Guide - Instructions - with - restricted - symbols - in - title", - "bookId": "THBFYNJKTGFTTVCGSAE5", - "bookAuthor": "Apple Inc.", - "bookGenre": "Technology", - "bookLanguage": "EN", - "bookLastOpenedDate": 731876693.002279, - "bookCoverUrl": '', - "annotations": [{ - "chapter": "Another aggregated Introduction", - "contextualText": "This is a contextual text for the aggregated hightlight from the Apple iPhone User Guide\ncontaining a new line to test the preservation of indentation", - "highlight": `Chapter 1 introduces the terminology and approach\nthat we're going to use throughout this book. It examines what we actually mean by\nwords like reliability, scalability, and maintainability, and how\nwe can try to achieve these goals.`, - "note": "Test note for the aggregated hightlight from the Apple iPhone User Guide\nalong with a new line to test the preservation of indentation", - "highlightStyle": 3, - "highlightCreationDate": 731876693.002279, - "highlightModificationDate": 731876693.002279 - }] -} diff --git a/test/mocks/aggregatedDetailsData.ts b/test/mocks/aggregatedDetailsData.ts index efbb08f..8459df7 100644 --- a/test/mocks/aggregatedDetailsData.ts +++ b/test/mocks/aggregatedDetailsData.ts @@ -1,6 +1,4 @@ -import { ICombinedBooksAndHighlights, IBookAnnotation, IBook } from "src/types"; - -export const booksToAggregate: IBook[] = [{ +export const booksToAggregate = [{ "ZASSETID": "THBFYNJKTGFTTVCGSAE5", "ZTITLE": "Apple iPhone: User Guide | Instructions ^ with # restricted [ symbols ] in \ / title", // eslint-disable-line "ZAUTHOR": "Apple Inc.", @@ -10,7 +8,7 @@ export const booksToAggregate: IBook[] = [{ "ZCOVERURL": '' }]; -export const annotationsToAggregate: IBookAnnotation[] = [{ +export const annotationsToAggregate = [{ "ZANNOTATIONASSETID": "THBFYNJKTGFTTVCGSAE5", "ZFUTUREPROOFING5": "Aggregated Introduction", "ZANNOTATIONREPRESENTATIVETEXT": "This is a contextual text for the aggregated hightlight from the Apple iPhone User Guide", @@ -32,7 +30,7 @@ export const annotationsToAggregate: IBookAnnotation[] = [{ "ZANNOTATIONDELETED": 0 }]; -export const aggregatedHighlights: ICombinedBooksAndHighlights[] = [{ +export const aggregatedHighlights = [{ "bookTitle": "Apple iPhone - User Guide - Instructions - with - restricted - symbols - in - title", "bookId": "THBFYNJKTGFTTVCGSAE5", "bookAuthor": "Apple Inc.", diff --git a/test/mocks/detailsData.ts b/test/mocks/detailsData.ts new file mode 100644 index 0000000..974e13c --- /dev/null +++ b/test/mocks/detailsData.ts @@ -0,0 +1,18 @@ +export const highlights = [{ + "bookTitle": "Designing Data-Intensive Applications", + "bookId": "28AEDF62F12B289C88BD6659BD6E50CC", + "bookAuthor": "Kleppmann, Martin", + "bookGenre": "Technology", + "bookLanguage": "EN", + "bookLastOpenedDate": 731876693.002279, + "bookCoverUrl": '', + "annotations": [{ + "chapter": '', + "contextualText": `Chapter 1 introduces the terminology and approach\nthat we're going to use throughout this book. It examines what we actually mean by\nwords like reliability, scalability, and maintainability, and how\nwe can try to achieve these goals.`, + "highlight": `Chapter 1 introduces the terminology and approach\nthat we're going to use throughout this book. It examines what we actually mean by\nwords like reliability, scalability, and maintainability, and how\nwe can try to achieve these goals.`, + "note": `Test note for the hightlight from Designing Data-Intensive Applications`, + "highlightStyle": 3, + "highlightCreationDate": 731876693.002279, + "highlightModificationDate": 731876693.002279 + }] +}] diff --git a/test/mocks/rawTemplates.ts b/test/mocks/rawTemplates.ts index 5a4594b..0ab9e1a 100644 --- a/test/mocks/rawTemplates.ts +++ b/test/mocks/rawTemplates.ts @@ -30,7 +30,15 @@ Number of annotations:: {{annotations.length}} {{/each}} `; -export const wrappedTextBlockTemplateMock = `{{#each annotations}} +export const rawCustomTemplateWrappedTextBlockMock = `Title:: 📕 {{{bookTitle}}} +Author:: {{{bookAuthor}}} +Link:: [Apple Books Link](ibooks://assetid/{{bookId}}) + +## Annotations + +Number of annotations:: {{annotations.length}} + +{{#each annotations}} ---- > [!QUOTE] diff --git a/test/mocks/renderedTemplate.ts b/test/mocks/renderedTemplate.ts index 9e03b37..d8a65a8 100644 --- a/test/mocks/renderedTemplate.ts +++ b/test/mocks/renderedTemplate.ts @@ -61,7 +61,15 @@ along with a new line to test the preservation of indentation `; -export const renderedWrappedTextBlockTemplateMock = `---- +export const renderedCustomTemplateWrappedTextBlockMock = `Title:: 📕 Designing Data-Intensive Applications +Author:: Kleppmann, Martin +Link:: [Apple Books Link](ibooks://assetid/28AEDF62F12B289C88BD6659BD6E50CC) + +## Annotations + +Number of annotations:: 1 + +---- > [!QUOTE] > Chapter 1 introduces the terminology and approach diff --git a/test/preserveNewlineIndentation.spec.ts b/test/preserveNewlineIndentation.spec.ts index 8fc39a6..d95ae56 100644 --- a/test/preserveNewlineIndentation.spec.ts +++ b/test/preserveNewlineIndentation.spec.ts @@ -1,9 +1,10 @@ import { describe, expect, test } from 'vitest' import { preserveNewlineIndentation } from 'src/utils' import { renderHighlightsTemplate } from 'src/methods/renderHighlightsTemplate' -import { wrappedTextBlockTemplateMock } from './mocks/rawTemplates' -import { renderedWrappedTextBlockTemplateMock } from './mocks/renderedTemplate' -import { aggregateWrappedTextBlockData } from './mocks/aggregateWrappedTextBlockData' +import { rawCustomTemplateWrappedTextBlockMock } from './mocks/rawTemplates' +import { renderedCustomTemplateWrappedTextBlockMock } from './mocks/renderedTemplate' +import { highlights } from './mocks/detailsData' +import { ICombinedBooksAndHighlights } from 'src/types' describe('preserveNewlineIndentation', () => { test('Should handle double new line characters to preserve proper indentation in text', () => { @@ -22,9 +23,9 @@ describe('preserveNewlineIndentation', () => { expect(actual).toEqual(expected) }) - test('Should render a custom template with the provided data', async () => { - const renderedTemplate = await renderHighlightsTemplate(aggregateWrappedTextBlockData, wrappedTextBlockTemplateMock); + test('Should render a custom template and preserve the proper indentation when a text block is wrapped', async () => { + const renderedTemplate = await renderHighlightsTemplate(highlights[0] as ICombinedBooksAndHighlights, rawCustomTemplateWrappedTextBlockMock); - expect(renderedTemplate).toEqual(renderedWrappedTextBlockTemplateMock); + expect(renderedTemplate).toEqual(renderedCustomTemplateWrappedTextBlockMock); }); }) diff --git a/test/renderHighlightsTemplate.spec.ts b/test/renderHighlightsTemplate.spec.ts index a8e2daf..6a95311 100644 --- a/test/renderHighlightsTemplate.spec.ts +++ b/test/renderHighlightsTemplate.spec.ts @@ -8,6 +8,7 @@ import { aggregatedHighlights } from './mocks/aggregatedDetailsData'; import { rawCustomTemplateMock } from './mocks/rawTemplates'; import { defaultTemplateMock, renderedCustomTemplateMock } from './mocks/renderedTemplate'; import defaultTemplate from '../src/template'; +import { ICombinedBooksAndHighlights } from 'src/types'; describe('renderHighlightsTemplate', () => { const helpers = Handlebars.helpers; @@ -18,7 +19,7 @@ describe('renderHighlightsTemplate', () => { describe('Template rendering', () => { test('Should render a default template with the provided data', async () => { - const renderedTemplate = await renderHighlightsTemplate(aggregatedHighlights[0], defaultTemplate); + const renderedTemplate = await renderHighlightsTemplate(aggregatedHighlights[0] as ICombinedBooksAndHighlights, defaultTemplate); expect(renderedTemplate).toEqual(defaultTemplateMock); }); @@ -26,7 +27,7 @@ describe('renderHighlightsTemplate', () => { test('Should render a custom template with the provided data', async () => { tzSpy.mockImplementation(() => 'America/New_York'); - const renderedTemplate = await renderHighlightsTemplate(aggregatedHighlights[0], rawCustomTemplateMock); + const renderedTemplate = await renderHighlightsTemplate(aggregatedHighlights[0] as ICombinedBooksAndHighlights, rawCustomTemplateMock); expect(renderedTemplate).toEqual(renderedCustomTemplateMock); }); diff --git a/test/saveHighlightsToVault.spec.ts b/test/saveHighlightsToVault.spec.ts index 2ad95c2..d730fda 100644 --- a/test/saveHighlightsToVault.spec.ts +++ b/test/saveHighlightsToVault.spec.ts @@ -3,6 +3,7 @@ import SaveHighlights from '../src/methods/saveHighlightsToVault'; import { AppleBooksHighlightsImportPluginSettings } from '../src/settings'; import { aggregatedHighlights } from './mocks/aggregatedDetailsData'; import { defaultTemplateMock } from './mocks/renderedTemplate'; +import { ICombinedBooksAndHighlights } from '../src/types' const mockVault = { getAbstractFileByPath: vi.fn(), @@ -43,7 +44,7 @@ describe('Save highlights to vault', () => { const saveHighlights = new SaveHighlights({ vault: mockVault } as any, settings); const spyGetAbstractFileByPath = vi.spyOn(mockVault, 'getAbstractFileByPath').mockReturnValue('ibooks-highlights'); - await saveHighlights.saveHighlightsToVault(aggregatedHighlights); + await saveHighlights.saveHighlightsToVault(aggregatedHighlights as ICombinedBooksAndHighlights[]); expect(spyGetAbstractFileByPath).toHaveBeenCalledTimes(1); expect(spyGetAbstractFileByPath).toHaveBeenCalledWith('ibooks-highlights'); @@ -66,7 +67,7 @@ describe('Save highlights to vault', () => { const saveHighlights = new SaveHighlights({ vault: mockVault } as any, { ...settings, highlightsFolder: '' }); const spyGetAbstractFileByPath = vi.spyOn(mockVault, 'getAbstractFileByPath').mockReturnValue(''); - await saveHighlights.saveHighlightsToVault(aggregatedHighlights); + await saveHighlights.saveHighlightsToVault(aggregatedHighlights as ICombinedBooksAndHighlights[]); expect(spyGetAbstractFileByPath).toHaveBeenCalledTimes(1); expect(spyGetAbstractFileByPath).toHaveBeenCalledWith(''); @@ -92,7 +93,7 @@ describe('Save highlights to vault', () => { }; }); - await saveHighlights.saveHighlightsToVault(aggregatedHighlights); + await saveHighlights.saveHighlightsToVault(aggregatedHighlights as ICombinedBooksAndHighlights[]); expect(spyList).toHaveBeenCalledTimes(1); expect(spyList).toReturnWith({