mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge branch 'master' into fixIssue2534
This commit is contained in:
@@ -3,7 +3,7 @@ import renderer from 'react-test-renderer'
|
||||
import TagListItem from 'browser/components/TagListItem'
|
||||
|
||||
it('TagListItem renders correctly', () => {
|
||||
const tagListItem = renderer.create(<TagListItem name='Test' handleClickTagListItem={jest.fn()} />)
|
||||
const tagListItem = renderer.create(<TagListItem name='Test' handleClickTagListItem={jest.fn()} color='#000' />)
|
||||
|
||||
expect(tagListItem.toJSON()).toMatchSnapshot()
|
||||
})
|
||||
|
||||
@@ -12,6 +12,14 @@ exports[`TagListItem renders correctly 1`] = `
|
||||
className="tagList-item"
|
||||
onClick={[Function]}
|
||||
>
|
||||
<span
|
||||
className="tagList-item-color"
|
||||
style={
|
||||
Object {
|
||||
"backgroundColor": "#000",
|
||||
}
|
||||
}
|
||||
/>
|
||||
<span
|
||||
className="tagList-item-name"
|
||||
>
|
||||
|
||||
@@ -38,7 +38,7 @@ it('should test that copyAttachment should throw an error if sourcePath dosen\'t
|
||||
fs.existsSync = jest.fn()
|
||||
fs.existsSync.mockReturnValue(false)
|
||||
|
||||
systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(() => {}, error => {
|
||||
return systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(() => {}, error => {
|
||||
expect(error).toBe('source file does not exist')
|
||||
expect(fs.existsSync).toHaveBeenCalledWith('path')
|
||||
})
|
||||
@@ -64,7 +64,7 @@ it('should test that copyAttachment works correctly assuming correct working of
|
||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||
uniqueSlug.mockReturnValue(dummyUniquePath)
|
||||
|
||||
systemUnderTest.copyAttachment(sourcePath, storageKey, noteKey).then(
|
||||
return systemUnderTest.copyAttachment(sourcePath, storageKey, noteKey).then(
|
||||
function (newFileName) {
|
||||
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||
expect(fs.createReadStream).toHaveBeenCalledWith(sourcePath)
|
||||
@@ -83,7 +83,7 @@ it('should test that copyAttachment creates a new folder if the attachment folde
|
||||
const dummyReadStream = {}
|
||||
|
||||
dummyReadStream.pipe = jest.fn()
|
||||
dummyReadStream.on = jest.fn()
|
||||
dummyReadStream.on = jest.fn((event, callback) => { callback() })
|
||||
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||
fs.existsSync = jest.fn()
|
||||
fs.existsSync.mockReturnValueOnce(true)
|
||||
@@ -95,7 +95,7 @@ it('should test that copyAttachment creates a new folder if the attachment folde
|
||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||
uniqueSlug.mockReturnValue('dummyPath')
|
||||
|
||||
systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(
|
||||
return systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(
|
||||
function () {
|
||||
expect(fs.existsSync).toHaveBeenCalledWith(attachmentFolderPath)
|
||||
expect(fs.mkdirSync).toHaveBeenCalledWith(attachmentFolderPath)
|
||||
@@ -109,7 +109,7 @@ it('should test that copyAttachment don\'t uses a random file name if not intend
|
||||
const dummyReadStream = {}
|
||||
|
||||
dummyReadStream.pipe = jest.fn()
|
||||
dummyReadStream.on = jest.fn()
|
||||
dummyReadStream.on = jest.fn((event, callback) => { callback() })
|
||||
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||
fs.existsSync = jest.fn()
|
||||
fs.existsSync.mockReturnValueOnce(true)
|
||||
@@ -120,14 +120,155 @@ it('should test that copyAttachment don\'t uses a random file name if not intend
|
||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||
uniqueSlug.mockReturnValue('dummyPath')
|
||||
|
||||
systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey', false).then(
|
||||
return systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey', false).then(
|
||||
function (newFileName) {
|
||||
expect(newFileName).toBe('path')
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that copyAttachment with url (with extension, without query)', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
|
||||
const dummyReadStream = {
|
||||
pipe: jest.fn(),
|
||||
on: jest.fn((event, callback) => { callback() })
|
||||
}
|
||||
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||
|
||||
const dummyWriteStream = {
|
||||
write: jest.fn((data, callback) => { callback() })
|
||||
}
|
||||
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
||||
|
||||
fs.existsSync = jest.fn()
|
||||
fs.existsSync.mockReturnValueOnce(true)
|
||||
fs.existsSync.mockReturnValueOnce(false)
|
||||
fs.mkdirSync = jest.fn()
|
||||
|
||||
findStorage.findStorage = jest.fn()
|
||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||
uniqueSlug.mockReturnValue('dummyPath')
|
||||
|
||||
const sourcePath = {
|
||||
sourceFilePath: 'http://www.foo.bar/baz/qux.jpg',
|
||||
type: 'base64',
|
||||
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
||||
}
|
||||
|
||||
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
||||
function (newFileName) {
|
||||
expect(newFileName).toBe('dummyPath.jpg')
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that copyAttachment with url (with extension, with query)', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
|
||||
const dummyReadStream = {
|
||||
pipe: jest.fn(),
|
||||
on: jest.fn((event, callback) => { callback() })
|
||||
}
|
||||
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||
|
||||
const dummyWriteStream = {
|
||||
write: jest.fn((data, callback) => { callback() })
|
||||
}
|
||||
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
||||
|
||||
fs.existsSync = jest.fn()
|
||||
fs.existsSync.mockReturnValueOnce(true)
|
||||
fs.existsSync.mockReturnValueOnce(false)
|
||||
fs.mkdirSync = jest.fn()
|
||||
|
||||
findStorage.findStorage = jest.fn()
|
||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||
uniqueSlug.mockReturnValue('dummyPath')
|
||||
|
||||
const sourcePath = {
|
||||
sourceFilePath: 'http://www.foo.bar/baz/qux.jpg?h=1080',
|
||||
type: 'base64',
|
||||
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
||||
}
|
||||
|
||||
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
||||
function (newFileName) {
|
||||
expect(newFileName).toBe('dummyPath.jpg')
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that copyAttachment with url (without extension, without query)', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
|
||||
const dummyReadStream = {
|
||||
pipe: jest.fn(),
|
||||
on: jest.fn((event, callback) => { callback() })
|
||||
}
|
||||
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||
|
||||
const dummyWriteStream = {
|
||||
write: jest.fn((data, callback) => { callback() })
|
||||
}
|
||||
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
||||
|
||||
fs.existsSync = jest.fn()
|
||||
fs.existsSync.mockReturnValueOnce(true)
|
||||
fs.existsSync.mockReturnValueOnce(false)
|
||||
fs.mkdirSync = jest.fn()
|
||||
|
||||
findStorage.findStorage = jest.fn()
|
||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||
uniqueSlug.mockReturnValue('dummyPath')
|
||||
|
||||
const sourcePath = {
|
||||
sourceFilePath: 'http://www.foo.bar/baz/qux',
|
||||
type: 'base64',
|
||||
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
||||
}
|
||||
|
||||
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
||||
function (newFileName) {
|
||||
expect(newFileName).toBe('dummyPath.png')
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that copyAttachment with url (without extension, with query)', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
|
||||
const dummyReadStream = {
|
||||
pipe: jest.fn(),
|
||||
on: jest.fn((event, callback) => { callback() })
|
||||
}
|
||||
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||
|
||||
const dummyWriteStream = {
|
||||
write: jest.fn((data, callback) => { callback() })
|
||||
}
|
||||
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
||||
|
||||
fs.existsSync = jest.fn()
|
||||
fs.existsSync.mockReturnValueOnce(true)
|
||||
fs.existsSync.mockReturnValueOnce(false)
|
||||
fs.mkdirSync = jest.fn()
|
||||
|
||||
findStorage.findStorage = jest.fn()
|
||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||
uniqueSlug.mockReturnValue('dummyPath')
|
||||
|
||||
const sourcePath = {
|
||||
sourceFilePath: 'http://www.foo.bar/baz/qux?h=1080',
|
||||
type: 'base64',
|
||||
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
||||
}
|
||||
|
||||
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
||||
function (newFileName) {
|
||||
expect(newFileName).toBe('dummyPath.png')
|
||||
})
|
||||
})
|
||||
|
||||
it('should replace the all ":storage" path with the actual storage path', function () {
|
||||
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
||||
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
||||
const testInput =
|
||||
'<html>\n' +
|
||||
' <head>\n' +
|
||||
@@ -136,14 +277,22 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
||||
' <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) + '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 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 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' +
|
||||
' <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.win32.sep) + noteKey + mdurl.encode(path.win32.sep) + 'f939b2c3.jpg</div>\n' +
|
||||
' </pre>\n' +
|
||||
' <pre class="fence" data-line="10">\n' +
|
||||
' <span class="filename"></span>\n' +
|
||||
' <div class="gallery" data-autoplay="undefined" data-height="undefined">:storage' + mdurl.encode(path.posix.sep) + noteKey + mdurl.encode(path.posix.sep) + 'f939b2c3.jpg</div>\n' +
|
||||
' </pre>\n' +
|
||||
' </body>\n' +
|
||||
'</html>'
|
||||
const storagePath = '<<dummyStoragePath>>'
|
||||
@@ -155,14 +304,22 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
||||
' <body data-theme="default">\n' +
|
||||
' <h2 data-line="0" id="Headline">Headline</h2>\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 + '/' + storageFolder + '/' + noteKey + '/' + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||
' </p>\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 + '/' + storageFolder + '/' + noteKey + '/' + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||
' </p>\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 + '/' + storageFolder + '/' + noteKey + '/' + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\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 + '/' + storageFolder + '/' + noteKey + '/' + 'f939b2c3.jpg</div>\n' +
|
||||
' </pre>\n' +
|
||||
' <pre class="fence" data-line="10">\n' +
|
||||
' <span class="filename"></span>\n' +
|
||||
' <div class="gallery" data-autoplay="undefined" data-height="undefined">file:///' + storagePath + '/' + storageFolder + '/' + noteKey + '/' + 'f939b2c3.jpg</div>\n' +
|
||||
' </pre>\n' +
|
||||
' </body>\n' +
|
||||
'</html>'
|
||||
const actual = systemUnderTest.fixLocalURLS(testInput, storagePath)
|
||||
@@ -171,6 +328,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 () {
|
||||
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
||||
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
||||
const testInput =
|
||||
'<html>\n' +
|
||||
' <head>\n' +
|
||||
@@ -179,10 +337,10 @@ it('should replace the ":storage" path with the actual storage path when they ha
|
||||
' <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.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 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' +
|
||||
' </body>\n' +
|
||||
'</html>'
|
||||
@@ -195,10 +353,10 @@ it('should replace the ":storage" path with the actual storage path when they ha
|
||||
' <body data-theme="default">\n' +
|
||||
' <h2 data-line="0" id="Headline">Headline</h2>\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 + '/' + storageFolder + '/' + noteKey + '/' + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||
' </p>\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 + '/' + storageFolder + '/' + noteKey + '/' + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||
' </p>\n' +
|
||||
' </body>\n' +
|
||||
'</html>'
|
||||
@@ -251,28 +409,17 @@ it('should test that getAttachmentsInMarkdownContent finds all attachments when
|
||||
|
||||
it('should test that getAbsolutePathsOfAttachmentsInContent returns all absolute paths', function () {
|
||||
const dummyStoragePath = 'dummyStoragePath'
|
||||
const testInput =
|
||||
'<html>\n' +
|
||||
' <head>\n' +
|
||||
' //header\n' +
|
||||
' </head>\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 noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
||||
const testInput = '"# Test\n' +
|
||||
'\n' +
|
||||
'\n' +
|
||||
'\n' +
|
||||
'"'
|
||||
|
||||
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',
|
||||
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 + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + 'd6c5ee92.jpg']
|
||||
const expected = [dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png',
|
||||
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf',
|
||||
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + 'd6c5ee92.jpg']
|
||||
expect(actual).toEqual(expect.arrayContaining(expected))
|
||||
})
|
||||
|
||||
@@ -287,13 +434,13 @@ it('should remove the all ":storage" and noteKey references', function () {
|
||||
' <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) + 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 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 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' +
|
||||
' </body>\n' +
|
||||
'</html>'
|
||||
@@ -323,8 +470,8 @@ it('should make sure that "removeStorageAndNoteReferences" works with markdown c
|
||||
const noteKey = 'noteKey'
|
||||
const testInput =
|
||||
'Test input' +
|
||||
' \n' +
|
||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + noteKey + path.sep + 'pdf.pdf](pdf})'
|
||||
' \n' +
|
||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + noteKey + path.posix.sep + 'pdf.pdf](pdf})'
|
||||
|
||||
const expectedOutput =
|
||||
'Test input' +
|
||||
@@ -431,6 +578,72 @@ it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey,
|
||||
expect(fs.unlink).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should test that getAttachmentsPathAndStatus return null if noteKey, storageKey or noteContent was undefined', function () {
|
||||
const noteKey = undefined
|
||||
const storageKey = undefined
|
||||
const markdownContent = ''
|
||||
|
||||
const result = systemUnderTest.getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey)
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
|
||||
it('should test that getAttachmentsPathAndStatus return null if noteKey, storageKey or noteContent was null', function () {
|
||||
const noteKey = null
|
||||
const storageKey = null
|
||||
const markdownContent = ''
|
||||
|
||||
const result = systemUnderTest.getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey)
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
|
||||
it('should test that getAttachmentsPathAndStatus return the correct path and status for attachments', async function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
const noteKey = 'noteKey'
|
||||
const storageKey = 'storageKey'
|
||||
const markdownContent =
|
||||
'Test input' +
|
||||
' \n'
|
||||
const dummyFilesInFolder = ['file1.txt', 'file2.pdf', 'file3.jpg']
|
||||
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
fs.existsSync = jest.fn(() => true)
|
||||
fs.readdir = jest.fn((paht, callback) => callback(undefined, dummyFilesInFolder))
|
||||
fs.unlink = jest.fn()
|
||||
|
||||
const targetStorage = findStorage.findStorage(storageKey)
|
||||
|
||||
const attachments = await systemUnderTest.getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey)
|
||||
expect(attachments.length).toBe(3)
|
||||
expect(attachments[0].isInUse).toBe(false)
|
||||
expect(attachments[1].isInUse).toBe(true)
|
||||
expect(attachments[2].isInUse).toBe(false)
|
||||
|
||||
expect(attachments[0].path).toBe(
|
||||
path.join(
|
||||
targetStorage.path,
|
||||
systemUnderTest.DESTINATION_FOLDER,
|
||||
noteKey,
|
||||
dummyFilesInFolder[0]
|
||||
)
|
||||
)
|
||||
expect(attachments[1].path).toBe(
|
||||
path.join(
|
||||
targetStorage.path,
|
||||
systemUnderTest.DESTINATION_FOLDER,
|
||||
noteKey,
|
||||
dummyFilesInFolder[1]
|
||||
)
|
||||
)
|
||||
expect(attachments[2].path).toBe(
|
||||
path.join(
|
||||
targetStorage.path,
|
||||
systemUnderTest.DESTINATION_FOLDER,
|
||||
noteKey,
|
||||
dummyFilesInFolder[2]
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
it('should test that moveAttachments moves attachments only if the source folder existed', function () {
|
||||
fse.existsSync = jest.fn(() => false)
|
||||
fse.moveSync = jest.fn()
|
||||
@@ -476,8 +689,8 @@ it('should test that moveAttachments returns a correct modified content version'
|
||||
const newNoteKey = 'newNoteKey'
|
||||
const testInput =
|
||||
'Test input' +
|
||||
' \n' +
|
||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNoteKey + path.sep + 'pdf.pdf](pdf})'
|
||||
' \n' +
|
||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNoteKey + path.posix.sep + 'pdf.pdf](pdf})'
|
||||
const expectedOutput =
|
||||
'Test input' +
|
||||
' \n' +
|
||||
@@ -492,8 +705,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 testInput =
|
||||
'Test input' +
|
||||
' \n' +
|
||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'pdf.pdf](pdf})'
|
||||
' \n' +
|
||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
|
||||
newNote.content = testInput
|
||||
findStorage.findStorage = jest.fn()
|
||||
findStorage.findStorage.mockReturnValue({path: 'dummyStoragePath'})
|
||||
@@ -516,8 +729,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 testInput =
|
||||
'Test input' +
|
||||
' \n' +
|
||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'pdf.pdf](pdf})'
|
||||
' \n' +
|
||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
|
||||
oldNote.content = testInput
|
||||
newNote.content = testInput
|
||||
|
||||
@@ -566,14 +779,22 @@ it('should test that isAttachmentLink works correctly', function () {
|
||||
expect(systemUnderTest.isAttachmentLink('text')).toBe(false)
|
||||
expect(systemUnderTest.isAttachmentLink('text [linkText](link)')).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('')).toBe(true)
|
||||
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf)')).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(' 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  test')).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('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('[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('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('[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 () {
|
||||
@@ -581,7 +802,7 @@ it('should test that handleAttachmentLinkPaste copies the attachments to the new
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-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')
|
||||
|
||||
@@ -596,12 +817,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'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-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 expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||
|
||||
@@ -622,8 +884,8 @@ it('should test that handleAttachmentLinkPaste copies multiple attachments if mu
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text  ..' +
|
||||
''
|
||||
const pasteText = 'text  ..' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
||||
@@ -647,7 +909,7 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const dummyNewFileName = 'dummyNewFileName'
|
||||
const pasteText = 'text '
|
||||
const pasteText = 'text '
|
||||
const expectedText = 'text '
|
||||
const storageKey = 'storageKey'
|
||||
|
||||
@@ -667,8 +929,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const dummyNewFileNameOne = 'dummyNewFileName'
|
||||
const dummyNewFileNameTwo = 'dummyNewFileNameTwo'
|
||||
const pasteText = 'text  ' +
|
||||
''
|
||||
const pasteText = 'text  ' +
|
||||
''
|
||||
const expectedText = 'text  ' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
@@ -689,8 +951,8 @@ it('should test that handleAttachmentLinkPaste calls the copy method correct if
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text  ..' +
|
||||
''
|
||||
const pasteText = 'text  ..' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
||||
@@ -716,7 +978,7 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text '
|
||||
const pasteText = 'text '
|
||||
const storageKey = 'storageKey'
|
||||
const fileNotFoundMD = 'file not found'
|
||||
const expectedPastText = 'text ' + fileNotFoundMD
|
||||
@@ -735,8 +997,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text  ' +
|
||||
''
|
||||
const pasteText = 'text  ' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const fileNotFoundMD = 'file not found'
|
||||
const expectedPastText = 'text ' + fileNotFoundMD + ' ' + fileNotFoundMD
|
||||
@@ -757,8 +1019,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const dummyFoundFileName = 'dummyFileName'
|
||||
const fileNotFoundMD = 'file not found'
|
||||
const pasteText = 'text  .. ' +
|
||||
''
|
||||
const pasteText = 'text  .. ' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const expectedPastText = 'text ' + fileNotFoundMD + ' .. '
|
||||
|
||||
@@ -781,8 +1043,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const dummyFoundFileName = 'dummyFileName'
|
||||
const fileNotFoundMD = 'file not found'
|
||||
const pasteText = 'text  .. ' +
|
||||
''
|
||||
const pasteText = 'text  .. ' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const expectedPastText = 'text  .. ' + fileNotFoundMD
|
||||
|
||||
|
||||
38
tests/dataApi/copyFile-test.js
Normal file
38
tests/dataApi/copyFile-test.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const test = require('ava')
|
||||
const copyFile = require('browser/main/lib/dataApi/copyFile')
|
||||
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const os = require('os')
|
||||
const execSync = require('child_process').execSync
|
||||
const removeDirCommand = os.platform() === 'win32' ? 'rmdir /s /q ' : 'rm -rf '
|
||||
|
||||
const testFile = 'test.txt'
|
||||
const srcFolder = path.join(__dirname, '🤔')
|
||||
const srcPath = path.join(srcFolder, testFile)
|
||||
const dstFolder = path.join(__dirname, '😇')
|
||||
const dstPath = path.join(dstFolder, testFile)
|
||||
|
||||
test.before((t) => {
|
||||
if (!fs.existsSync(srcFolder)) fs.mkdirSync(srcFolder)
|
||||
|
||||
fs.writeFileSync(srcPath, 'test')
|
||||
})
|
||||
|
||||
test('`copyFile` should handle encoded URI on src path', (t) => {
|
||||
return copyFile(encodeURI(srcPath), dstPath)
|
||||
.then(() => {
|
||||
t.true(true)
|
||||
})
|
||||
.catch(() => {
|
||||
t.true(false)
|
||||
})
|
||||
})
|
||||
|
||||
test.after((t) => {
|
||||
fs.unlinkSync(srcPath)
|
||||
fs.unlinkSync(dstPath)
|
||||
execSync(removeDirCommand + '"' + srcFolder + '"')
|
||||
execSync(removeDirCommand + '"' + dstFolder + '"')
|
||||
})
|
||||
|
||||
@@ -25,13 +25,16 @@ test.serial('Create a note', (t) => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const folderKey = t.context.storage.json.folders[0].key
|
||||
|
||||
const randLinesHighlightedArray = new Array(10).fill().map(() => Math.round(Math.random() * 10))
|
||||
|
||||
const input1 = {
|
||||
type: 'SNIPPET_NOTE',
|
||||
description: faker.lorem.lines(),
|
||||
snippets: [{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
content: faker.lorem.lines(),
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}],
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
@@ -42,7 +45,8 @@ test.serial('Create a note', (t) => {
|
||||
type: 'MARKDOWN_NOTE',
|
||||
content: faker.lorem.lines(),
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
folder: folderKey,
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}
|
||||
input2.title = input2.content.split('\n').shift()
|
||||
|
||||
@@ -59,6 +63,7 @@ test.serial('Create a note', (t) => {
|
||||
|
||||
t.is(storageKey, data1.storage)
|
||||
const jsonData1 = CSON.readFileSync(path.join(storagePath, 'notes', data1.key + '.cson'))
|
||||
|
||||
t.is(input1.title, data1.title)
|
||||
t.is(input1.title, jsonData1.title)
|
||||
t.is(input1.description, data1.description)
|
||||
@@ -71,6 +76,8 @@ test.serial('Create a note', (t) => {
|
||||
t.is(input1.snippets[0].content, jsonData1.snippets[0].content)
|
||||
t.is(input1.snippets[0].name, data1.snippets[0].name)
|
||||
t.is(input1.snippets[0].name, jsonData1.snippets[0].name)
|
||||
t.deepEqual(input1.snippets[0].linesHighlighted, data1.snippets[0].linesHighlighted)
|
||||
t.deepEqual(input1.snippets[0].linesHighlighted, jsonData1.snippets[0].linesHighlighted)
|
||||
|
||||
t.is(storageKey, data2.storage)
|
||||
const jsonData2 = CSON.readFileSync(path.join(storagePath, 'notes', data2.key + '.cson'))
|
||||
@@ -80,6 +87,8 @@ test.serial('Create a note', (t) => {
|
||||
t.is(input2.content, jsonData2.content)
|
||||
t.is(input2.tags.length, data2.tags.length)
|
||||
t.is(input2.tags.length, jsonData2.tags.length)
|
||||
t.deepEqual(input2.linesHighlighted, data2.linesHighlighted)
|
||||
t.deepEqual(input2.linesHighlighted, jsonData2.linesHighlighted)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
43
tests/dataApi/createNoteFromUrl-test.js
Normal file
43
tests/dataApi/createNoteFromUrl-test.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const test = require('ava')
|
||||
const createNoteFromUrl = require('browser/main/lib/dataApi/createNoteFromUrl')
|
||||
|
||||
global.document = require('jsdom').jsdom('<body></body>')
|
||||
global.window = document.defaultView
|
||||
global.navigator = window.navigator
|
||||
|
||||
const Storage = require('dom-storage')
|
||||
const localStorage = window.localStorage = global.localStorage = new Storage(null, { strict: true })
|
||||
const path = require('path')
|
||||
const TestDummy = require('../fixtures/TestDummy')
|
||||
const sander = require('sander')
|
||||
const os = require('os')
|
||||
const CSON = require('@rokt33r/season')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/create-note-from-url')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
test.serial('Create a note from URL', (t) => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const folderKey = t.context.storage.json.folders[0].key
|
||||
|
||||
const url = 'https://shapeshed.com/writing-cross-platform-node/'
|
||||
|
||||
return createNoteFromUrl(url, storageKey, folderKey)
|
||||
.then(function assert ({ note }) {
|
||||
t.is(storageKey, note.storage)
|
||||
const jsonData = CSON.readFileSync(path.join(storagePath, 'notes', note.key + '.cson'))
|
||||
|
||||
// Test if saved content is matching the created in memory note
|
||||
t.is(note.content, jsonData.content)
|
||||
t.is(note.tags.length, jsonData.tags.length)
|
||||
})
|
||||
})
|
||||
|
||||
test.after(function after () {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
@@ -26,6 +26,7 @@ test.serial('Create a snippet', (t) => {
|
||||
t.is(snippet.name, data.name)
|
||||
t.deepEqual(snippet.prefix, data.prefix)
|
||||
t.is(snippet.content, data.content)
|
||||
t.deepEqual(snippet.linesHighlighted, data.linesHighlighted)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -26,13 +26,17 @@ test.serial('Update a note', (t) => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const folderKey = t.context.storage.json.folders[0].key
|
||||
|
||||
const randLinesHighlightedArray = new Array(10).fill().map(() => Math.round(Math.random() * 10))
|
||||
const randLinesHighlightedArray2 = new Array(15).fill().map(() => Math.round(Math.random() * 15))
|
||||
|
||||
const input1 = {
|
||||
type: 'SNIPPET_NOTE',
|
||||
description: faker.lorem.lines(),
|
||||
snippets: [{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
content: faker.lorem.lines(),
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}],
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
@@ -43,7 +47,8 @@ test.serial('Update a note', (t) => {
|
||||
type: 'MARKDOWN_NOTE',
|
||||
content: faker.lorem.lines(),
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
folder: folderKey,
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}
|
||||
input2.title = input2.content.split('\n').shift()
|
||||
|
||||
@@ -53,7 +58,8 @@ test.serial('Update a note', (t) => {
|
||||
snippets: [{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
content: faker.lorem.lines(),
|
||||
linesHighlighted: randLinesHighlightedArray2
|
||||
}],
|
||||
tags: faker.lorem.words().split(' ')
|
||||
}
|
||||
@@ -62,7 +68,8 @@ test.serial('Update a note', (t) => {
|
||||
const input4 = {
|
||||
type: 'MARKDOWN_NOTE',
|
||||
content: faker.lorem.lines(),
|
||||
tags: faker.lorem.words().split(' ')
|
||||
tags: faker.lorem.words().split(' '),
|
||||
linesHighlighted: randLinesHighlightedArray2
|
||||
}
|
||||
input4.title = input4.content.split('\n').shift()
|
||||
|
||||
@@ -99,6 +106,8 @@ test.serial('Update a note', (t) => {
|
||||
t.is(input3.snippets[0].content, jsonData1.snippets[0].content)
|
||||
t.is(input3.snippets[0].name, data1.snippets[0].name)
|
||||
t.is(input3.snippets[0].name, jsonData1.snippets[0].name)
|
||||
t.deepEqual(input3.snippets[0].linesHighlighted, data1.snippets[0].linesHighlighted)
|
||||
t.deepEqual(input3.snippets[0].linesHighlighted, jsonData1.snippets[0].linesHighlighted)
|
||||
|
||||
const jsonData2 = CSON.readFileSync(path.join(storagePath, 'notes', data2.key + '.cson'))
|
||||
t.is(input4.title, data2.title)
|
||||
@@ -107,6 +116,8 @@ test.serial('Update a note', (t) => {
|
||||
t.is(input4.content, jsonData2.content)
|
||||
t.is(input4.tags.length, data2.tags.length)
|
||||
t.is(input4.tags.length, jsonData2.tags.length)
|
||||
t.deepEqual(input4.linesHighlighted, data2.linesHighlighted)
|
||||
t.deepEqual(input4.linesHighlighted, jsonData2.linesHighlighted)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
92
tests/fixtures/markdowns.js
vendored
92
tests/fixtures/markdowns.js
vendored
@@ -104,6 +104,89 @@ Term 2 with *inline markup*
|
||||
`
|
||||
const shortcuts = '<kbd>Ctrl</kbd>\n\n[[Ctrl]]'
|
||||
|
||||
const footnote = `
|
||||
^[hello-world]
|
||||
hello-world: https://github.com/BoostIO/Boostnote/
|
||||
`
|
||||
|
||||
const tocPlaceholder = `
|
||||
[TOC]
|
||||
# H1
|
||||
## H2
|
||||
### H3
|
||||
###$ H4
|
||||
`
|
||||
|
||||
const plantUmlMindMap = `
|
||||
@startmindmap
|
||||
* Debian
|
||||
** Ubuntu
|
||||
*** Linux Mint
|
||||
*** Kubuntu
|
||||
*** Lubuntu
|
||||
*** KDE Neon
|
||||
** LMDE
|
||||
** SolydXK
|
||||
** SteamOS
|
||||
** Raspbian with a very long name
|
||||
*** <s>Raspmbc</s> => OSMC
|
||||
*** <s>Raspyfi</s> => Volumio
|
||||
@endmindmap
|
||||
`
|
||||
|
||||
const plantUmlGantt = `
|
||||
@startgantt
|
||||
[Prototype design] lasts 15 days
|
||||
[Test prototype] lasts 10 days
|
||||
[Test prototype] starts at [Prototype design]'s end
|
||||
@endgantt
|
||||
`
|
||||
|
||||
const plantUmlWbs = `
|
||||
@startwbs
|
||||
* Business Process Modelling WBS
|
||||
** Launch the project
|
||||
*** Complete Stakeholder Research
|
||||
*** Initial Implementation Plan
|
||||
** Design phase
|
||||
*** Model of AsIs Processes Completed
|
||||
**** Model of AsIs Processes Completed1
|
||||
**** Model of AsIs Processes Completed2
|
||||
*** Measure AsIs performance metrics
|
||||
*** Identify Quick Wins
|
||||
** Complete innovate phase
|
||||
@endwbs
|
||||
`
|
||||
|
||||
const plantUmlUml = `
|
||||
@startuml
|
||||
left to right direction
|
||||
skinparam packageStyle rectangle
|
||||
actor customer
|
||||
actor clerk
|
||||
rectangle checkout {
|
||||
customer -- (checkout)
|
||||
(checkout) .> (payment) : include
|
||||
(help) .> (checkout) : extends
|
||||
(checkout) -- clerk
|
||||
}
|
||||
@enduml
|
||||
`
|
||||
|
||||
const plantUmlDitaa = `
|
||||
@startditaa
|
||||
+--------+ +-------+ +-------+
|
||||
| +---+ ditaa +--> | |
|
||||
| Text | +-------+ |Diagram|
|
||||
|Dokument| |!Magie!| | |
|
||||
| {d}| | | | |
|
||||
+---+----+ +-------+ +-------+
|
||||
: ^
|
||||
| Ein Haufen Arbeit |
|
||||
+-------------------------+
|
||||
@endditaa
|
||||
`
|
||||
|
||||
export default {
|
||||
basic,
|
||||
codeblock,
|
||||
@@ -115,5 +198,12 @@ export default {
|
||||
subTexts,
|
||||
supTexts,
|
||||
deflists,
|
||||
shortcuts
|
||||
shortcuts,
|
||||
footnote,
|
||||
tocPlaceholder,
|
||||
plantUmlMindMap,
|
||||
plantUmlGantt,
|
||||
plantUmlWbs,
|
||||
plantUmlDitaa,
|
||||
plantUmlUml
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ const noop = () => {}
|
||||
mock('electron', {
|
||||
remote: {
|
||||
app: {
|
||||
getAppPath: noop
|
||||
getAppPath: noop,
|
||||
getPath: noop
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
138
tests/lib/contextMenuBuilder.test.js
Normal file
138
tests/lib/contextMenuBuilder.test.js
Normal file
@@ -0,0 +1,138 @@
|
||||
let menuBuilderParameter
|
||||
jest.mock('electron', () => {
|
||||
return {remote: {require: jest.fn(() => { return {Menu: {buildFromTemplate: jest.fn((param) => { menuBuilderParameter = param })}} })}}
|
||||
})
|
||||
|
||||
const spellcheck = require('browser/lib/spellcheck')
|
||||
const buildEditorContextMenu = require('browser/lib/contextMenuBuilder').buildEditorContextMenu
|
||||
const buildMarkdownPreviewContextMenu = require('browser/lib/contextMenuBuilder').buildMarkdownPreviewContextMenu
|
||||
|
||||
beforeEach(() => {
|
||||
menuBuilderParameter = null
|
||||
})
|
||||
|
||||
// Editor Context Menu
|
||||
it('should make sure that no context menu is build if the passed editor instance was null', function () {
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
}
|
||||
buildEditorContextMenu(null, event)
|
||||
expect(menuBuilderParameter).toEqual(null)
|
||||
})
|
||||
|
||||
it('should make sure that word suggestions are only requested if the word contained a typo', function () {
|
||||
spellcheck.getSpellingSuggestion = jest.fn()
|
||||
const editor = jest.fn()
|
||||
editor.coordsChar = jest.fn()
|
||||
editor.findWordAt = jest.fn(() => { return {anchor: {}, head: {}} })
|
||||
editor.getRange = jest.fn()
|
||||
editor.findMarks = jest.fn(() => [])
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
}
|
||||
const expectedMenuParameter = [ { role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'selectall' } ]
|
||||
buildEditorContextMenu(editor, event)
|
||||
expect(menuBuilderParameter).toEqual(expectedMenuParameter)
|
||||
expect(spellcheck.getSpellingSuggestion).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should make sure that word suggestions are only requested if the word contained a typo and no other mark', function () {
|
||||
spellcheck.getSpellingSuggestion = jest.fn()
|
||||
spellcheck.getCSSClassName = jest.fn(() => 'dummyErrorClassName')
|
||||
const editor = jest.fn()
|
||||
editor.coordsChar = jest.fn()
|
||||
editor.findWordAt = jest.fn(() => { return {anchor: {}, head: {}} })
|
||||
editor.getRange = jest.fn()
|
||||
const dummyMarks = [
|
||||
{className: 'someStupidClassName'}
|
||||
]
|
||||
editor.findMarks = jest.fn(() => dummyMarks)
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
}
|
||||
const expectedMenuParameter = [ { role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'selectall' } ]
|
||||
buildEditorContextMenu(editor, event)
|
||||
expect(menuBuilderParameter).toEqual(expectedMenuParameter)
|
||||
expect(spellcheck.getSpellingSuggestion).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should make sure that word suggestions calls the right editor functions', function () {
|
||||
spellcheck.getSpellingSuggestion = jest.fn()
|
||||
spellcheck.getCSSClassName = jest.fn(() => 'dummyErrorClassName')
|
||||
const dummyCursor = {dummy: 'dummy'}
|
||||
const dummyRange = {anchor: {test: 'test'}, head: {test2: 'test2'}}
|
||||
const editor = jest.fn()
|
||||
editor.coordsChar = jest.fn(() => dummyCursor)
|
||||
editor.findWordAt = jest.fn(() => dummyRange)
|
||||
editor.getRange = jest.fn()
|
||||
const dummyMarks = [
|
||||
{className: 'someStupidClassName'}
|
||||
]
|
||||
editor.findMarks = jest.fn(() => dummyMarks)
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 21
|
||||
}
|
||||
|
||||
const expectedCoordsCharCall = {left: event.pageX, top: event.pageY}
|
||||
|
||||
buildEditorContextMenu(editor, event)
|
||||
|
||||
expect(editor.coordsChar).toHaveBeenCalledWith(expectedCoordsCharCall)
|
||||
expect(editor.findWordAt).toHaveBeenCalledWith(dummyCursor)
|
||||
expect(editor.getRange).toHaveBeenCalledWith(dummyRange.anchor, dummyRange.head)
|
||||
})
|
||||
|
||||
it('should make sure that word suggestions creates a correct menu if there was an error', function () {
|
||||
const suggestions = ['test1', 'test2', 'Pustekuchen']
|
||||
const errorClassName = 'errorCSS'
|
||||
const wordToCorrect = 'pustekuchen'
|
||||
const dummyMarks = [
|
||||
{className: errorClassName}
|
||||
]
|
||||
spellcheck.getSpellingSuggestion = jest.fn(() => suggestions)
|
||||
spellcheck.getCSSClassName = jest.fn(() => errorClassName)
|
||||
const editor = jest.fn()
|
||||
editor.coordsChar = jest.fn()
|
||||
editor.findWordAt = jest.fn(() => { return {anchor: {}, head: {}} })
|
||||
editor.getRange = jest.fn(() => wordToCorrect)
|
||||
editor.findMarks = jest.fn(() => [])
|
||||
|
||||
editor.findMarks = jest.fn(() => dummyMarks)
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
}
|
||||
buildEditorContextMenu(editor, event)
|
||||
expect(menuBuilderParameter[0].label).toEqual(suggestions[0])
|
||||
expect(menuBuilderParameter[0].click).not.toBeNull()
|
||||
expect(menuBuilderParameter[1].label).toEqual(suggestions[1])
|
||||
expect(menuBuilderParameter[1].click).not.toBeNull()
|
||||
expect(menuBuilderParameter[2].label).toEqual(suggestions[2])
|
||||
expect(menuBuilderParameter[2].click).not.toBeNull()
|
||||
expect(menuBuilderParameter[3].type).toEqual('separator')
|
||||
expect(menuBuilderParameter[4].role).toEqual('cut')
|
||||
expect(menuBuilderParameter[5].role).toEqual('copy')
|
||||
expect(menuBuilderParameter[6].role).toEqual('paste')
|
||||
expect(menuBuilderParameter[7].role).toEqual('selectall')
|
||||
expect(spellcheck.getSpellingSuggestion).toHaveBeenCalledWith(wordToCorrect)
|
||||
})
|
||||
|
||||
// Markdown Preview Context Menu
|
||||
it('should make sure that no context menu is built if the Markdown Preview instance was null', function () {
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
}
|
||||
buildMarkdownPreviewContextMenu(null, event)
|
||||
expect(menuBuilderParameter).toEqual(null)
|
||||
})
|
||||
@@ -28,7 +28,14 @@ test('getTodoStatus should return a correct hash object', t => {
|
||||
['- [x] `- [x] a`\n', { total: 1, completed: 1 }],
|
||||
['- [X] `- [X] a`\n', { total: 1, completed: 1 }],
|
||||
[' \t - [X] `- [X] a`\n', { total: 1, completed: 1 }],
|
||||
[' \t - [X] `- [X] a`\n \t - [ ] `- [X] a`\n', { total: 2, completed: 1 }]
|
||||
[' \t - [X] `- [X] a`\n \t - [ ] `- [X] a`\n', { total: 2, completed: 1 }],
|
||||
['> - [ ] a\n', { total: 1, completed: 0 }],
|
||||
['> - [ ] a\n- [x] a\n', { total: 2, completed: 1 }],
|
||||
['> + [ ] a\n+ foo [x]bar a\n', { total: 1, completed: 0 }],
|
||||
['> - [X] `- [X] a`\n', { total: 1, completed: 1 }],
|
||||
['> \t - [X] `- [X] a`\n', { total: 1, completed: 1 }],
|
||||
['> > - [ ] a\n', { total: 1, completed: 0 }],
|
||||
['> > > - [ ] a\n- [x] a\n', { total: 2, completed: 1 }]
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
|
||||
@@ -68,3 +68,38 @@ test('Markdown.render() should render shortcuts correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.shortcuts)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should render footnote correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.footnote)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders [TOC] placholder correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.tocPlaceholder)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML MindMaps correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlMindMap)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML Gantt correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlGantt)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML WBS correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlWbs)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML Umls correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlUml)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML Ditaa correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlDitaa)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
@@ -36,7 +36,8 @@ test(t => {
|
||||
['`MY_TITLE`', 'MY_TITLE'],
|
||||
['MY_TITLE', 'MY_TITLE'],
|
||||
// I have no idea for it...
|
||||
['```test', '`test']
|
||||
['```test', '`test'],
|
||||
['# C# Features', 'C# Features']
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
|
||||
58
tests/lib/slugify-test.js
Normal file
58
tests/lib/slugify-test.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import test from 'ava'
|
||||
import slugify from 'browser/lib/slugify'
|
||||
|
||||
test('alphabet and digit', t => {
|
||||
const upperAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
const lowerAlphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
const digit = '0123456789'
|
||||
const testCase = upperAlphabet + lowerAlphabet + digit
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
t.true(decodeSlug === testCase)
|
||||
})
|
||||
|
||||
test('should delete unavailable symbols', t => {
|
||||
const availableSymbols = '_-'
|
||||
const testCase = availableSymbols + '][!\'#$%&()*+,./:;<=>?@\\^{|}~`'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
t.true(decodeSlug === availableSymbols)
|
||||
})
|
||||
|
||||
test('should convert from white spaces between words to hyphens', t => {
|
||||
const testCase = 'This is one'
|
||||
const expectedString = 'This-is-one'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
t.true(decodeSlug === expectedString)
|
||||
})
|
||||
|
||||
test('should remove leading white spaces', t => {
|
||||
const testCase = ' This is one'
|
||||
const expectedString = 'This-is-one'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
t.true(decodeSlug === expectedString)
|
||||
})
|
||||
|
||||
test('should remove trailing white spaces', t => {
|
||||
const testCase = 'This is one '
|
||||
const expectedString = 'This-is-one'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
t.true(decodeSlug === expectedString)
|
||||
})
|
||||
|
||||
test('2-byte charactor support', t => {
|
||||
const testCase = '菠萝芒果テストÀžƁƵ'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
t.true(decodeSlug === testCase)
|
||||
})
|
||||
|
||||
test('emoji', t => {
|
||||
const testCase = '🌸'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
t.true(decodeSlug === testCase)
|
||||
})
|
||||
@@ -4,6 +4,56 @@ The actual snapshot is saved in `markdown-test.js.snap`.
|
||||
|
||||
Generated by [AVA](https://ava.li).
|
||||
|
||||
## Markdown.render() should render PlantUML Ditaa correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/png/SoWkIImgISaiIKpaqjQ50cq51GLj93Q2mrMZ00NQO3cmHX3RJW4cKmDI4v9QKQ805a8nfyObCp6zA34NgCObFxiqDpMl1AIcHj4tCJqpLH5i18evG52TKbk3B8og1kmC0cvMKB1Im0NYkA2ckMRcANWabgQbvYau5YMbPfP0p4UOWmcqkHnIyrB0GG00" alt="uml diagram" />␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render PlantUML Gantt correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/svg/SoWkIImgIK_CAodXYWueoY_9BwaiI5L8IItEJC-BLSX9B2ufLZ0qLKX9h2pcYWv9BIvHA82fWaiRu906crsia5YYW6cqUh52QbuAbmEG0DiE0000" alt="uml diagram" />␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render PlantUML MindMaps correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/svg/JOzD3e8m44Rtd6BMtNW192IM5I29HEDsAbKdeLD2MvNRIsjCMCsRlFd9LpgFipV4Wy4f4o2r8kHC23Yhm3wi9A0X3XzeYNrgwx1H6wvb1KTjqtRJoYhMtexBSAqJUescwoEUq4tn3xp9Fm7XfUS5HiiFO3Gw7SjT4QUCkkKxLy2-WAvl3rkrtEclBdOCXcnMwZN7ByiN" alt="uml diagram" />␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render PlantUML Umls correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/svg/LOzD2eCm44RtESMtj0jx01V5E_G4Gvngo2_912gbTsz4LBfylCV7p5Y4ibJlbEENG2AocHV1P39hCJ6eOar8bCaZaROqyrDMnzWqXTcn8YqnGzSYqNC-q76sweoW5zOsLi57uMpHz-WESslY0jmVw1AjdaE30IPeLoVUceLTslrL3-2tS9ZA_qZRtm_vgh7PzkOF" alt="uml diagram" />␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render PlantUML WBS correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/svg/ZP2_JiD03CRtFeNdRF04fR140gdGeREv-z8plVYYimFYxSabKbaxsR9-ylTdRyxLVpvjrz5XDb6OqR6MqEPRYSXPz4BdmsdNTVJAiuP4da1JBLy8lbmxUYxZbE6Wa_CLgUI8IXymS0rf9NeL5yxKDt24EhiKfMDcRNzVO79HcX8RLdvLfZBGa_KtFx2RKcpK7TZ3dTpZfWgskMAZ9jIXr94rW4PubM1RbBZOb-6NtcS9LpgBjlj_1w9QldbPjZHxQ5pg_GC0" alt="uml diagram" />␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render footnote correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<p data-line="1"><sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup><br />␊
|
||||
hello-world: <a href="https://github.com/BoostIO/Boostnote/">https://github.com/BoostIO/Boostnote/</a></p>␊
|
||||
<hr class="footnotes-sep" />␊
|
||||
<section class="footnotes">␊
|
||||
<ol class="footnotes-list">␊
|
||||
<li id="fn1" class="footnote-item"><p>hello-world <a href="#fnref1" class="footnote-backref">↩︎</a></p>␊
|
||||
</li>␊
|
||||
</ol>␊
|
||||
</section>␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render line breaks correctly
|
||||
|
||||
> Snapshot 1
|
||||
@@ -30,14 +80,36 @@ Generated by [AVA](https://ava.li).
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>c</mi><mo>=</mo><mi>p</mi><mi>m</mi><mi>s</mi><mi>q</mi><mi>r</mi><mi>t</mi><mrow><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup></mrow></mrow><annotation encoding="application/x-tex">c = pmsqrt{a^2 + b^2}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8641079999999999em;"></span><span class="strut bottom" style="height:1.0585479999999998em;vertical-align:-0.19444em;"></span><span class="base"><span class="mord mathit">c</span><span class="mord rule" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mord rule" style="margin-right:0.2777777777777778em;"></span><span class="mord mathit">p</span><span class="mord mathit">m</span><span class="mord mathit">s</span><span class="mord mathit" style="margin-right:0.03588em;">q</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">t</span><span class="mord"><span class="mord"><span class="mord mathit">a</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mord rule" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mord rule" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord mathit">b</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span></span></span></span>␊
|
||||
`<span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>c</mi><mo>=</mo><mi>p</mi><mi>m</mi><mi>s</mi><mi>q</mi><mi>r</mi><mi>t</mi><mrow><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup></mrow></mrow><annotation encoding="application/x-tex">c = pmsqrt{a^2 + b^2}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathdefault">c</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.0585479999999998em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">p</span><span class="mord mathdefault">m</span><span class="mord mathdefault">s</span><span class="mord mathdefault" style="margin-right:0.03588em;">q</span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mord mathdefault">t</span><span class="mord"><span class="mord"><span class="mord mathdefault">a</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord mathdefault">b</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span></span></span></span>␊
|
||||
`
|
||||
|
||||
## Markdown.render() should renders [TOC] placholder correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<p data-line="1"><ul class="markdownIt-TOC">␊
|
||||
<li><a href="#H1">H1</a>␊
|
||||
<ul>␊
|
||||
<li><a href="#H2">H2</a>␊
|
||||
<ul>␊
|
||||
<li><a href="#H3">H3</a></li>␊
|
||||
</ul>␊
|
||||
</li>␊
|
||||
</ul>␊
|
||||
</li>␊
|
||||
</ul>␊
|
||||
</p>␊
|
||||
<h1 id="H1" data-line="2">H1</h1>␊
|
||||
<h2 id="H2" data-line="3">H2</h2>␊
|
||||
<h3 id="H3" data-line="4">H3</h3>␊
|
||||
<p data-line="5">###$ H4</p>␊
|
||||
`
|
||||
|
||||
## Markdown.render() should renders abbrevations correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<h2 data-line="1" id="abbr">abbr</h2>␊
|
||||
`<h2 id="abbr" data-line="1">abbr</h2>␊
|
||||
<p data-line="3">The <abbr title="Hyper Text Markup Language">HTML</abbr> specification<br />␊
|
||||
is maintained by the <abbr title="World Wide Web Consortium">W3C</abbr>.</p>␊
|
||||
`
|
||||
@@ -67,8 +139,8 @@ Generated by [AVA](https://ava.li).
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<h2 data-line="1" id="definition-list">definition list</h2>␊
|
||||
<h3 data-line="3" id="list-1">list 1</h3>␊
|
||||
`<h2 id="definition-list" data-line="1">definition list</h2>␊
|
||||
<h3 id="list-1" data-line="3">list 1</h3>␊
|
||||
<dl>␊
|
||||
<dt data-line="5">Term 1</dt>␊
|
||||
<dd data-line="6">Definition 1</dd>␊
|
||||
@@ -78,7 +150,7 @@ Generated by [AVA](https://ava.li).
|
||||
</dl>␊
|
||||
<p data-line="12">Term 3<br />␊
|
||||
~</p>␊
|
||||
<h3 data-line="16" id="list-2">list 2</h3>␊
|
||||
<h3 id="list-2" data-line="16">list 2</h3>␊
|
||||
<dl>␊
|
||||
<dt data-line="18">Term 1</dt>␊
|
||||
<dd data-line="20">␊
|
||||
@@ -98,10 +170,10 @@ Generated by [AVA](https://ava.li).
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<h1 data-line="1" id="Welcome-to-Boostnote">Welcome to Boostnote!</h1>␊
|
||||
<h2 data-line="2" id="Click-here-to-edit-markdown-%F0%9F%91%8B">Click here to edit markdown 👋</h2>␊
|
||||
`<h1 id="Welcome-to-Boostnote" data-line="1">Welcome to Boostnote!</h1>␊
|
||||
<h2 id="Click-here-to-edit-markdown" data-line="2">Click here to edit markdown 👋</h2>␊
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/L0qNPLsvmyM" frameborder="0" allowfullscreen></iframe>␊
|
||||
<h2 data-line="6" id="Docs-%F0%9F%93%9D">Docs 📝</h2>␊
|
||||
<h2 id="Docs" data-line="6">Docs 📝</h2>␊
|
||||
<ul>␊
|
||||
<li data-line="7"><a href="https://hackernoon.com/boostnote-boost-your-happiness-productivity-and-creativity-315034efeebe">Boostnote | Boost your happiness, productivity and creativity.</a></li>␊
|
||||
<li data-line="8"><a href="https://github.com/BoostIO/Boostnote/wiki/Cloud-Syncing-and-Backup">Cloud Syncing & Backups</a></li>␊
|
||||
@@ -112,7 +184,7 @@ Generated by [AVA](https://ava.li).
|
||||
<li data-line="13"><a href="https://github.com/BoostIO/Boostnote/wiki/Syntax-Highlighting">How to set syntax highlight in Snippet note</a></li>␊
|
||||
</ul>␊
|
||||
<hr />␊
|
||||
<h2 data-line="17" id="Article-Archive-%F0%9F%93%9A">Article Archive 📚</h2>␊
|
||||
<h2 id="Article-Archive" data-line="17">Article Archive 📚</h2>␊
|
||||
<ul>␊
|
||||
<li data-line="18"><a href="http://bit.ly/2mOJPu7">Reddit English</a></li>␊
|
||||
<li data-line="19"><a href="https://www.reddit.com/r/boostnote_es/">Reddit Spanish</a></li>␊
|
||||
@@ -120,7 +192,7 @@ Generated by [AVA](https://ava.li).
|
||||
<li data-line="21"><a href="https://www.reddit.com/r/boostnote_jp/">Reddit Japanese</a></li>␊
|
||||
</ul>␊
|
||||
<hr />␊
|
||||
<h2 data-line="25" id="Community-%F0%9F%8D%BB">Community 🍻</h2>␊
|
||||
<h2 id="Community" data-line="25">Community 🍻</h2>␊
|
||||
<ul>␊
|
||||
<li data-line="26"><a href="http://bit.ly/2AWWzkD">GitHub</a></li>␊
|
||||
<li data-line="27"><a href="http://bit.ly/2z8BUJZ">Twitter</a></li>␊
|
||||
@@ -132,7 +204,7 @@ Generated by [AVA](https://ava.li).
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<h2 data-line="1" id="sub">sub</h2>␊
|
||||
`<h2 id="sub" data-line="1">sub</h2>␊
|
||||
<p data-line="3">H<sub>2</sub>0</p>␊
|
||||
`
|
||||
|
||||
@@ -140,7 +212,7 @@ Generated by [AVA](https://ava.li).
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<h2 data-line="1" id="sup">sup</h2>␊
|
||||
`<h2 id="sup" data-line="1">sup</h2>␊
|
||||
<p data-line="3">29<sup>th</sup></p>␊
|
||||
`
|
||||
|
||||
@@ -154,4 +226,39 @@ Generated by [AVA](https://ava.li).
|
||||
> Snapshot 2
|
||||
|
||||
`<p data-line="0">This is a "QUOTE".</p>␊
|
||||
|
||||
|
||||
## Markdown.render() should render PlantUML Ditaa correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/png/SoWkIImgISaiIKpaqjQ50cq51GLj93Q2mrMZ00NQO3cmHX3RJW4cKmDI4v9QKQ805a8nfyObCp6zA34NgCObFxiqDpMl1AIcHj4tCJqpLH5i18evG52TKbk3B8og1kmC0cvMKB1Im0NYkA2ckMRcANWabgQbvYau5YMbPfP0p4UOWmcqkHnIyrB0GG00" alt="uml diagram" />␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render PlantUML Gantt correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/svg/SoWkIImgIK_CAodXYWueoY_9BwaiI5L8IItEJC-BLSX9B2ufLZ0qLKX9h2pcYWv9BIvHA82fWaiRu906crsia5YYW6cqUh52QbuAbmEG0DiE0000" alt="uml diagram" />␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render PlantUML MindMaps correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/svg/JOzD3e8m44Rtd6BMtNW192IM5I29HEDsAbKdeLD2MvNRIsjCMCsRlFd9LpgFipV4Wy4f4o2r8kHC23Yhm3wi9A0X3XzeYNrgwx1H6wvb1KTjqtRJoYhMtexBSAqJUescwoEUq4tn3xp9Fm7XfUS5HiiFO3Gw7SjT4QUCkkKxLy2-WAvl3rkrtEclBdOCXcnMwZN7ByiN" alt="uml diagram" />␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render PlantUML Umls correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/svg/LOzD2eCm44RtESMtj0jx01V5E_G4Gvngo2_912gbTsz4LBfylCV7p5Y4ibJlbEENG2AocHV1P39hCJ6eOar8bCaZaROqyrDMnzWqXTcn8YqnGzSYqNC-q76sweoW5zOsLi57uMpHz-WESslY0jmVw1AjdaE30IPeLoVUceLTslrL3-2tS9ZA_qZRtm_vgh7PzkOF" alt="uml diagram" />␊
|
||||
`
|
||||
|
||||
## Markdown.render() should render PlantUML WBS correctly
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<img src="http://www.plantuml.com/plantuml/svg/ZP2_JiD03CRtFeNdRF04fR140gdGeREv-z8plVYYimFYxSabKbaxsR9-ylTdRyxLVpvjrz5XDb6OqR6MqEPRYSXPz4BdmsdNTVJAiuP4da1JBLy8lbmxUYxZbE6Wa_CLgUI8IXymS0rf9NeL5yxKDt24EhiKfMDcRNzVO79HcX8RLdvLfZBGa_KtFx2RKcpK7TZ3dTpZfWgskMAZ9jIXr94rW4PubM1RbBZOb-6NtcS9LpgBjlj_1w9QldbPjZHxQ5pg_GC0" alt="uml diagram" />␊
|
||||
`
|
||||
Binary file not shown.
330
tests/lib/spellcheck.test.js
Normal file
330
tests/lib/spellcheck.test.js
Normal file
@@ -0,0 +1,330 @@
|
||||
const Typo = require('typo-js')
|
||||
const CodeMirror = require('codemirror')
|
||||
jest.mock('typo-js')
|
||||
|
||||
const systemUnderTest = require('browser/lib/spellcheck')
|
||||
|
||||
beforeEach(() => {
|
||||
// Clear all instances and calls to constructor and all methods:
|
||||
Typo.mockClear()
|
||||
})
|
||||
|
||||
it('should test that checkWord does not marks words that do not contain a typo', function () {
|
||||
const testWord = 'testWord'
|
||||
const editor = jest.fn()
|
||||
editor.getRange = jest.fn(() => testWord)
|
||||
editor.markText = jest.fn()
|
||||
const range = {anchor: {line: 1, ch: 0}, head: {line: 1, ch: 10}}
|
||||
const mockDictionary = jest.fn()
|
||||
mockDictionary.check = jest.fn(() => true)
|
||||
systemUnderTest.setDictionaryForTestsOnly(mockDictionary)
|
||||
|
||||
systemUnderTest.checkWord(editor, range)
|
||||
|
||||
expect(editor.getRange).toHaveBeenCalledWith(range.anchor, range.head)
|
||||
expect(mockDictionary.check).toHaveBeenCalledWith(testWord)
|
||||
expect(editor.markText).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should test that checkWord should marks words that contain a typo', function () {
|
||||
const testWord = 'testWord'
|
||||
const editor = jest.fn()
|
||||
editor.getRange = jest.fn(() => testWord)
|
||||
editor.markText = jest.fn()
|
||||
const range = {anchor: {line: 1, ch: 0}, head: {line: 1, ch: 10}}
|
||||
const mockDictionary = jest.fn()
|
||||
mockDictionary.check = jest.fn(() => false)
|
||||
systemUnderTest.setDictionaryForTestsOnly(mockDictionary)
|
||||
|
||||
systemUnderTest.checkWord(editor, range)
|
||||
|
||||
expect(editor.getRange).toHaveBeenCalledWith(range.anchor, range.head)
|
||||
expect(mockDictionary.check).toHaveBeenCalledWith(testWord)
|
||||
expect(editor.markText).toHaveBeenCalledWith(range.anchor, range.head, {'className': systemUnderTest.CSS_ERROR_CLASS})
|
||||
})
|
||||
|
||||
it('should test that setLanguage clears all marks', function () {
|
||||
const dummyMarks = [
|
||||
{clear: jest.fn()},
|
||||
{clear: jest.fn()},
|
||||
{clear: jest.fn()}
|
||||
]
|
||||
const editor = jest.fn()
|
||||
editor.getAllMarks = jest.fn(() => dummyMarks)
|
||||
|
||||
systemUnderTest.setLanguage(editor, systemUnderTest.SPELLCHECK_DISABLED)
|
||||
|
||||
expect(editor.getAllMarks).toHaveBeenCalled()
|
||||
for (const dummyMark of dummyMarks) {
|
||||
expect(dummyMark.clear).toHaveBeenCalled()
|
||||
}
|
||||
})
|
||||
|
||||
it('should test that setLanguage with DISABLED as a lang argument should not load any dictionary and not check the whole document', function () {
|
||||
const editor = jest.fn()
|
||||
editor.getAllMarks = jest.fn(() => [])
|
||||
const checkWholeDocumentSpy = jest.spyOn(systemUnderTest, 'checkWholeDocument').mockImplementation()
|
||||
|
||||
systemUnderTest.setLanguage(editor, systemUnderTest.SPELLCHECK_DISABLED)
|
||||
|
||||
expect(Typo).not.toHaveBeenCalled()
|
||||
expect(checkWholeDocumentSpy).not.toHaveBeenCalled()
|
||||
checkWholeDocumentSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should test that setLanguage loads the correct dictionary', function () {
|
||||
const editor = jest.fn()
|
||||
editor.getAllMarks = jest.fn(() => [])
|
||||
const lang = 'de_DE'
|
||||
const checkWholeDocumentSpy = jest.spyOn(systemUnderTest, 'checkWholeDocument').mockImplementation()
|
||||
|
||||
expect(Typo).not.toHaveBeenCalled()
|
||||
systemUnderTest.setLanguage(editor, lang)
|
||||
|
||||
expect(Typo).toHaveBeenCalledWith(lang, false, false, expect.anything())
|
||||
expect(Typo.mock.calls[0][3].dictionaryPath).toEqual(systemUnderTest.DICTIONARY_PATH)
|
||||
expect(Typo.mock.calls[0][3].asyncLoad).toBe(true)
|
||||
checkWholeDocumentSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should test that checkMultiLineRange performs checks for each word in the stated range', function () {
|
||||
const dic = jest.fn()
|
||||
dic.check = jest.fn()
|
||||
systemUnderTest.setDictionaryForTestsOnly(dic)
|
||||
document.body.createTextRange = jest.fn(() => document.createElement('textArea'))
|
||||
const editor = new CodeMirror(jest.fn())
|
||||
editor.setValue(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vehicula sem id tempor sollicitudin. Sed eu sagittis ligula. Maecenas sit amet velit enim. Etiam massa urna, elementum et sapien sit amet, vestibulum pharetra lectus. Nulla consequat malesuada nunc in aliquam. Vivamus faucibus orci et faucibus maximus. Pellentesque at dolor ac mi mollis molestie in facilisis nisl.\n' +
|
||||
'\n' +
|
||||
'Nam id lacus et elit sollicitudin vestibulum. Phasellus blandit laoreet odio \n' +
|
||||
'Ut tristique risus et mi tristique, in aliquam odio laoreet. Curabitur nunc felis, mollis ut laoreet quis, finibus in nibh. Proin urna risus, rhoncus at diam interdum, maximus vestibulum nulla. Maecenas ut rutrum nulla, vel finibus est. Etiam placerat mi et libero volutpat, tristique rhoncus felis volutpat. Donec quam erat, congue quis ligula eget, mollis aliquet elit. Vestibulum feugiat odio sit amet ex dignissim, sit amet vulputate lectus iaculis. Sed tempus id enim at eleifend. Nullam bibendum eleifend congue. Pellentesque varius arcu elit, at accumsan dolor ultrices vitae. Etiam condimentum lectus id dolor fringilla tempor. Aliquam nec fringilla sem. Fusce ac quam porta, molestie nunc sed, semper nisl. Curabitur luctus sem in dapibus gravida. Suspendisse scelerisque mollis rutrum. Proin lacinia dolor sit amet ornare condimentum.\n' +
|
||||
'\n' +
|
||||
'In ex neque, volutpat quis ullamcorper in, vestibulum vel ligula. Quisque lobortis eget neque quis ullamcorper. Nunc purus lorem, scelerisque in malesuada id, congue a magna. Donec rutrum maximus egestas. Nulla ornare libero quis odio ultricies iaculis. Suspendisse consectetur bibendum purus ac blandit. Donec et neque quis dolor eleifend tempus. Fusce fringilla risus id venenatis rutrum. Mauris commodo posuere ipsum, sit amet hendrerit risus lacinia quis. Aenean placerat ultricies ante id dapibus. Donec imperdiet eros quis porttitor accumsan. Vestibulum ut nulla luctus velit feugiat elementum. Nam vel pharetra nisl. Nullam risus tellus, tempor quis ipsum et, pretium rutrum ipsum.\n' +
|
||||
'\n' +
|
||||
'Fusce molestie leo at facilisis mollis. Vivamus iaculis facilisis fermentum. Vivamus blandit id nisi sit amet porta. Nunc luctus porta blandit. Sed ac consequat eros, eu fringilla lorem. In blandit pharetra sollicitudin. Vivamus placerat risus ut ex faucibus, nec vehicula sapien imperdiet. Praesent luctus, leo eget ultrices cursus, neque ante porttitor mauris, id tempus tellus urna at ex. Curabitur elementum id quam vitae condimentum. Proin sit amet magna vel metus blandit iaculis. Phasellus viverra libero in lacus gravida, id laoreet ligula dapibus. Cras commodo arcu eget mi dignissim, et lobortis elit faucibus. Suspendisse potenti. ')
|
||||
const rangeFrom = {line: 2, ch: 4}
|
||||
const rangeTo = {line: 3, ch: 36}
|
||||
|
||||
systemUnderTest.checkMultiLineRange(editor, rangeFrom, rangeTo)
|
||||
|
||||
expect(dic.check).toHaveBeenCalledTimes(11)
|
||||
expect(dic.check.mock.calls[0][0]).toEqual('lacus')
|
||||
expect(dic.check.mock.calls[1][0]).toEqual('elit')
|
||||
expect(dic.check.mock.calls[2][0]).toEqual('sollicitudin')
|
||||
expect(dic.check.mock.calls[3][0]).toEqual('vestibulum')
|
||||
expect(dic.check.mock.calls[4][0]).toEqual('Phasellus')
|
||||
expect(dic.check.mock.calls[5][0]).toEqual('blandit')
|
||||
expect(dic.check.mock.calls[6][0]).toEqual('laoreet')
|
||||
expect(dic.check.mock.calls[7][0]).toEqual('odio')
|
||||
expect(dic.check.mock.calls[8][0]).toEqual('tristique')
|
||||
expect(dic.check.mock.calls[9][0]).toEqual('risus')
|
||||
expect(dic.check.mock.calls[10][0]).toEqual('tristique')
|
||||
})
|
||||
|
||||
it('should test that checkMultiLineRange works correct even when the range is inverted (from is the later position and to the lower)', function () {
|
||||
const dic = jest.fn()
|
||||
dic.check = jest.fn()
|
||||
systemUnderTest.setDictionaryForTestsOnly(dic)
|
||||
document.body.createTextRange = jest.fn(() => document.createElement('textArea'))
|
||||
const editor = new CodeMirror(jest.fn())
|
||||
editor.setValue(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vehicula sem id tempor sollicitudin. Sed eu sagittis ligula. Maecenas sit amet velit enim. Etiam massa urna, elementum et sapien sit amet, vestibulum pharetra lectus. Nulla consequat malesuada nunc in aliquam. Vivamus faucibus orci et faucibus maximus. Pellentesque at dolor ac mi mollis molestie in facilisis nisl.\n' +
|
||||
'\n' +
|
||||
'Nam id lacus et elit sollicitudin vestibulum. Phasellus blandit laoreet odio \n' +
|
||||
'Ut tristique risus et mi tristique, in aliquam odio laoreet. Curabitur nunc felis, mollis ut laoreet quis, finibus in nibh. Proin urna risus, rhoncus at diam interdum, maximus vestibulum nulla. Maecenas ut rutrum nulla, vel finibus est. Etiam placerat mi et libero volutpat, tristique rhoncus felis volutpat. Donec quam erat, congue quis ligula eget, mollis aliquet elit. Vestibulum feugiat odio sit amet ex dignissim, sit amet vulputate lectus iaculis. Sed tempus id enim at eleifend. Nullam bibendum eleifend congue. Pellentesque varius arcu elit, at accumsan dolor ultrices vitae. Etiam condimentum lectus id dolor fringilla tempor. Aliquam nec fringilla sem. Fusce ac quam porta, molestie nunc sed, semper nisl. Curabitur luctus sem in dapibus gravida. Suspendisse scelerisque mollis rutrum. Proin lacinia dolor sit amet ornare condimentum.\n' +
|
||||
'\n' +
|
||||
'In ex neque, volutpat quis ullamcorper in, vestibulum vel ligula. Quisque lobortis eget neque quis ullamcorper. Nunc purus lorem, scelerisque in malesuada id, congue a magna. Donec rutrum maximus egestas. Nulla ornare libero quis odio ultricies iaculis. Suspendisse consectetur bibendum purus ac blandit. Donec et neque quis dolor eleifend tempus. Fusce fringilla risus id venenatis rutrum. Mauris commodo posuere ipsum, sit amet hendrerit risus lacinia quis. Aenean placerat ultricies ante id dapibus. Donec imperdiet eros quis porttitor accumsan. Vestibulum ut nulla luctus velit feugiat elementum. Nam vel pharetra nisl. Nullam risus tellus, tempor quis ipsum et, pretium rutrum ipsum.\n' +
|
||||
'\n' +
|
||||
'Fusce molestie leo at facilisis mollis. Vivamus iaculis facilisis fermentum. Vivamus blandit id nisi sit amet porta. Nunc luctus porta blandit. Sed ac consequat eros, eu fringilla lorem. In blandit pharetra sollicitudin. Vivamus placerat risus ut ex faucibus, nec vehicula sapien imperdiet. Praesent luctus, leo eget ultrices cursus, neque ante porttitor mauris, id tempus tellus urna at ex. Curabitur elementum id quam vitae condimentum. Proin sit amet magna vel metus blandit iaculis. Phasellus viverra libero in lacus gravida, id laoreet ligula dapibus. Cras commodo arcu eget mi dignissim, et lobortis elit faucibus. Suspendisse potenti. ')
|
||||
const rangeFrom = {line: 3, ch: 36}
|
||||
const rangeTo = {line: 2, ch: 4}
|
||||
|
||||
systemUnderTest.checkMultiLineRange(editor, rangeFrom, rangeTo)
|
||||
|
||||
expect(dic.check).toHaveBeenCalledTimes(11)
|
||||
expect(dic.check.mock.calls[0][0]).toEqual('lacus')
|
||||
expect(dic.check.mock.calls[1][0]).toEqual('elit')
|
||||
expect(dic.check.mock.calls[2][0]).toEqual('sollicitudin')
|
||||
expect(dic.check.mock.calls[3][0]).toEqual('vestibulum')
|
||||
expect(dic.check.mock.calls[4][0]).toEqual('Phasellus')
|
||||
expect(dic.check.mock.calls[5][0]).toEqual('blandit')
|
||||
expect(dic.check.mock.calls[6][0]).toEqual('laoreet')
|
||||
expect(dic.check.mock.calls[7][0]).toEqual('odio')
|
||||
expect(dic.check.mock.calls[8][0]).toEqual('tristique')
|
||||
expect(dic.check.mock.calls[9][0]).toEqual('risus')
|
||||
expect(dic.check.mock.calls[10][0]).toEqual('tristique')
|
||||
})
|
||||
|
||||
it('should test that checkMultiLineRange works for single line', function () {
|
||||
const dic = jest.fn()
|
||||
dic.check = jest.fn()
|
||||
systemUnderTest.setDictionaryForTestsOnly(dic)
|
||||
document.body.createTextRange = jest.fn(() => document.createElement('textArea'))
|
||||
const editor = new CodeMirror(jest.fn())
|
||||
editor.setValue(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vehicula sem id tempor sollicitudin. Sed eu sagittis ligula. Maecenas sit amet velit enim. Etiam massa urna, elementum et sapien sit amet, vestibulum pharetra lectus. Nulla consequat malesuada nunc in aliquam. Vivamus faucibus orci et faucibus maximus. Pellentesque at dolor ac mi mollis molestie in facilisis nisl.\n' +
|
||||
'\n' +
|
||||
'Nam id lacus et elit sollicitudin vestibulum. Phasellus blandit laoreet odio \n' +
|
||||
'Ut tristique risus et mi tristique, in aliquam odio laoreet. Curabitur nunc felis, mollis ut laoreet quis, finibus in nibh. Proin urna risus, rhoncus at diam interdum, maximus vestibulum nulla. Maecenas ut rutrum nulla, vel finibus est. Etiam placerat mi et libero volutpat, tristique rhoncus felis volutpat. Donec quam erat, congue quis ligula eget, mollis aliquet elit. Vestibulum feugiat odio sit amet ex dignissim, sit amet vulputate lectus iaculis. Sed tempus id enim at eleifend. Nullam bibendum eleifend congue. Pellentesque varius arcu elit, at accumsan dolor ultrices vitae. Etiam condimentum lectus id dolor fringilla tempor. Aliquam nec fringilla sem. Fusce ac quam porta, molestie nunc sed, semper nisl. Curabitur luctus sem in dapibus gravida. Suspendisse scelerisque mollis rutrum. Proin lacinia dolor sit amet ornare condimentum.\n' +
|
||||
'\n' +
|
||||
'In ex neque, volutpat quis ullamcorper in, vestibulum vel ligula. Quisque lobortis eget neque quis ullamcorper. Nunc purus lorem, scelerisque in malesuada id, congue a magna. Donec rutrum maximus egestas. Nulla ornare libero quis odio ultricies iaculis. Suspendisse consectetur bibendum purus ac blandit. Donec et neque quis dolor eleifend tempus. Fusce fringilla risus id venenatis rutrum. Mauris commodo posuere ipsum, sit amet hendrerit risus lacinia quis. Aenean placerat ultricies ante id dapibus. Donec imperdiet eros quis porttitor accumsan. Vestibulum ut nulla luctus velit feugiat elementum. Nam vel pharetra nisl. Nullam risus tellus, tempor quis ipsum et, pretium rutrum ipsum.\n' +
|
||||
'\n' +
|
||||
'Fusce molestie leo at facilisis mollis. Vivamus iaculis facilisis fermentum. Vivamus blandit id nisi sit amet porta. Nunc luctus porta blandit. Sed ac consequat eros, eu fringilla lorem. In blandit pharetra sollicitudin. Vivamus placerat risus ut ex faucibus, nec vehicula sapien imperdiet. Praesent luctus, leo eget ultrices cursus, neque ante porttitor mauris, id tempus tellus urna at ex. Curabitur elementum id quam vitae condimentum. Proin sit amet magna vel metus blandit iaculis. Phasellus viverra libero in lacus gravida, id laoreet ligula dapibus. Cras commodo arcu eget mi dignissim, et lobortis elit faucibus. Suspendisse potenti. ')
|
||||
const rangeFrom = {line: 5, ch: 14}
|
||||
const rangeTo = {line: 5, ch: 39}
|
||||
|
||||
systemUnderTest.checkMultiLineRange(editor, rangeFrom, rangeTo)
|
||||
|
||||
expect(dic.check).toHaveBeenCalledTimes(3)
|
||||
expect(dic.check.mock.calls[0][0]).toEqual('volutpat')
|
||||
expect(dic.check.mock.calls[1][0]).toEqual('quis')
|
||||
expect(dic.check.mock.calls[2][0]).toEqual('ullamcorper')
|
||||
})
|
||||
|
||||
it('should test that checkMultiLineRange works for single word', function () {
|
||||
const dic = jest.fn()
|
||||
dic.check = jest.fn()
|
||||
systemUnderTest.setDictionaryForTestsOnly(dic)
|
||||
document.body.createTextRange = jest.fn(() => document.createElement('textArea'))
|
||||
const editor = new CodeMirror(jest.fn())
|
||||
editor.setValue(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vehicula sem id tempor sollicitudin. Sed eu sagittis ligula. Maecenas sit amet velit enim. Etiam massa urna, elementum et sapien sit amet, vestibulum pharetra lectus. Nulla consequat malesuada nunc in aliquam. Vivamus faucibus orci et faucibus maximus. Pellentesque at dolor ac mi mollis molestie in facilisis nisl.\n' +
|
||||
'\n' +
|
||||
'Nam id lacus et elit sollicitudin vestibulum. Phasellus blandit laoreet odio \n' +
|
||||
'Ut tristique risus et mi tristique, in aliquam odio laoreet. Curabitur nunc felis, mollis ut laoreet quis, finibus in nibh. Proin urna risus, rhoncus at diam interdum, maximus vestibulum nulla. Maecenas ut rutrum nulla, vel finibus est. Etiam placerat mi et libero volutpat, tristique rhoncus felis volutpat. Donec quam erat, congue quis ligula eget, mollis aliquet elit. Vestibulum feugiat odio sit amet ex dignissim, sit amet vulputate lectus iaculis. Sed tempus id enim at eleifend. Nullam bibendum eleifend congue. Pellentesque varius arcu elit, at accumsan dolor ultrices vitae. Etiam condimentum lectus id dolor fringilla tempor. Aliquam nec fringilla sem. Fusce ac quam porta, molestie nunc sed, semper nisl. Curabitur luctus sem in dapibus gravida. Suspendisse scelerisque mollis rutrum. Proin lacinia dolor sit amet ornare condimentum.\n' +
|
||||
'\n' +
|
||||
'In ex neque, volutpat quis ullamcorper in, vestibulum vel ligula. Quisque lobortis eget neque quis ullamcorper. Nunc purus lorem, scelerisque in malesuada id, congue a magna. Donec rutrum maximus egestas. Nulla ornare libero quis odio ultricies iaculis. Suspendisse consectetur bibendum purus ac blandit. Donec et neque quis dolor eleifend tempus. Fusce fringilla risus id venenatis rutrum. Mauris commodo posuere ipsum, sit amet hendrerit risus lacinia quis. Aenean placerat ultricies ante id dapibus. Donec imperdiet eros quis porttitor accumsan. Vestibulum ut nulla luctus velit feugiat elementum. Nam vel pharetra nisl. Nullam risus tellus, tempor quis ipsum et, pretium rutrum ipsum.\n' +
|
||||
'\n' +
|
||||
'Fusce molestie leo at facilisis mollis. Vivamus iaculis facilisis fermentum. Vivamus blandit id nisi sit amet porta. Nunc luctus porta blandit. Sed ac consequat eros, eu fringilla lorem. In blandit pharetra sollicitudin. Vivamus placerat risus ut ex faucibus, nec vehicula sapien imperdiet. Praesent luctus, leo eget ultrices cursus, neque ante porttitor mauris, id tempus tellus urna at ex. Curabitur elementum id quam vitae condimentum. Proin sit amet magna vel metus blandit iaculis. Phasellus viverra libero in lacus gravida, id laoreet ligula dapibus. Cras commodo arcu eget mi dignissim, et lobortis elit faucibus. Suspendisse potenti. ')
|
||||
const rangeFrom = {line: 7, ch: 6}
|
||||
const rangeTo = {line: 7, ch: 6}
|
||||
|
||||
systemUnderTest.checkMultiLineRange(editor, rangeFrom, rangeTo)
|
||||
|
||||
expect(dic.check).toHaveBeenCalledTimes(1)
|
||||
expect(dic.check.mock.calls[0][0]).toEqual('molestie')
|
||||
})
|
||||
|
||||
it('should make sure that liveSpellcheck don\'t work if the spellcheck is not enabled', function () {
|
||||
const checkMultiLineRangeSpy = jest.spyOn(systemUnderTest, 'checkMultiLineRange').mockImplementation()
|
||||
const editor = jest.fn()
|
||||
editor.findMarks = jest.fn()
|
||||
|
||||
systemUnderTest.setDictionaryForTestsOnly(null)
|
||||
systemUnderTest.checkChangeRange(editor, {}, {})
|
||||
|
||||
expect(checkMultiLineRangeSpy).not.toHaveBeenCalled()
|
||||
expect(editor.findMarks).not.toHaveBeenCalled()
|
||||
|
||||
checkMultiLineRangeSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should make sure that liveSpellcheck works for a range of changes', function () {
|
||||
const editor = jest.fn()
|
||||
const marks = [{clear: jest.fn()}, {clear: jest.fn()}]
|
||||
editor.findMarks = jest.fn(() => marks)
|
||||
const checkMultiLineRangeSpy = jest.spyOn(systemUnderTest, 'checkMultiLineRange').mockImplementation()
|
||||
|
||||
const inputChangeRange = {from: {line: 0, ch: 2}, to: {line: 1, ch: 1}}
|
||||
const inputChangeRangeTo = {from: {line: 0, ch: 2}, to: {line: 1, ch: 2}}
|
||||
|
||||
systemUnderTest.setDictionaryForTestsOnly({})
|
||||
systemUnderTest.checkChangeRange(editor, inputChangeRange, inputChangeRangeTo)
|
||||
|
||||
expect(checkMultiLineRangeSpy).toHaveBeenCalledWith(editor, {line: 0, ch: 1}, {line: 1, ch: 3})
|
||||
expect(editor.findMarks).toHaveBeenCalledWith({line: 0, ch: 1}, {line: 1, ch: 3})
|
||||
expect(marks[0].clear).toHaveBeenCalled()
|
||||
expect(marks[1].clear).toHaveBeenCalled()
|
||||
checkMultiLineRangeSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should make sure that liveSpellcheck works if ranges are inverted', function () {
|
||||
const editor = jest.fn()
|
||||
const marks = [{clear: jest.fn()}, {clear: jest.fn()}]
|
||||
editor.findMarks = jest.fn(() => marks)
|
||||
const checkMultiLineRangeSpy = jest.spyOn(systemUnderTest, 'checkMultiLineRange').mockImplementation()
|
||||
|
||||
const inputChangeRange = {from: {line: 0, ch: 2}, to: {line: 1, ch: 2}}
|
||||
const inputChangeRangeTo = {from: {line: 0, ch: 2}, to: {line: 1, ch: 1}}
|
||||
|
||||
systemUnderTest.setDictionaryForTestsOnly({})
|
||||
systemUnderTest.checkChangeRange(editor, inputChangeRange, inputChangeRangeTo)
|
||||
|
||||
expect(checkMultiLineRangeSpy).toHaveBeenCalledWith(editor, {line: 0, ch: 1}, {line: 1, ch: 3})
|
||||
expect(editor.findMarks).toHaveBeenCalledWith({line: 0, ch: 1}, {line: 1, ch: 3})
|
||||
expect(marks[0].clear).toHaveBeenCalled()
|
||||
expect(marks[1].clear).toHaveBeenCalled()
|
||||
checkMultiLineRangeSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should make sure that liveSpellcheck works for a single word with change at the beginning', function () {
|
||||
const dic = jest.fn()
|
||||
dic.check = jest.fn()
|
||||
systemUnderTest.setDictionaryForTestsOnly(dic)
|
||||
document.body.createTextRange = jest.fn(() => document.createElement('textArea'))
|
||||
const editor = new CodeMirror(jest.fn())
|
||||
editor.setValue(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vehicula sem id tempor sollicitudin. Sed eu sagittis ligula. Maecenas sit amet velit enim. Etiam massa urna, elementum et sapien sit amet, vestibulum pharetra lectus. Nulla consequat malesuada nunc in aliquam. Vivamus faucibus orci et faucibus maximus. Pellentesque at dolor ac mi mollis molestie in facilisis nisl.\n' +
|
||||
'\n' +
|
||||
'Nam id lacus et elit sollicitudin vestibulum. Phasellus blandit laoreet odio \n' +
|
||||
'Ut tristique risus et mi tristique, in aliquam odio laoreet. Curabitur nunc felis, mollis ut laoreet quis, finibus in nibh. Proin urna risus, rhoncus at diam interdum, maximus vestibulum nulla. Maecenas ut rutrum nulla, vel finibus est. Etiam placerat mi et libero volutpat, tristique rhoncus felis volutpat. Donec quam erat, congue quis ligula eget, mollis aliquet elit. Vestibulum feugiat odio sit amet ex dignissim, sit amet vulputate lectus iaculis. Sed tempus id enim at eleifend. Nullam bibendum eleifend congue. Pellentesque varius arcu elit, at accumsan dolor ultrices vitae. Etiam condimentum lectus id dolor fringilla tempor. Aliquam nec fringilla sem. Fusce ac quam porta, molestie nunc sed, semper nisl. Curabitur luctus sem in dapibus gravida. Suspendisse scelerisque mollis rutrum. Proin lacinia dolor sit amet ornare condimentum.\n' +
|
||||
'\n' +
|
||||
'In ex neque, volutpat quis ullamcorper in, vestibulum vel ligula. Quisque lobortis eget neque quis ullamcorper. Nunc purus lorem, scelerisque in malesuada id, congue a magna. Donec rutrum maximus egestas. Nulla ornare libero quis odio ultricies iaculis. Suspendisse consectetur bibendum purus ac blandit. Donec et neque quis dolor eleifend tempus. Fusce fringilla risus id venenatis rutrum. Mauris commodo posuere ipsum, sit amet hendrerit risus lacinia quis. Aenean placerat ultricies ante id dapibus. Donec imperdiet eros quis porttitor accumsan. Vestibulum ut nulla luctus velit feugiat elementum. Nam vel pharetra nisl. Nullam risus tellus, tempor quis ipsum et, pretium rutrum ipsum.\n' +
|
||||
'\n' +
|
||||
'Fusce molestie leo at facilisis mollis. Vivamus iaculis facilisis fermentum. Vivamus blandit id nisi sit amet porta. Nunc luctus porta blandit. Sed ac consequat eros, eu fringilla lorem. In blandit pharetra sollicitudin. Vivamus placerat risus ut ex faucibus, nec vehicula sapien imperdiet. Praesent luctus, leo eget ultrices cursus, neque ante porttitor mauris, id tempus tellus urna at ex. Curabitur elementum id quam vitae condimentum. Proin sit amet magna vel metus blandit iaculis. Phasellus viverra libero in lacus gravida, id laoreet ligula dapibus. Cras commodo arcu eget mi dignissim, et lobortis elit faucibus. Suspendisse potenti. ')
|
||||
const rangeFrom = {from: {line: 7, ch: 6}, to: {line: 7, ch: 6}}
|
||||
const rangeTo = {from: {line: 7, ch: 6}, to: {line: 7, ch: 6}}
|
||||
|
||||
systemUnderTest.checkChangeRange(editor, rangeFrom, rangeTo)
|
||||
|
||||
expect(dic.check).toHaveBeenCalledTimes(1)
|
||||
expect(dic.check.mock.calls[0][0]).toEqual('molestie')
|
||||
})
|
||||
|
||||
it('should make sure that liveSpellcheck works for a single word with change in the middle', function () {
|
||||
const dic = jest.fn()
|
||||
dic.check = jest.fn()
|
||||
systemUnderTest.setDictionaryForTestsOnly(dic)
|
||||
document.body.createTextRange = jest.fn(() => document.createElement('textArea'))
|
||||
const editor = new CodeMirror(jest.fn())
|
||||
editor.setValue(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vehicula sem id tempor sollicitudin. Sed eu sagittis ligula. Maecenas sit amet velit enim. Etiam massa urna, elementum et sapien sit amet, vestibulum pharetra lectus. Nulla consequat malesuada nunc in aliquam. Vivamus faucibus orci et faucibus maximus. Pellentesque at dolor ac mi mollis molestie in facilisis nisl.\n' +
|
||||
'\n' +
|
||||
'Nam id lacus et elit sollicitudin vestibulum. Phasellus blandit laoreet odio \n' +
|
||||
'Ut tristique risus et mi tristique, in aliquam odio laoreet. Curabitur nunc felis, mollis ut laoreet quis, finibus in nibh. Proin urna risus, rhoncus at diam interdum, maximus vestibulum nulla. Maecenas ut rutrum nulla, vel finibus est. Etiam placerat mi et libero volutpat, tristique rhoncus felis volutpat. Donec quam erat, congue quis ligula eget, mollis aliquet elit. Vestibulum feugiat odio sit amet ex dignissim, sit amet vulputate lectus iaculis. Sed tempus id enim at eleifend. Nullam bibendum eleifend congue. Pellentesque varius arcu elit, at accumsan dolor ultrices vitae. Etiam condimentum lectus id dolor fringilla tempor. Aliquam nec fringilla sem. Fusce ac quam porta, molestie nunc sed, semper nisl. Curabitur luctus sem in dapibus gravida. Suspendisse scelerisque mollis rutrum. Proin lacinia dolor sit amet ornare condimentum.\n' +
|
||||
'\n' +
|
||||
'In ex neque, volutpat quis ullamcorper in, vestibulum vel ligula. Quisque lobortis eget neque quis ullamcorper. Nunc purus lorem, scelerisque in malesuada id, congue a magna. Donec rutrum maximus egestas. Nulla ornare libero quis odio ultricies iaculis. Suspendisse consectetur bibendum purus ac blandit. Donec et neque quis dolor eleifend tempus. Fusce fringilla risus id venenatis rutrum. Mauris commodo posuere ipsum, sit amet hendrerit risus lacinia quis. Aenean placerat ultricies ante id dapibus. Donec imperdiet eros quis porttitor accumsan. Vestibulum ut nulla luctus velit feugiat elementum. Nam vel pharetra nisl. Nullam risus tellus, tempor quis ipsum et, pretium rutrum ipsum.\n' +
|
||||
'\n' +
|
||||
'Fusce molestie leo at facilisis mollis. Vivamus iaculis facilisis fermentum. Vivamus blandit id nisi sit amet porta. Nunc luctus porta blandit. Sed ac consequat eros, eu fringilla lorem. In blandit pharetra sollicitudin. Vivamus placerat risus ut ex faucibus, nec vehicula sapien imperdiet. Praesent luctus, leo eget ultrices cursus, neque ante porttitor mauris, id tempus tellus urna at ex. Curabitur elementum id quam vitae condimentum. Proin sit amet magna vel metus blandit iaculis. Phasellus viverra libero in lacus gravida, id laoreet ligula dapibus. Cras commodo arcu eget mi dignissim, et lobortis elit faucibus. Suspendisse potenti. ')
|
||||
const rangeFrom = {from: {line: 7, ch: 9}, to: {line: 7, ch: 9}}
|
||||
const rangeTo = {from: {line: 7, ch: 9}, to: {line: 7, ch: 9}}
|
||||
|
||||
systemUnderTest.checkChangeRange(editor, rangeFrom, rangeTo)
|
||||
|
||||
expect(dic.check).toHaveBeenCalledTimes(1)
|
||||
expect(dic.check.mock.calls[0][0]).toEqual('molestie')
|
||||
})
|
||||
|
||||
it('should make sure that liveSpellcheck works for a single word with change at the end', function () {
|
||||
const dic = jest.fn()
|
||||
dic.check = jest.fn()
|
||||
systemUnderTest.setDictionaryForTestsOnly(dic)
|
||||
document.body.createTextRange = jest.fn(() => document.createElement('textArea'))
|
||||
const editor = new CodeMirror(jest.fn())
|
||||
editor.setValue(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vehicula sem id tempor sollicitudin. Sed eu sagittis ligula. Maecenas sit amet velit enim. Etiam massa urna, elementum et sapien sit amet, vestibulum pharetra lectus. Nulla consequat malesuada nunc in aliquam. Vivamus faucibus orci et faucibus maximus. Pellentesque at dolor ac mi mollis molestie in facilisis nisl.\n' +
|
||||
'\n' +
|
||||
'Nam id lacus et elit sollicitudin vestibulum. Phasellus blandit laoreet odio \n' +
|
||||
'Ut tristique risus et mi tristique, in aliquam odio laoreet. Curabitur nunc felis, mollis ut laoreet quis, finibus in nibh. Proin urna risus, rhoncus at diam interdum, maximus vestibulum nulla. Maecenas ut rutrum nulla, vel finibus est. Etiam placerat mi et libero volutpat, tristique rhoncus felis volutpat. Donec quam erat, congue quis ligula eget, mollis aliquet elit. Vestibulum feugiat odio sit amet ex dignissim, sit amet vulputate lectus iaculis. Sed tempus id enim at eleifend. Nullam bibendum eleifend congue. Pellentesque varius arcu elit, at accumsan dolor ultrices vitae. Etiam condimentum lectus id dolor fringilla tempor. Aliquam nec fringilla sem. Fusce ac quam porta, molestie nunc sed, semper nisl. Curabitur luctus sem in dapibus gravida. Suspendisse scelerisque mollis rutrum. Proin lacinia dolor sit amet ornare condimentum.\n' +
|
||||
'\n' +
|
||||
'In ex neque, volutpat quis ullamcorper in, vestibulum vel ligula. Quisque lobortis eget neque quis ullamcorper. Nunc purus lorem, scelerisque in malesuada id, congue a magna. Donec rutrum maximus egestas. Nulla ornare libero quis odio ultricies iaculis. Suspendisse consectetur bibendum purus ac blandit. Donec et neque quis dolor eleifend tempus. Fusce fringilla risus id venenatis rutrum. Mauris commodo posuere ipsum, sit amet hendrerit risus lacinia quis. Aenean placerat ultricies ante id dapibus. Donec imperdiet eros quis porttitor accumsan. Vestibulum ut nulla luctus velit feugiat elementum. Nam vel pharetra nisl. Nullam risus tellus, tempor quis ipsum et, pretium rutrum ipsum.\n' +
|
||||
'\n' +
|
||||
'Fusce molestie leo at facilisis mollis. Vivamus iaculis facilisis fermentum. Vivamus blandit id nisi sit amet porta. Nunc luctus porta blandit. Sed ac consequat eros, eu fringilla lorem. In blandit pharetra sollicitudin. Vivamus placerat risus ut ex faucibus, nec vehicula sapien imperdiet. Praesent luctus, leo eget ultrices cursus, neque ante porttitor mauris, id tempus tellus urna at ex. Curabitur elementum id quam vitae condimentum. Proin sit amet magna vel metus blandit iaculis. Phasellus viverra libero in lacus gravida, id laoreet ligula dapibus. Cras commodo arcu eget mi dignissim, et lobortis elit faucibus. Suspendisse potenti. ')
|
||||
const rangeFrom = {from: {line: 7, ch: 14}, to: {line: 7, ch: 14}}
|
||||
const rangeTo = {from: {line: 7, ch: 14}, to: {line: 7, ch: 14}}
|
||||
|
||||
systemUnderTest.checkChangeRange(editor, rangeFrom, rangeTo)
|
||||
|
||||
expect(dic.check).toHaveBeenCalledTimes(1)
|
||||
expect(dic.check.mock.calls[0][0]).toEqual('molestie')
|
||||
})
|
||||
15
tests/lib/utils.test.js
Normal file
15
tests/lib/utils.test.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { isMarkdownTitleURL } from '../../browser/lib/utils'
|
||||
|
||||
describe('isMarkdownTitleURL', () => {
|
||||
it('returns true for valid Markdown title with url', () => {
|
||||
expect(isMarkdownTitleURL('# https://validurl.com')).toBe(true)
|
||||
expect(isMarkdownTitleURL('## https://validurl.com')).toBe(true)
|
||||
expect(isMarkdownTitleURL('###### https://validurl.com')).toBe(true)
|
||||
})
|
||||
|
||||
it('returns true for invalid Markdown title with url', () => {
|
||||
expect(isMarkdownTitleURL('1 https://validurl.com')).toBe(false)
|
||||
expect(isMarkdownTitleURL('24 https://validurl.com')).toBe(false)
|
||||
expect(isMarkdownTitleURL('####### https://validurl.com')).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user