-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quick fix for #61
- Loading branch information
Elias Sundqvist
committed
Sep 11, 2021
1 parent
d3b068d
commit 865d99a
Showing
8 changed files
with
122 additions
and
12 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
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
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 |
---|---|---|
@@ -1,13 +1,58 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import * as annotationUtils from "../src/annotationUtils"; | ||
import { Annotation } from '../src/types'; | ||
import { IHasAnnotatorSettings } from '../src/main'; | ||
|
||
const testAnnotatorSettings: IHasAnnotatorSettings = { | ||
settings: { | ||
deafultDarkMode: false, | ||
darkReaderSettings: null, | ||
customDefaultPath: null, | ||
annotationMarkdownSettings: { | ||
includePostfix: true, | ||
includePrefix: true, | ||
highlightHighlightedText: true | ||
} | ||
} | ||
} | ||
|
||
function loadMd(mdfile: string) { | ||
const mdTestFilePath = path.join(__dirname, "./", mdfile); | ||
return fs.readFileSync(mdTestFilePath, {encoding: "utf8"}).replaceAll('\r\n','\n'); | ||
} | ||
|
||
function loadJson(jsonfile: string) { | ||
const jsonTestFilePath = path.join(__dirname, "./", jsonfile); | ||
return fs.readFileSync(jsonTestFilePath, {encoding: "utf8"}); | ||
} | ||
|
||
const mdTestFilePath = path.join(__dirname, "./", "testfile.md"); | ||
const mdTestFile = fs.readFileSync(mdTestFilePath, {encoding: "utf8"}).replaceAll('\r\n','\n'); | ||
const jsonTestFilePath = path.join(__dirname, "./", "testfile.json"); | ||
const jsonTestFile = fs.readFileSync(jsonTestFilePath, {encoding: "utf8"}); | ||
|
||
test("AnnotationShouldBeCorrectlyParsed", ()=>{ | ||
const loadedAnnotations = annotationUtils.loadAnnotationsAtUriFromFileText(null, mdTestFile) | ||
const mdTestFile = loadMd("testfile.md"); | ||
const jsonTestFile = loadJson("testfile.json"); | ||
const loadedAnnotations = annotationUtils.loadAnnotationsAtUriFromFileText(null, mdTestFile); | ||
expect(JSON.parse(jsonTestFile)).toEqual(loadedAnnotations); | ||
}) | ||
|
||
test("AnnotationsCanBeModified", ()=>{ | ||
const mdTestFile = loadMd("testfile2.md"); | ||
const loadedAnnotations = annotationUtils.loadAnnotationsAtUriFromFileText(null, mdTestFile); | ||
const modifiedAnnotation: Annotation = {...JSON.parse(JSON.stringify(loadedAnnotations.rows[0])), text: "this is a modified comment"}; | ||
const res = annotationUtils.writeAnnotationToAnnotationFileString(modifiedAnnotation, mdTestFile, testAnnotatorSettings); | ||
const loadedModifiedAnnotations = annotationUtils.loadAnnotationsAtUriFromFileText(null, res.newAnnotationFileString); | ||
expect(loadedModifiedAnnotations.total).toEqual(loadedAnnotations.total); | ||
expect(loadedModifiedAnnotations.rows[0]).toEqual(modifiedAnnotation); | ||
const drop1 = ([arr, ...rest]: Annotation[])=>rest; | ||
expect(drop1(loadedAnnotations.rows)).toEqual(drop1(loadedModifiedAnnotations.rows)); | ||
}) | ||
|
||
test("AnnotationsCanBeAdded", ()=>{ | ||
const mdTestFile = loadMd("testfile2.md"); | ||
const loadedAnnotations = annotationUtils.loadAnnotationsAtUriFromFileText(null, mdTestFile); | ||
const newAnnotation: Annotation = {...JSON.parse(JSON.stringify(loadedAnnotations.rows[0])), id: 'anewid'}; | ||
const res = annotationUtils.writeAnnotationToAnnotationFileString(newAnnotation, mdTestFile, testAnnotatorSettings); | ||
const loadedModifiedAnnotations = annotationUtils.loadAnnotationsAtUriFromFileText(null, res.newAnnotationFileString); | ||
expect(loadedModifiedAnnotations.total).toEqual(loadedAnnotations.total+1); | ||
expect(loadedModifiedAnnotations.rows).toEqual([...loadedAnnotations.rows, newAnnotation]); | ||
}) |
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,56 @@ | ||
annotation-target:: TIF160+CourseIntro+2021.pdf | ||
|
||
>%% | ||
>```annotation-json | ||
>{"created":"2021-08-31T19:14:06.862Z","updated":"2021-08-31T19:14:06.862Z","uri":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729","document":{"title":"TIF160/FIM800 Humanoid robotics -Course introduction-","link":[{"href":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729"}],"documentFingerprint":"522f388ebd51503bb23c2db5991d6729"},"target":[{"source":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729","selector":[{"type":"TextPositionSelector","start":98,"end":121},{"type":"TextQuoteSelector","exact":"Mechanics and Maritime ","prefix":"ssociate professorDepartment of ","suffix":"SciencesChalmers University of T"}]}]} | ||
>``` | ||
>%% | ||
>*%%PREFIX%%ssociate professorDepartment of%%HIGHLIGHT%% ==Mechanics and Maritime== %%POSTFIX%%SciencesChalmers University of T* | ||
>%%LINK%%[[#^ghrcuqkctcn|show annotation]] | ||
>%%COMMENT%% | ||
> | ||
>%%TAGS%% | ||
> | ||
^ghrcuqkctcn | ||
>%% | ||
>```annotation-json | ||
>{"text":"testie ball","target":[{"source":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729","selector":[{"type":"TextPositionSelector","start":32,"end":51},{"type":"TextQuoteSelector","exact":"Course introduction","prefix":"TIF160/FIM800 Humanoid robotics-","suffix":"-Krister WolffAssociate professo"}]}],"created":"2021-09-01T14:48:59.315Z","updated":"2021-09-01T14:48:59.315Z","uri":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729","document":{"title":"TIF160/FIM800 Humanoid robotics -Course introduction-","link":[{"href":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729"}],"documentFingerprint":"522f388ebd51503bb23c2db5991d6729"}} | ||
>``` | ||
>%% | ||
>*%%HIGHLIGHT%% ==Course introduction== * | ||
>%%LINK%%[[#^0lj0rg85p8y9|show annotation]] | ||
>%%COMMENT%% | ||
>testie ball | ||
>%%TAGS%% | ||
> | ||
^0lj0rg85p8y9 | ||
>%% | ||
>```annotation-json | ||
>{"created":"2021-09-03T13:35:28.431Z","updated":"2021-09-03T13:35:28.431Z","uri":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729","document":{"title":"TIF160/FIM800 Humanoid robotics -Course introduction-","link":[{"href":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729"}],"documentFingerprint":"522f388ebd51503bb23c2db5991d6729"},"target":[{"source":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729","selector":[{"type":"TextPositionSelector","start":6212,"end":6232},{"type":"TextQuoteSelector","exact":"Contribution outside","prefix":"to contribute to team meetings,I","suffix":" of team meetings,IShow confiden"}]}]} | ||
>``` | ||
>%% | ||
>*%%HIGHLIGHT%% ==Contribution outside== * | ||
>%%LINK%%[[#^undefined|show annotation]] | ||
>%%COMMENT%% | ||
> | ||
>%%TAGS%% | ||
> | ||
^chill | ||
>%% | ||
>```annotation-json | ||
>{"created":"2021-09-03T13:42:22.993Z","updated":"2021-09-03T13:42:22.993Z","uri":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729","document":{"title":"TIF160/FIM800 Humanoid robotics -Course introduction-","link":[{"href":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729"}],"documentFingerprint":"522f388ebd51503bb23c2db5991d6729"},"target":[{"source":"urn:x-pdf:522f388ebd51503bb23c2db5991d6729","selector":[{"type":"TextPositionSelector","start":6642,"end":6655},{"type":"TextQuoteSelector","exact":"Krister Wolff","prefix":"tics Compendium(draft version)by","suffix":"Please note:This is awork in pro"}]}]} | ||
>``` | ||
>%% | ||
>*%%HIGHLIGHT%% ==Krister Wolff== * | ||
>%%LINK%%[[#^pt6evw5pjd|show annotation]] | ||
>%%COMMENT%% | ||
> | ||
>%%TAGS%% | ||
> | ||
^pt6evw5pjd |
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 |
---|---|---|
|
@@ -9,5 +9,6 @@ | |
"0.0.8": "0.9.12", | ||
"0.0.9": "0.9.12", | ||
"0.1.0": "0.9.12", | ||
"0.1.1": "0.9.12" | ||
"0.1.1": "0.9.12", | ||
"0.1.2": "0.9.12" | ||
} |