Skip to content

Commit

Permalink
fix: add test for to ensure proper indentation when a text block is w…
Browse files Browse the repository at this point in the history
…rapped (#28) (#21)
  • Loading branch information
absorpheus committed Jul 16, 2024
1 parent 1ac8d3a commit efb79fb
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ export interface IBookAnnotation {
ZANNOTATIONCREATIONDATE: number;
ZANNOTATIONMODIFICATIONDATE: number;
ZANNOTATIONSTYLE: 0 | 1 | 2 | 3 | 4 | 5;
ZANNOTATIONDELETED: 0 | 1;
}

export interface IHighlight {
chapter: string;
contextualText: string;
highlight: string;
note: string;
highlightStyle: IBookAnnotation['ZANNOTATIONSTYLE'],
highlightCreationDate: number;
highlightModificationDate: number;
}
export interface ICombinedBooksAndHighlights {
bookTitle: string;
Expand Down
20 changes: 20 additions & 0 deletions test/mocks/aggregateWrappedTextBlockData.ts
Original file line number Diff line number Diff line change
@@ -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
}]
}
8 changes: 5 additions & 3 deletions test/mocks/aggregatedDetailsData.ts
Original file line number Diff line number Diff line change
@@ -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.",
Expand All @@ -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",
Expand All @@ -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.",
Expand Down
9 changes: 9 additions & 0 deletions test/mocks/rawTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ Number of annotations:: {{annotations.length}}
{{/each}}
`;

export const wrappedTextBlockTemplateMock = `{{#each annotations}}
----
> [!QUOTE]
> {{{highlight}}}
{{/each}}
`;
10 changes: 10 additions & 0 deletions test/mocks/renderedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ along with a new line to test the preservation of indentation
- <small>📅 Highlight modified on:: 2024-03-11 03:04:53 PM -04:00</small>
`;

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.
`;
10 changes: 10 additions & 0 deletions test/preserveNewlineIndentation.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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);
});
})

0 comments on commit efb79fb

Please sign in to comment.