mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge pull request #1936 from ehhc/delete_folder
deleting a folder should also delete the attachments -> fixes #1903
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
const test = require('ava')
|
||||
const deleteFolder = require('browser/main/lib/dataApi/deleteFolder')
|
||||
const attachmentManagement = require('browser/main/lib/dataApi/attachmentManagement')
|
||||
const createNote = require('browser/main/lib/dataApi/createNote')
|
||||
const fs = require('fs')
|
||||
const faker = require('faker')
|
||||
|
||||
global.document = require('jsdom').jsdom('<body></body>')
|
||||
global.window = document.defaultView
|
||||
@@ -24,8 +28,32 @@ test.beforeEach((t) => {
|
||||
test.serial('Delete a folder', (t) => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const folderKey = t.context.storage.json.folders[0].key
|
||||
let noteKey
|
||||
|
||||
const input1 = {
|
||||
type: 'SNIPPET_NOTE',
|
||||
description: faker.lorem.lines(),
|
||||
snippets: [{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
}],
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
}
|
||||
input1.title = input1.description.split('\n').shift()
|
||||
|
||||
return Promise.resolve()
|
||||
.then(function prepare () {
|
||||
return createNote(storageKey, input1)
|
||||
.then(function createAttachmentFolder (data) {
|
||||
fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER))
|
||||
fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.key))
|
||||
noteKey = data.key
|
||||
|
||||
return data
|
||||
})
|
||||
})
|
||||
.then(function doTest () {
|
||||
return deleteFolder(storageKey, folderKey)
|
||||
})
|
||||
@@ -36,6 +64,9 @@ test.serial('Delete a folder', (t) => {
|
||||
t.true(_.find(jsonData.folders, {key: folderKey}) == null)
|
||||
const notePaths = sander.readdirSync(data.storage.path, 'notes')
|
||||
t.is(notePaths.length, t.context.storage.notes.filter((note) => note.folder !== folderKey).length)
|
||||
|
||||
const attachmentFolderPath = path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, noteKey)
|
||||
t.false(fs.existsSync(attachmentFolderPath))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ const TestDummy = require('../fixtures/TestDummy')
|
||||
const os = require('os')
|
||||
const faker = require('faker')
|
||||
const fs = require('fs')
|
||||
const sander = require('sander')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/export-note')
|
||||
|
||||
@@ -60,3 +61,8 @@ test.serial('Export a folder', (t) => {
|
||||
t.false(fs.existsSync(filePath))
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(function after () {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user