mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Merge branch 'master' into IntroduceMarkdownLint#864
This commit is contained in:
@@ -926,10 +926,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
handlePaste (editor, forceSmartPaste) {
|
handlePaste (editor, forceSmartPaste) {
|
||||||
const { storageKey, noteKey, fetchUrlTitle, enableSmartPaste } = this.props
|
const { storageKey, noteKey, fetchUrlTitle, enableSmartPaste } = this.props
|
||||||
|
|
||||||
const isURL = str => {
|
const isURL = str => /(?:^\w+:|^)\/\/(?:[^\s\.]+\.\S{2}|localhost[\:?\d]*)/.test(str)
|
||||||
const matcher = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/
|
|
||||||
return matcher.test(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
const isInLinkTag = editor => {
|
const isInLinkTag = editor => {
|
||||||
const startCursor = editor.getCursor('start')
|
const startCursor = editor.getCursor('start')
|
||||||
@@ -1002,7 +999,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
} else {
|
} else {
|
||||||
const image = clipboard.readImage()
|
const image = clipboard.readImage()
|
||||||
if (!image.isEmpty()) {
|
if (!image.isEmpty()) {
|
||||||
attachmentManagement.handlePastNativeImage(
|
attachmentManagement.handlePasteNativeImage(
|
||||||
this,
|
this,
|
||||||
storageKey,
|
storageKey,
|
||||||
noteKey,
|
noteKey,
|
||||||
@@ -1147,7 +1144,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
iconv.encodingExists(_charset)
|
iconv.encodingExists(_charset)
|
||||||
? _charset
|
? _charset
|
||||||
: 'utf-8'
|
: 'utf-8'
|
||||||
resolve(iconv.decode(new Buffer(buff), charset).toString())
|
resolve(iconv.decode(Buffer.from(buff), charset).toString())
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e)
|
reject(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,11 +231,11 @@ function fixLocalURLS (renderedHTML, storagePath) {
|
|||||||
A :storage reference is like `:storage/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`.
|
A :storage reference is like `:storage/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`.
|
||||||
|
|
||||||
- `STORAGE_FOLDER_PLACEHOLDER` will match `:storage`
|
- `STORAGE_FOLDER_PLACEHOLDER` will match `:storage`
|
||||||
- `(?:(?:\\\/|%5C)[\\w.]+)+` will match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`
|
- `(?:(?:\\\/|%5C)[-.\\w]+)+` will match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`
|
||||||
- `(?:\\\/|%5C)[\\w.]+` will either match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564` or `/f939b2c3.jpg`
|
- `(?:\\\/|%5C)[-.\\w]+` will either match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564` or `/f939b2c3.jpg`
|
||||||
- `(?:\\\/|%5C)` match the path seperator. `\\\/` for posix systems and `%5C` for windows.
|
- `(?:\\\/|%5C)` match the path seperator. `\\\/` for posix systems and `%5C` for windows.
|
||||||
*/
|
*/
|
||||||
return renderedHTML.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '(?:(?:\\\/|%5C)[\\w.]+)+', 'g'), function (match) {
|
return renderedHTML.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '(?:(?:\\\/|%5C)[-.\\w]+)+', 'g'), function (match) {
|
||||||
var encodedPathSeparators = new RegExp(mdurl.encode(path.win32.sep) + '|' + mdurl.encode(path.posix.sep), 'g')
|
var encodedPathSeparators = new RegExp(mdurl.encode(path.win32.sep) + '|' + mdurl.encode(path.posix.sep), 'g')
|
||||||
return match.replace(encodedPathSeparators, path.sep).replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER, 'g'), 'file:///' + path.join(storagePath, DESTINATION_FOLDER))
|
return match.replace(encodedPathSeparators, path.sep).replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER, 'g'), 'file:///' + path.join(storagePath, DESTINATION_FOLDER))
|
||||||
})
|
})
|
||||||
@@ -287,7 +287,7 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
|
|||||||
* @param {String} noteKey Key of the current note
|
* @param {String} noteKey Key of the current note
|
||||||
* @param {DataTransferItem} dataTransferItem Part of the past-event
|
* @param {DataTransferItem} dataTransferItem Part of the past-event
|
||||||
*/
|
*/
|
||||||
function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem) {
|
function handlePasteImageEvent (codeEditor, storageKey, noteKey, dataTransferItem) {
|
||||||
if (!codeEditor) {
|
if (!codeEditor) {
|
||||||
throw new Error('codeEditor has to be given')
|
throw new Error('codeEditor has to be given')
|
||||||
}
|
}
|
||||||
@@ -331,7 +331,7 @@ function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem
|
|||||||
* @param {String} noteKey Key of the current note
|
* @param {String} noteKey Key of the current note
|
||||||
* @param {NativeImage} image The native image
|
* @param {NativeImage} image The native image
|
||||||
*/
|
*/
|
||||||
function handlePastNativeImage (codeEditor, storageKey, noteKey, image) {
|
function handlePasteNativeImage (codeEditor, storageKey, noteKey, image) {
|
||||||
if (!codeEditor) {
|
if (!codeEditor) {
|
||||||
throw new Error('codeEditor has to be given')
|
throw new Error('codeEditor has to be given')
|
||||||
}
|
}
|
||||||
@@ -429,7 +429,14 @@ function replaceNoteKeyWithNewNoteKey (noteContent, oldNoteKey, newNoteKey) {
|
|||||||
* @returns {String} Input without the references
|
* @returns {String} Input without the references
|
||||||
*/
|
*/
|
||||||
function removeStorageAndNoteReferences (input, noteKey) {
|
function removeStorageAndNoteReferences (input, noteKey) {
|
||||||
return input.replace(new RegExp(mdurl.encode(path.sep), 'g'), path.sep).replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + '(' + escapeStringRegexp(path.sep) + noteKey + ')?', 'g'), DESTINATION_FOLDER)
|
return input.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?("|])', 'g'), function (match) {
|
||||||
|
const temp = match
|
||||||
|
.replace(new RegExp(mdurl.encode(path.win32.sep), 'g'), path.sep)
|
||||||
|
.replace(new RegExp(mdurl.encode(path.posix.sep), 'g'), path.sep)
|
||||||
|
.replace(new RegExp(escapeStringRegexp(path.win32.sep), 'g'), path.sep)
|
||||||
|
.replace(new RegExp(escapeStringRegexp(path.posix.sep), 'g'), path.sep)
|
||||||
|
return temp.replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + '(' + escapeStringRegexp(path.sep) + noteKey + ')?', 'g'), DESTINATION_FOLDER)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -584,8 +591,8 @@ module.exports = {
|
|||||||
fixLocalURLS,
|
fixLocalURLS,
|
||||||
generateAttachmentMarkdown,
|
generateAttachmentMarkdown,
|
||||||
handleAttachmentDrop,
|
handleAttachmentDrop,
|
||||||
handlePastImageEvent,
|
handlePasteImageEvent,
|
||||||
handlePastNativeImage,
|
handlePasteNativeImage,
|
||||||
getAttachmentsInMarkdownContent,
|
getAttachmentsInMarkdownContent,
|
||||||
getAbsolutePathsOfAttachmentsInContent,
|
getAbsolutePathsOfAttachmentsInContent,
|
||||||
removeStorageAndNoteReferences,
|
removeStorageAndNoteReferences,
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ it('should test that copyAttachment don\'t uses a random file name if not intend
|
|||||||
|
|
||||||
it('should replace the all ":storage" path with the actual storage path', function () {
|
it('should replace the all ":storage" path with the actual storage path', function () {
|
||||||
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
||||||
|
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
||||||
const testInput =
|
const testInput =
|
||||||
'<html>\n' +
|
'<html>\n' +
|
||||||
' <head>\n' +
|
' <head>\n' +
|
||||||
@@ -136,14 +137,18 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href=":storage' + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="6">\n' +
|
' <p data-line="6">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
|
' <pre class="fence" data-line="8">\n' +
|
||||||
|
' <span class="filename"></span>\n' +
|
||||||
|
' <div class="gallery" data-autoplay="undefined" data-height="undefined">:storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + 'f939b2c3.jpg</div>\n' +
|
||||||
|
' </pre>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
const storagePath = '<<dummyStoragePath>>'
|
const storagePath = '<<dummyStoragePath>>'
|
||||||
@@ -155,14 +160,18 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="6">\n' +
|
' <p data-line="6">\n' +
|
||||||
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
|
' <pre class="fence" data-line="8">\n' +
|
||||||
|
' <span class="filename"></span>\n' +
|
||||||
|
' <div class="gallery" data-autoplay="undefined" data-height="undefined">file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + 'f939b2c3.jpg</div>\n' +
|
||||||
|
' </pre>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
const actual = systemUnderTest.fixLocalURLS(testInput, storagePath)
|
const actual = systemUnderTest.fixLocalURLS(testInput, storagePath)
|
||||||
@@ -171,6 +180,7 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
|||||||
|
|
||||||
it('should replace the ":storage" path with the actual storage path when they have different path separators', function () {
|
it('should replace the ":storage" path with the actual storage path when they have different path separators', function () {
|
||||||
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
||||||
|
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
||||||
const testInput =
|
const testInput =
|
||||||
'<html>\n' +
|
'<html>\n' +
|
||||||
' <head>\n' +
|
' <head>\n' +
|
||||||
@@ -179,10 +189,10 @@ it('should replace the ":storage" path with the actual storage path when they ha
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.win32.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src=":storage' + mdurl.encode(path.win32.sep) + noteKey + mdurl.encode(path.win32.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href=":storage' + mdurl.encode(path.posix.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href=":storage' + mdurl.encode(path.posix.sep) + noteKey + mdurl.encode(path.posix.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
@@ -195,10 +205,10 @@ it('should replace the ":storage" path with the actual storage path when they ha
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
@@ -251,28 +261,17 @@ it('should test that getAttachmentsInMarkdownContent finds all attachments when
|
|||||||
|
|
||||||
it('should test that getAbsolutePathsOfAttachmentsInContent returns all absolute paths', function () {
|
it('should test that getAbsolutePathsOfAttachmentsInContent returns all absolute paths', function () {
|
||||||
const dummyStoragePath = 'dummyStoragePath'
|
const dummyStoragePath = 'dummyStoragePath'
|
||||||
const testInput =
|
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
||||||
'<html>\n' +
|
const testInput = '"# Test\n' +
|
||||||
' <head>\n' +
|
'\n' +
|
||||||
' //header\n' +
|
'\n' +
|
||||||
' </head>\n' +
|
'\n' +
|
||||||
' <body data-theme="default">\n' +
|
'"'
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
|
||||||
' <p data-line="2">\n' +
|
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
||||||
' </p>\n' +
|
|
||||||
' <p data-line="4">\n' +
|
|
||||||
' <a href=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
||||||
' </p>\n' +
|
|
||||||
' <p data-line="6">\n' +
|
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
||||||
' </p>\n' +
|
|
||||||
' </body>\n' +
|
|
||||||
'</html>'
|
|
||||||
const actual = systemUnderTest.getAbsolutePathsOfAttachmentsInContent(testInput, dummyStoragePath)
|
const actual = systemUnderTest.getAbsolutePathsOfAttachmentsInContent(testInput, dummyStoragePath)
|
||||||
const expected = [dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '0.6r4zdgc22xp.png',
|
const expected = [dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png',
|
||||||
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '0.q2i4iw0fyx.pdf',
|
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf',
|
||||||
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + 'd6c5ee92.jpg']
|
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + 'd6c5ee92.jpg']
|
||||||
expect(actual).toEqual(expect.arrayContaining(expected))
|
expect(actual).toEqual(expect.arrayContaining(expected))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -287,13 +286,13 @@ it('should remove the all ":storage" and noteKey references', function () {
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src=":storage' + mdurl.encode(path.win32.sep) + noteKey + mdurl.encode(path.win32.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href=":storage' + mdurl.encode(path.posix.sep) + noteKey + mdurl.encode(path.posix.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="6">\n' +
|
' <p data-line="6">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
' <img src=":storage' + mdurl.encode(path.win32.sep) + noteKey + mdurl.encode(path.posix.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
@@ -323,8 +322,8 @@ it('should make sure that "removeStorageAndNoteReferences" works with markdown c
|
|||||||
const noteKey = 'noteKey'
|
const noteKey = 'noteKey'
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + noteKey + path.sep + 'pdf.pdf](pdf})'
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + noteKey + path.posix.sep + 'pdf.pdf](pdf})'
|
||||||
|
|
||||||
const expectedOutput =
|
const expectedOutput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
@@ -476,8 +475,8 @@ it('should test that moveAttachments returns a correct modified content version'
|
|||||||
const newNoteKey = 'newNoteKey'
|
const newNoteKey = 'newNoteKey'
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNoteKey + path.sep + 'pdf.pdf](pdf})'
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNoteKey + path.posix.sep + 'pdf.pdf](pdf})'
|
||||||
const expectedOutput =
|
const expectedOutput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
@@ -492,8 +491,8 @@ it('should test that cloneAttachments modifies the content of the new note corre
|
|||||||
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
|
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'pdf.pdf](pdf})'
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
|
||||||
newNote.content = testInput
|
newNote.content = testInput
|
||||||
findStorage.findStorage = jest.fn()
|
findStorage.findStorage = jest.fn()
|
||||||
findStorage.findStorage.mockReturnValue({path: 'dummyStoragePath'})
|
findStorage.findStorage.mockReturnValue({path: 'dummyStoragePath'})
|
||||||
@@ -516,8 +515,8 @@ it('should test that cloneAttachments finds all attachments and copies them to t
|
|||||||
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'MARKDOWN_NOTE'}
|
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'MARKDOWN_NOTE'}
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'pdf.pdf](pdf})'
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
|
||||||
oldNote.content = testInput
|
oldNote.content = testInput
|
||||||
newNote.content = testInput
|
newNote.content = testInput
|
||||||
|
|
||||||
@@ -566,14 +565,22 @@ it('should test that isAttachmentLink works correctly', function () {
|
|||||||
expect(systemUnderTest.isAttachmentLink('text')).toBe(false)
|
expect(systemUnderTest.isAttachmentLink('text')).toBe(false)
|
||||||
expect(systemUnderTest.isAttachmentLink('text [linkText](link)')).toBe(false)
|
expect(systemUnderTest.isAttachmentLink('text [linkText](link)')).toBe(false)
|
||||||
expect(systemUnderTest.isAttachmentLink('text ')).toBe(false)
|
expect(systemUnderTest.isAttachmentLink('text ')).toBe(false)
|
||||||
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf)')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf)')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf)')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf)')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('text ')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('text ')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf) test')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf) test')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink(' test')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink(' test')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('text [linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf) test')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('text [linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf) test')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('text  test')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('text  test')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf)')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf)')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('text ')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf) test')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink(' test')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('text [linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf) test')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('text  test')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should test that handleAttachmentLinkPaste copies the attachments to the new location', function () {
|
it('should test that handleAttachmentLinkPaste copies the attachments to the new location', function () {
|
||||||
@@ -581,7 +588,7 @@ it('should test that handleAttachmentLinkPaste copies the attachments to the new
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text '
|
const pasteText = 'text '
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
|
|
||||||
@@ -596,12 +603,53 @@ it('should test that handleAttachmentLinkPaste copies the attachments to the new
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should test that handleAttachmentLinkPaste don\'t try to copy the file if it does not exist', function () {
|
it('should test that handleAttachmentLinkPaste copies the attachments to the new location - win32 path', function () {
|
||||||
const dummyStorage = {path: 'dummyStoragePath'}
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text '
|
const pasteText = 'text '
|
||||||
|
const storageKey = 'storageKey'
|
||||||
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
|
|
||||||
|
sander.exists = jest.fn(() => Promise.resolve(true))
|
||||||
|
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve('dummyNewFileName'))
|
||||||
|
|
||||||
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||||
|
.then(() => {
|
||||||
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||||
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
||||||
|
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePath, storageKey, newNoteKey)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should test that handleAttachmentLinkPaste don\'t try to copy the file if it does not exist - win32 path', function () {
|
||||||
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
|
const pasteText = 'text '
|
||||||
|
const storageKey = 'storageKey'
|
||||||
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
|
|
||||||
|
sander.exists = jest.fn(() => Promise.resolve(false))
|
||||||
|
systemUnderTest.copyAttachment = jest.fn()
|
||||||
|
systemUnderTest.generateFileNotFoundMarkdown = jest.fn()
|
||||||
|
|
||||||
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||||
|
.then(() => {
|
||||||
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||||
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
||||||
|
expect(systemUnderTest.copyAttachment).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should test that handleAttachmentLinkPaste don\'t try to copy the file if it does not exist -- posix', function () {
|
||||||
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
|
const pasteText = 'text '
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
|
|
||||||
@@ -622,8 +670,8 @@ it('should test that handleAttachmentLinkPaste copies multiple attachments if mu
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text  ..' +
|
const pasteText = 'text  ..' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
||||||
@@ -647,7 +695,7 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const dummyNewFileName = 'dummyNewFileName'
|
const dummyNewFileName = 'dummyNewFileName'
|
||||||
const pasteText = 'text '
|
const pasteText = 'text '
|
||||||
const expectedText = 'text '
|
const expectedText = 'text '
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
|
|
||||||
@@ -667,8 +715,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const dummyNewFileNameOne = 'dummyNewFileName'
|
const dummyNewFileNameOne = 'dummyNewFileName'
|
||||||
const dummyNewFileNameTwo = 'dummyNewFileNameTwo'
|
const dummyNewFileNameTwo = 'dummyNewFileNameTwo'
|
||||||
const pasteText = 'text  ' +
|
const pasteText = 'text  ' +
|
||||||
''
|
''
|
||||||
const expectedText = 'text  ' +
|
const expectedText = 'text  ' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
@@ -689,8 +737,8 @@ it('should test that handleAttachmentLinkPaste calls the copy method correct if
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text  ..' +
|
const pasteText = 'text  ..' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
||||||
@@ -716,7 +764,7 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text '
|
const pasteText = 'text '
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const fileNotFoundMD = 'file not found'
|
const fileNotFoundMD = 'file not found'
|
||||||
const expectedPastText = 'text ' + fileNotFoundMD
|
const expectedPastText = 'text ' + fileNotFoundMD
|
||||||
@@ -735,8 +783,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text  ' +
|
const pasteText = 'text  ' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const fileNotFoundMD = 'file not found'
|
const fileNotFoundMD = 'file not found'
|
||||||
const expectedPastText = 'text ' + fileNotFoundMD + ' ' + fileNotFoundMD
|
const expectedPastText = 'text ' + fileNotFoundMD + ' ' + fileNotFoundMD
|
||||||
@@ -757,8 +805,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const dummyFoundFileName = 'dummyFileName'
|
const dummyFoundFileName = 'dummyFileName'
|
||||||
const fileNotFoundMD = 'file not found'
|
const fileNotFoundMD = 'file not found'
|
||||||
const pasteText = 'text  .. ' +
|
const pasteText = 'text  .. ' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedPastText = 'text ' + fileNotFoundMD + ' .. '
|
const expectedPastText = 'text ' + fileNotFoundMD + ' .. '
|
||||||
|
|
||||||
@@ -781,8 +829,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const dummyFoundFileName = 'dummyFileName'
|
const dummyFoundFileName = 'dummyFileName'
|
||||||
const fileNotFoundMD = 'file not found'
|
const fileNotFoundMD = 'file not found'
|
||||||
const pasteText = 'text  .. ' +
|
const pasteText = 'text  .. ' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedPastText = 'text  .. ' + fileNotFoundMD
|
const expectedPastText = 'text  .. ' + fileNotFoundMD
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user