mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
Merge branch 'master' of https://github.com/BoostIO/Boostnote into paste_storage_link_should_clone_attachment
# Conflicts: # browser/components/CodeEditor.js # browser/main/lib/dataApi/attachmentManagement.js
This commit is contained in:
34
tests/dataApi/createSnippet-test.js
Normal file
34
tests/dataApi/createSnippet-test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const test = require('ava')
|
||||
const createSnippet = require('browser/main/lib/dataApi/createSnippet')
|
||||
const sander = require('sander')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
|
||||
const snippetFilePath = path.join(os.tmpdir(), 'test', 'create-snippet')
|
||||
const snippetFile = path.join(snippetFilePath, 'snippets.json')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
sander.writeFileSync(snippetFile, '[]')
|
||||
})
|
||||
|
||||
test.serial('Create a snippet', (t) => {
|
||||
return Promise.resolve()
|
||||
.then(function doTest () {
|
||||
return Promise.all([
|
||||
createSnippet(snippetFile)
|
||||
])
|
||||
})
|
||||
.then(function assert (data) {
|
||||
data = data[0]
|
||||
const snippets = JSON.parse(sander.readFileSync(snippetFile))
|
||||
const snippet = snippets.find(currentSnippet => currentSnippet.id === data.id)
|
||||
t.not(snippet, undefined)
|
||||
t.is(snippet.name, data.name)
|
||||
t.deepEqual(snippet.prefix, data.prefix)
|
||||
t.is(snippet.content, data.content)
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(() => {
|
||||
sander.rimrafSync(snippetFilePath)
|
||||
})
|
||||
37
tests/dataApi/deleteSnippet-test.js
Normal file
37
tests/dataApi/deleteSnippet-test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const test = require('ava')
|
||||
const deleteSnippet = require('browser/main/lib/dataApi/deleteSnippet')
|
||||
const sander = require('sander')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const crypto = require('crypto')
|
||||
|
||||
const snippetFilePath = path.join(os.tmpdir(), 'test', 'delete-snippet')
|
||||
const snippetFile = path.join(snippetFilePath, 'snippets.json')
|
||||
const newSnippet = {
|
||||
id: crypto.randomBytes(16).toString('hex'),
|
||||
name: 'Unnamed snippet',
|
||||
prefix: [],
|
||||
content: ''
|
||||
}
|
||||
|
||||
test.beforeEach((t) => {
|
||||
sander.writeFileSync(snippetFile, JSON.stringify([newSnippet]))
|
||||
})
|
||||
|
||||
test.serial('Delete a snippet', (t) => {
|
||||
return Promise.resolve()
|
||||
.then(function doTest () {
|
||||
return Promise.all([
|
||||
deleteSnippet(newSnippet, snippetFile)
|
||||
])
|
||||
})
|
||||
.then(function assert (data) {
|
||||
data = data[0]
|
||||
const snippets = JSON.parse(sander.readFileSync(snippetFile))
|
||||
t.is(snippets.length, 0)
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(() => {
|
||||
sander.rimrafSync(snippetFilePath)
|
||||
})
|
||||
47
tests/dataApi/updateSnippet-test.js
Normal file
47
tests/dataApi/updateSnippet-test.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const test = require('ava')
|
||||
const updateSnippet = require('browser/main/lib/dataApi/updateSnippet')
|
||||
const sander = require('sander')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const crypto = require('crypto')
|
||||
|
||||
const snippetFilePath = path.join(os.tmpdir(), 'test', 'update-snippet')
|
||||
const snippetFile = path.join(snippetFilePath, 'snippets.json')
|
||||
const oldSnippet = {
|
||||
id: crypto.randomBytes(16).toString('hex'),
|
||||
name: 'Initial snippet',
|
||||
prefix: [],
|
||||
content: ''
|
||||
}
|
||||
|
||||
const newSnippet = {
|
||||
id: oldSnippet.id,
|
||||
name: 'new name',
|
||||
prefix: ['prefix'],
|
||||
content: 'new content'
|
||||
}
|
||||
|
||||
test.beforeEach((t) => {
|
||||
sander.writeFileSync(snippetFile, JSON.stringify([oldSnippet]))
|
||||
})
|
||||
|
||||
test.serial('Update a snippet', (t) => {
|
||||
return Promise.resolve()
|
||||
.then(function doTest () {
|
||||
return Promise.all([
|
||||
updateSnippet(newSnippet, snippetFile)
|
||||
])
|
||||
})
|
||||
.then(function assert () {
|
||||
const snippets = JSON.parse(sander.readFileSync(snippetFile))
|
||||
const snippet = snippets.find(currentSnippet => currentSnippet.id === newSnippet.id)
|
||||
t.not(snippet, undefined)
|
||||
t.is(snippet.name, newSnippet.name)
|
||||
t.deepEqual(snippet.prefix, newSnippet.prefix)
|
||||
t.is(snippet.content, newSnippet.content)
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(() => {
|
||||
sander.rimrafSync(snippetFilePath)
|
||||
})
|
||||
Reference in New Issue
Block a user