From ab038b1f311103dc1407f5b14e87e758e3cf6bc2 Mon Sep 17 00:00:00 2001
From: ozone <802146+o-3@users.noreply.github.com>
Date: Fri, 4 May 2018 00:44:22 -0400
Subject: [PATCH 1/9] Add configuration to render line breaks as
or not
---
browser/components/MarkdownEditor.js | 1 +
browser/components/MarkdownPreview.js | 12 ++++++++----
browser/components/MarkdownSplitEditor.js | 1 +
browser/lib/markdown.js | 2 +-
browser/main/lib/ConfigManager.js | 1 +
browser/main/modals/PreferencesModal/UiTab.js | 11 +++++++++++
tests/fixtures/markdowns.js | 5 ++++-
tests/lib/markdown-test.js | 9 +++++++++
tests/lib/snapshots/markdown-test.js.md | 14 ++++++++++++++
tests/lib/snapshots/markdown-test.js.snap | Bin 1665 -> 3060 bytes
10 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js
index 2c98f18e..2bd5d951 100644
--- a/browser/components/MarkdownEditor.js
+++ b/browser/components/MarkdownEditor.js
@@ -283,6 +283,7 @@ class MarkdownEditor extends React.Component {
indentSize={editorIndentSize}
scrollPastEnd={config.preview.scrollPastEnd}
smartQuotes={config.preview.smartQuotes}
+ breaks={config.preview.breaks}
sanitize={config.preview.sanitize}
ref='preview'
onContextMenu={(e) => this.handleContextMenu(e)}
diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js
index 058dce19..9d457238 100755
--- a/browser/components/MarkdownPreview.js
+++ b/browser/components/MarkdownPreview.js
@@ -145,10 +145,11 @@ export default class MarkdownPreview extends React.Component {
}
initMarkdown () {
- const { smartQuotes, sanitize } = this.props
+ const { smartQuotes, sanitize, breaks } = this.props
this.markdown = new Markdown({
typographer: smartQuotes,
- sanitize
+ sanitize,
+ breaks
})
}
@@ -340,7 +341,9 @@ export default class MarkdownPreview extends React.Component {
componentDidUpdate (prevProps) {
if (prevProps.value !== this.props.value) this.rewriteIframe()
- if (prevProps.smartQuotes !== this.props.smartQuotes || prevProps.sanitize !== this.props.sanitize) {
+ if (prevProps.smartQuotes !== this.props.smartQuotes ||
+ prevProps.sanitize !== this.props.sanitize ||
+ prevProps.breaks !== this.props.breaks) {
this.initMarkdown()
this.rewriteIframe()
}
@@ -599,5 +602,6 @@ MarkdownPreview.propTypes = {
value: PropTypes.string,
showCopyNotification: PropTypes.bool,
storagePath: PropTypes.string,
- smartQuotes: PropTypes.bool
+ smartQuotes: PropTypes.bool,
+ breaks: PropTypes.bool
}
diff --git a/browser/components/MarkdownSplitEditor.js b/browser/components/MarkdownSplitEditor.js
index 27505a5a..2bee5c24 100644
--- a/browser/components/MarkdownSplitEditor.js
+++ b/browser/components/MarkdownSplitEditor.js
@@ -131,6 +131,7 @@ class MarkdownSplitEditor extends React.Component {
lineNumber={config.preview.lineNumber}
scrollPastEnd={config.preview.scrollPastEnd}
smartQuotes={config.preview.smartQuotes}
+ breaks={config.preview.breaks}
sanitize={config.preview.sanitize}
ref='preview'
tabInde='0'
diff --git a/browser/lib/markdown.js b/browser/lib/markdown.js
index 1ef488a7..e5923790 100644
--- a/browser/lib/markdown.js
+++ b/browser/lib/markdown.js
@@ -25,7 +25,7 @@ class Markdown {
linkify: true,
html: true,
xhtmlOut: true,
- breaks: true,
+ breaks: config.preview.breaks,
highlight: function (str, lang) {
const delimiter = ':'
const langInfo = lang.split(delimiter)
diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js
index ee8a57c7..166e7181 100644
--- a/browser/main/lib/ConfigManager.js
+++ b/browser/main/lib/ConfigManager.js
@@ -55,6 +55,7 @@ export const DEFAULT_CONFIG = {
latexBlockClose: '$$',
scrollPastEnd: false,
smartQuotes: true,
+ breaks: true,
sanitize: 'STRICT' // 'STRICT', 'ALLOW_STYLES', 'NONE'
},
blog: {
diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js
index a607f548..42f1503c 100644
--- a/browser/main/modals/PreferencesModal/UiTab.js
+++ b/browser/main/modals/PreferencesModal/UiTab.js
@@ -96,6 +96,7 @@ class UiTab extends React.Component {
latexBlockClose: this.refs.previewLatexBlockClose.value,
scrollPastEnd: this.refs.previewScrollPastEnd.checked,
smartQuotes: this.refs.previewSmartQuotes.checked,
+ breaks: this.refs.previewBreaks.checked,
sanitize: this.refs.previewSanitize.value
}
}
@@ -475,6 +476,16 @@ class UiTab extends React.Component {
Enable smart quotes
+
+
+
diff --git a/tests/fixtures/markdowns.js b/tests/fixtures/markdowns.js
index 8db35485..69e335e0 100644
--- a/tests/fixtures/markdowns.js
+++ b/tests/fixtures/markdowns.js
@@ -48,10 +48,13 @@ const checkboxes = `
const smartQuotes = 'This is a "QUOTE".'
+const breaks = 'This is the first line.\nThis is the second line.'
+
export default {
basic,
codeblock,
katex,
checkboxes,
- smartQuotes
+ smartQuotes,
+ breaks
}
diff --git a/tests/lib/markdown-test.js b/tests/lib/markdown-test.js
index b2a81fdf..73b68799 100644
--- a/tests/lib/markdown-test.js
+++ b/tests/lib/markdown-test.js
@@ -34,3 +34,12 @@ test('Markdown.render() should text with quotes correctly', t => {
const renderedNonSmartQuotes = newmd.render(markdownFixtures.smartQuotes)
t.snapshot(renderedNonSmartQuotes)
})
+
+test('Markdown.render() should render line breaks correctly', t => {
+ const renderedBreaks = md.render(markdownFixtures.breaks)
+ t.snapshot(renderedBreaks)
+
+ const newmd = new Markdown({ breaks: false })
+ const renderedNonBreaks = newmd.render(markdownFixtures.breaks)
+ t.snapshot(renderedNonBreaks)
+})
diff --git a/tests/lib/snapshots/markdown-test.js.md b/tests/lib/snapshots/markdown-test.js.md
index d4f0469e..0c3e317b 100644
--- a/tests/lib/snapshots/markdown-test.js.md
+++ b/tests/lib/snapshots/markdown-test.js.md
@@ -73,4 +73,18 @@ Generated by [AVA](https://ava.li).
> Snapshot 2
`
This is a "QUOTE".
␊
+
+
+## Markdown.render() should render line breaks correctly
+
+> Snapshot 1
+
+ `
This is the first line.
␊
+ This is the second line.
␊
`
+
+> Snapshot 2
+
+ `
This is the first line.␊
+ This is the second line.
␊
+ `
\ No newline at end of file
diff --git a/tests/lib/snapshots/markdown-test.js.snap b/tests/lib/snapshots/markdown-test.js.snap
index 71ff221d9f61036d05dda745e42bdb820e08eda5..1dc64bba756effea535593a01693be463c95a26a 100644
GIT binary patch
literal 3060
zcmZ8jTT@e46b^z71V%0aBm@YAt0=c{Q6LCGAPE;y10<1)2DwC#Yc7ZoV@KPW&gesZ
zw6=CSbz0kL`_N7woN;{6b{u@rGVM&A4&y^RZJ*k|(C=fNo~X{Z*80}o=bY@l*0(p>
zMr?(yMc;D3zZ5JC*XiOk=Dgu$`>-i>@!y9JW?+Y!D$-4eiJIMidQf*CTwZq${P^Q*
z6@F%`2S-P2Aa9_oUIw1rdVB-y&-ZRRLW3Y-Sa1z)WEgG=HVI2lFvY$Rzf^DxW928|
z1h$k!v$^y5C1ftE4DoHCl|K{VLdvx=0w3Ls(P{(uikgEgND_Ny`!2UB*g!~utw-T}
z3FSvyHeS91S~JEOAQ0f<^CW?9GQ#cLf#VxzV1oTMDh1&~z`pZvscX5C!Sfw6?6Nun
zaul`-t7(O6fT`d<&hdF*0yZZUev!`tk8Z(5g!7|57{8?=nN5iB8^JlQW;*I|b<1pq
z1o$$QRe_C5c348j+*x(D2aIy*?=prEjwD&LGx{v^pmjyX%15S#N(@`~Fa%t9Eg<2`
ztGfF96Np?5FkiC$F@mmcsmXH?q=#B8ruudrqQLJ&EXk6jE1wylU4qk%z$vQ?r0hfD
zr=UWC3$q9b`EbC~``!b>9LtDY$|)G-NQs<=b;3$5E6zAX!1?#hciY@!l;QK+9)4Hb
zFEe8ZN{
)(8(7jK5`pEhO7@$%=RfxipWV6rSY=sI?d0^*gxw
zyg985vIYQ4s%tc|jsn(qzfirKn-b(B1U7ien_z8B0bl;2y#O&=QdgRvV#|%!PUi*N
zSxBG)W)#Zx7D=>tf(A%G3pzT$z`_*yo+eG7GQy7QAm!|50~%?|-iMH1Wh
zeKK$ep%+%qeVX~Qz&cw5k_7Y0KyYde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shot
---
tests/lib/snapshots/markdown-test.js.md | 28 +++++++++++-----------
tests/lib/snapshots/markdown-test.js.snap | Bin 3060 -> 1724 bytes
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/tests/lib/snapshots/markdown-test.js.md b/tests/lib/snapshots/markdown-test.js.md
index 0c3e317b..ffc3d699 100644
--- a/tests/lib/snapshots/markdown-test.js.md
+++ b/tests/lib/snapshots/markdown-test.js.md
@@ -4,6 +4,20 @@ The actual snapshot is saved in `markdown-test.js.snap`.
Generated by [AVA](https://ava.li).
+## Markdown.render() should render line breaks correctly
+
+> Snapshot 1
+
+ `This is the first line.
␊
+ This is the second line.
␊
+ `
+
+> Snapshot 2
+
+ `This is the first line.␊
+ This is the second line.
␊
+ `
+
## Markdown.render() should renders KaTeX correctly
> Snapshot 1
@@ -73,18 +87,4 @@ Generated by [AVA](https://ava.li).
> Snapshot 2
`This is a "QUOTE".
␊
-
-
-## Markdown.render() should render line breaks correctly
-
-> Snapshot 1
-
- `This is the first line.
␊
- This is the second line.
␊
`
-
-> Snapshot 2
-
- `This is the first line.␊
- This is the second line.
␊
- `
\ No newline at end of file
diff --git a/tests/lib/snapshots/markdown-test.js.snap b/tests/lib/snapshots/markdown-test.js.snap
index 1dc64bba756effea535593a01693be463c95a26a..fc310cfd28f22b2e7d20fa14c94bd5f9b806b0fd 100644
GIT binary patch
delta 1717
zcmV;m21@z#7rYIS8-LzrqAWHj5g&^P00000000y1S4)T-MHuc~#Dpkl)EsgvTUJ5S
z)AQKP&L%UB`^cKajfv)ol1Oz=?RM>SclB0P?_{E4@DT(bL4<(f18*Kff+tbDh~PmC
z2qGdvPI}T)Jc<5Q-P1cWnSE%YCkLjx=6`(utLm?RE*XY#tAFv$=53d+eEZD#(xo5m
z7`Ezr3oE*~B*ESo*-JjKeu3x$E+!rssy#3l6
zv-b{Z>JN7s#^Udrf88Rle){3p$3EY3`!73&H1&h6hH>hRVpSjPrZF2xO8f1+hu=PQ$_au628O6ChgtOEyi8L=Q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k$iClCQtSOge6Yw&m;FbqV*%8WwR}c>+@axyy
zB*0gP6fw8+?FHqclIf?PPWjsV!B4yw>h>DYQH&~ol(9Oev?v1ovsHz_dWZZxg#8I`2Qh`6s}!fhUNPb!`D$kZgy)Tu)3@%Yo%QL&P?#%K7&hf!wEX(qOD**-zdSj|z(*^r(YELW%;Au~9X#
z6dCU^9to}}#D?wO))W{}k_2bZgfHree+1ehJBwkKkrsUX^jKab`VMy^ON8c?<=c
sJEDuj5iorNuXDfw(>2DrGG?=~fq)AZdh)HYd%_4tl>>WV>w1mmKX*}
Date: Thu, 10 May 2018 21:36:58 +0200
Subject: [PATCH 3/9] Deleting a note should also delete the attachments ->
fixes #1900
---
browser/main/lib/dataApi/attachmentManagement.js | 13 +++++++++++++
browser/main/lib/dataApi/deleteNote.js | 5 +++++
tests/dataApi/attachmentManagement.test.js | 14 ++++++++++++++
tests/dataApi/deleteNote-test.js | 10 ++++++++++
4 files changed, 42 insertions(+)
diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js
index c2e7f6d6..ace33464 100644
--- a/browser/main/lib/dataApi/attachmentManagement.js
+++ b/browser/main/lib/dataApi/attachmentManagement.js
@@ -4,6 +4,7 @@ const path = require('path')
const findStorage = require('browser/lib/findStorage')
const mdurl = require('mdurl')
const escapeStringRegexp = require('escape-string-regexp')
+const sander = require('sander')
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
const DESTINATION_FOLDER = 'attachments'
@@ -190,6 +191,17 @@ function removeStorageAndNoteReferences (input, noteKey) {
return input.replace(new RegExp(mdurl.encode(path.sep), 'g'), path.sep).replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey, 'g'), DESTINATION_FOLDER)
}
+/**
+ * @description Deletes the attachment folder specified by the given storageKey and noteKey
+ * @param storageKey Key of the storage of the note to be deleted
+ * @param noteKey Key of the note to be deleted
+ */
+function deleteAttachmentFolder (storageKey, noteKey) {
+ const storagePath = findStorage.findStorage(storageKey)
+ const noteAttachmentPath = path.join(storagePath.path, DESTINATION_FOLDER, noteKey)
+ sander.rimraf(noteAttachmentPath)
+}
+
module.exports = {
copyAttachment,
fixLocalURLS,
@@ -199,6 +211,7 @@ module.exports = {
getAttachmentsInContent,
getAbsolutePathsOfAttachmentsInContent,
removeStorageAndNoteReferences,
+ deleteAttachmentFolder,
STORAGE_FOLDER_PLACEHOLDER,
DESTINATION_FOLDER
}
diff --git a/browser/main/lib/dataApi/deleteNote.js b/browser/main/lib/dataApi/deleteNote.js
index 49498a30..46ec2b55 100644
--- a/browser/main/lib/dataApi/deleteNote.js
+++ b/browser/main/lib/dataApi/deleteNote.js
@@ -1,6 +1,7 @@
const resolveStorageData = require('./resolveStorageData')
const path = require('path')
const sander = require('sander')
+const attachmentManagement = require('./attachmentManagement')
const { findStorage } = require('browser/lib/findStorage')
function deleteNote (storageKey, noteKey) {
@@ -25,6 +26,10 @@ function deleteNote (storageKey, noteKey) {
storageKey
}
})
+ .then(function deleteAttachments (storageInfo) {
+ attachmentManagement.deleteAttachmentFolder(storageInfo.storageKey, storageInfo.noteKey)
+ return storageInfo
+ })
}
module.exports = deleteNote
diff --git a/tests/dataApi/attachmentManagement.test.js b/tests/dataApi/attachmentManagement.test.js
index d58a8eb8..148f6958 100644
--- a/tests/dataApi/attachmentManagement.test.js
+++ b/tests/dataApi/attachmentManagement.test.js
@@ -7,6 +7,7 @@ const findStorage = require('browser/lib/findStorage')
jest.mock('unique-slug')
const uniqueSlug = require('unique-slug')
const mdurl = require('mdurl')
+const sander = require('sander')
const systemUnderTest = require('browser/main/lib/dataApi/attachmentManagement')
@@ -260,3 +261,16 @@ it('should remove the all ":storage" and noteKey references', function () {
const actual = systemUnderTest.removeStorageAndNoteReferences(testInput, noteKey)
expect(actual).toEqual(expectedOutput)
})
+
+it('should delete the correct attachment folder if a note is deleted', function () {
+ const dummyStorage = {path: 'dummyStoragePath'}
+ const storageKey = 'storageKey'
+ const noteKey = 'noteKey'
+ findStorage.findStorage = jest.fn(() => dummyStorage)
+ sander.rimraf = jest.fn()
+
+ const expectedPathToBeDeleted = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, noteKey)
+ systemUnderTest.deleteAttachmentFolder(storageKey, noteKey)
+ expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
+ expect(sander.rimraf).toHaveBeenCalledWith(expectedPathToBeDeleted)
+})
diff --git a/tests/dataApi/deleteNote-test.js b/tests/dataApi/deleteNote-test.js
index 611022de..ed37854d 100644
--- a/tests/dataApi/deleteNote-test.js
+++ b/tests/dataApi/deleteNote-test.js
@@ -14,6 +14,8 @@ const sander = require('sander')
const os = require('os')
const CSON = require('@rokt33r/season')
const faker = require('faker')
+const fs = require('fs')
+const attachmentManagement = require('browser/main/lib/dataApi/attachmentManagement')
const storagePath = path.join(os.tmpdir(), 'test/delete-note')
@@ -42,6 +44,10 @@ test.serial('Delete a note', (t) => {
return Promise.resolve()
.then(function doTest () {
return createNote(storageKey, input1)
+ .then(function createAttachmentFolder (data) {
+ fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.noteKey))
+ return data
+ })
.then(function (data) {
return deleteNote(storageKey, data.key)
})
@@ -54,6 +60,10 @@ test.serial('Delete a note', (t) => {
t.is(err.code, 'ENOENT')
}
})
+ .then(function assertAttachmentFolderDeleted (data) {
+ const attachmentFolderPath = path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.noteKey)
+ t.assert(fs.existsSync(attachmentFolderPath) === false, 'Attachment folder was not deleted')
+ })
})
test.after(function after () {
From ff59af6b51e6f79d885d1392b8cfead4fedc48a5 Mon Sep 17 00:00:00 2001
From: ehhc
Date: Thu, 10 May 2018 21:42:23 +0200
Subject: [PATCH 4/9] Fix for the broken test
---
tests/dataApi/deleteNote-test.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/dataApi/deleteNote-test.js b/tests/dataApi/deleteNote-test.js
index ed37854d..c9a33145 100644
--- a/tests/dataApi/deleteNote-test.js
+++ b/tests/dataApi/deleteNote-test.js
@@ -45,7 +45,7 @@ test.serial('Delete a note', (t) => {
.then(function doTest () {
return createNote(storageKey, input1)
.then(function createAttachmentFolder (data) {
- fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.noteKey))
+ fs.mkdirSync(path.join(storagePath.path, attachmentManagement.DESTINATION_FOLDER, data.noteKey))
return data
})
.then(function (data) {
@@ -54,14 +54,14 @@ test.serial('Delete a note', (t) => {
})
.then(function assert (data) {
try {
- CSON.readFileSync(path.join(storagePath, 'notes', data.noteKey + '.cson'))
+ CSON.readFileSync(path.join(storagePath.path, 'notes', data.noteKey + '.cson'))
t.fail('note cson must be deleted.')
} catch (err) {
t.is(err.code, 'ENOENT')
}
})
.then(function assertAttachmentFolderDeleted (data) {
- const attachmentFolderPath = path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.noteKey)
+ const attachmentFolderPath = path.join(storagePath.path, attachmentManagement.DESTINATION_FOLDER, data.noteKey)
t.assert(fs.existsSync(attachmentFolderPath) === false, 'Attachment folder was not deleted')
})
})
From 03fd1e29e37a84dacaea3bce8cdad7cda55599a4 Mon Sep 17 00:00:00 2001
From: ehhc
Date: Thu, 10 May 2018 22:30:13 +0200
Subject: [PATCH 5/9] Fix for the broken test
---
browser/main/lib/dataApi/attachmentManagement.js | 2 +-
tests/dataApi/deleteNote-test.js | 10 ++++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js
index ace33464..a1030aee 100644
--- a/browser/main/lib/dataApi/attachmentManagement.js
+++ b/browser/main/lib/dataApi/attachmentManagement.js
@@ -199,7 +199,7 @@ function removeStorageAndNoteReferences (input, noteKey) {
function deleteAttachmentFolder (storageKey, noteKey) {
const storagePath = findStorage.findStorage(storageKey)
const noteAttachmentPath = path.join(storagePath.path, DESTINATION_FOLDER, noteKey)
- sander.rimraf(noteAttachmentPath)
+ sander.rimrafSync(noteAttachmentPath)
}
module.exports = {
diff --git a/tests/dataApi/deleteNote-test.js b/tests/dataApi/deleteNote-test.js
index c9a33145..9c809dcf 100644
--- a/tests/dataApi/deleteNote-test.js
+++ b/tests/dataApi/deleteNote-test.js
@@ -45,7 +45,8 @@ test.serial('Delete a note', (t) => {
.then(function doTest () {
return createNote(storageKey, input1)
.then(function createAttachmentFolder (data) {
- fs.mkdirSync(path.join(storagePath.path, attachmentManagement.DESTINATION_FOLDER, data.noteKey))
+ fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER))
+ fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.key))
return data
})
.then(function (data) {
@@ -54,15 +55,16 @@ test.serial('Delete a note', (t) => {
})
.then(function assert (data) {
try {
- CSON.readFileSync(path.join(storagePath.path, 'notes', data.noteKey + '.cson'))
+ CSON.readFileSync(path.join(storagePath, 'notes', data.noteKey + '.cson'))
t.fail('note cson must be deleted.')
} catch (err) {
t.is(err.code, 'ENOENT')
+ return data
}
})
.then(function assertAttachmentFolderDeleted (data) {
- const attachmentFolderPath = path.join(storagePath.path, attachmentManagement.DESTINATION_FOLDER, data.noteKey)
- t.assert(fs.existsSync(attachmentFolderPath) === false, 'Attachment folder was not deleted')
+ const attachmentFolderPath = path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.noteKey)
+ t.is(fs.existsSync(attachmentFolderPath), false)
})
})
From e9218d10889cd89b4dc13a7ea772d84a032d1bef Mon Sep 17 00:00:00 2001
From: ehhc
Date: Thu, 10 May 2018 22:39:00 +0200
Subject: [PATCH 6/9] Fix for the broken test
---
tests/dataApi/attachmentManagement.test.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/dataApi/attachmentManagement.test.js b/tests/dataApi/attachmentManagement.test.js
index 148f6958..734aa3b9 100644
--- a/tests/dataApi/attachmentManagement.test.js
+++ b/tests/dataApi/attachmentManagement.test.js
@@ -267,10 +267,10 @@ it('should delete the correct attachment folder if a note is deleted', function
const storageKey = 'storageKey'
const noteKey = 'noteKey'
findStorage.findStorage = jest.fn(() => dummyStorage)
- sander.rimraf = jest.fn()
+ sander.rimrafSync = jest.fn()
const expectedPathToBeDeleted = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, noteKey)
systemUnderTest.deleteAttachmentFolder(storageKey, noteKey)
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
- expect(sander.rimraf).toHaveBeenCalledWith(expectedPathToBeDeleted)
+ expect(sander.rimrafSync).toHaveBeenCalledWith(expectedPathToBeDeleted)
})
From 6f52744b0fba0b4fb2af1618fe6fbea2e4c57d91 Mon Sep 17 00:00:00 2001
From: ehhc
Date: Tue, 15 May 2018 20:32:35 +0200
Subject: [PATCH 7/9] Fix eslinter issue
From 905d6860fca8d4724b63c81aed9ce863e5da2ea2 Mon Sep 17 00:00:00 2001
From: ehhc
Date: Tue, 15 May 2018 20:39:16 +0200
Subject: [PATCH 8/9] really fix the eslinter issue... -.-
---
tests/dataApi/attachmentManagement.test.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/dataApi/attachmentManagement.test.js b/tests/dataApi/attachmentManagement.test.js
index e625005f..91cac64b 100644
--- a/tests/dataApi/attachmentManagement.test.js
+++ b/tests/dataApi/attachmentManagement.test.js
@@ -274,7 +274,7 @@ it('should delete the correct attachment folder if a note is deleted', function
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
expect(sander.rimrafSync).toHaveBeenCalledWith(expectedPathToBeDeleted)
})
-
+
it('should test that deleteAttachmentsNotPresentInNote deletes all unreferenced attachments ', function () {
const dummyStorage = {path: 'dummyStoragePath'}
const noteKey = 'noteKey'
From c9cb31bd02e27ded80f2061f1ce6306ba2534694 Mon Sep 17 00:00:00 2001
From: hidaiy
Date: Wed, 16 May 2018 17:41:20 +0900
Subject: [PATCH 9/9] Update CodeMirror version (#1925)
to fix issue#1003
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 82c90896..faf99bba 100644
--- a/package.json
+++ b/package.json
@@ -53,7 +53,7 @@
"@rokt33r/season": "^5.3.0",
"aws-sdk": "^2.48.0",
"aws-sdk-mobile-analytics": "^0.9.2",
- "codemirror": "^5.19.0",
+ "codemirror": "^5.37.0",
"codemirror-mode-elixir": "^1.1.1",
"electron-config": "^0.2.1",
"electron-gh-releases": "^2.0.2",