From efb79fb875950de8220f97a00f59153e68920e3c Mon Sep 17 00:00:00 2001 From: Abdullah Malek <19255312+absorpheus@users.noreply.github.com> Date: Tue, 16 Jul 2024 03:24:48 +0100 Subject: [PATCH] fix: add test for to ensure proper indentation when a text block is wrapped (#28) (#21) --- src/types.ts | 4 ++++ test/mocks/aggregateWrappedTextBlockData.ts | 20 ++++++++++++++++++++ test/mocks/aggregatedDetailsData.ts | 8 +++++--- test/mocks/rawTemplates.ts | 9 +++++++++ test/mocks/renderedTemplate.ts | 10 ++++++++++ test/preserveNewlineIndentation.spec.ts | 10 ++++++++++ 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 test/mocks/aggregateWrappedTextBlockData.ts diff --git a/src/types.ts b/src/types.ts index 08f8d8c..91392c5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,6 +17,7 @@ export interface IBookAnnotation { ZANNOTATIONCREATIONDATE: number; ZANNOTATIONMODIFICATIONDATE: number; ZANNOTATIONSTYLE: 0 | 1 | 2 | 3 | 4 | 5; + ZANNOTATIONDELETED: 0 | 1; } export interface IHighlight { @@ -24,6 +25,9 @@ export interface IHighlight { contextualText: string; highlight: string; note: string; + highlightStyle: IBookAnnotation['ZANNOTATIONSTYLE'], + highlightCreationDate: number; + highlightModificationDate: number; } export interface ICombinedBooksAndHighlights { bookTitle: string; diff --git a/test/mocks/aggregateWrappedTextBlockData.ts b/test/mocks/aggregateWrappedTextBlockData.ts new file mode 100644 index 0000000..c0d068b --- /dev/null +++ b/test/mocks/aggregateWrappedTextBlockData.ts @@ -0,0 +1,20 @@ +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 8459df7..efbb08f 100644 --- a/test/mocks/aggregatedDetailsData.ts +++ b/test/mocks/aggregatedDetailsData.ts @@ -1,4 +1,6 @@ -export const booksToAggregate = [{ +import { ICombinedBooksAndHighlights, IBookAnnotation, IBook } from "src/types"; + +export const booksToAggregate: IBook[] = [{ "ZASSETID": "THBFYNJKTGFTTVCGSAE5", "ZTITLE": "Apple iPhone: User Guide | Instructions ^ with # restricted [ symbols ] in \ / title", // eslint-disable-line "ZAUTHOR": "Apple Inc.", @@ -8,7 +10,7 @@ export const booksToAggregate = [{ "ZCOVERURL": '' }]; -export const annotationsToAggregate = [{ +export const annotationsToAggregate: IBookAnnotation[] = [{ "ZANNOTATIONASSETID": "THBFYNJKTGFTTVCGSAE5", "ZFUTUREPROOFING5": "Aggregated Introduction", "ZANNOTATIONREPRESENTATIVETEXT": "This is a contextual text for the aggregated hightlight from the Apple iPhone User Guide", @@ -30,7 +32,7 @@ export const annotationsToAggregate = [{ "ZANNOTATIONDELETED": 0 }]; -export const aggregatedHighlights = [{ +export const aggregatedHighlights: ICombinedBooksAndHighlights[] = [{ "bookTitle": "Apple iPhone - User Guide - Instructions - with - restricted - symbols - in - title", "bookId": "THBFYNJKTGFTTVCGSAE5", "bookAuthor": "Apple Inc.", diff --git a/test/mocks/rawTemplates.ts b/test/mocks/rawTemplates.ts index 4884507..5a4594b 100644 --- a/test/mocks/rawTemplates.ts +++ b/test/mocks/rawTemplates.ts @@ -29,3 +29,12 @@ Number of annotations:: {{annotations.length}} {{/each}} `; + +export const wrappedTextBlockTemplateMock = `{{#each annotations}} +---- + +> [!QUOTE] +> {{{highlight}}} + +{{/each}} +`; diff --git a/test/mocks/renderedTemplate.ts b/test/mocks/renderedTemplate.ts index 2d0622b..9e03b37 100644 --- a/test/mocks/renderedTemplate.ts +++ b/test/mocks/renderedTemplate.ts @@ -60,3 +60,13 @@ along with a new line to test the preservation of indentation - 📅 Highlight modified on:: 2024-03-11 03:04:53 PM -04:00 `; + +export const renderedWrappedTextBlockTemplateMock = `---- + +> [!QUOTE] +> Chapter 1 introduces the terminology and approach +that we're going to use throughout this book. It examines what we actually mean by +words like reliability, scalability, and maintainability, and how +we can try to achieve these goals. + +`; diff --git a/test/preserveNewlineIndentation.spec.ts b/test/preserveNewlineIndentation.spec.ts index 09caf34..8fc39a6 100644 --- a/test/preserveNewlineIndentation.spec.ts +++ b/test/preserveNewlineIndentation.spec.ts @@ -1,5 +1,9 @@ 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' describe('preserveNewlineIndentation', () => { test('Should handle double new line characters to preserve proper indentation in text', () => { @@ -17,4 +21,10 @@ describe('preserveNewlineIndentation', () => { expect(actual).toEqual(expected) }) + + test('Should render a custom template with the provided data', async () => { + const renderedTemplate = await renderHighlightsTemplate(aggregateWrappedTextBlockData, wrappedTextBlockTemplateMock); + + expect(renderedTemplate).toEqual(renderedWrappedTextBlockTemplateMock); + }); })