1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

fixed eslint error & integrated with prettier as well as formatted the whole codebase (#3450)

This commit is contained in:
Nguyen Viet Hung
2020-02-05 13:28:27 +13:00
committed by GitHub
parent 051ce9e208
commit 592aca1539
186 changed files with 9233 additions and 5565 deletions

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const sander = require('sander')
@@ -18,24 +21,24 @@ const v1StoragePath = path.join(os.tmpdir(), 'test/addStorage-v1-storage')
// const legacyStoragePath = path.join(os.tmpdir(), 'test/addStorage-legacy-storage')
// const emptyDirPath = path.join(os.tmpdir(), 'test/addStorage-empty-storage')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.v1StorageData = TestDummy.dummyStorage(v1StoragePath)
// t.context.legacyStorageData = TestDummy.dummyLegacyStorage(legacyStoragePath)
localStorage.setItem('storages', JSON.stringify([]))
})
test.serial('Add Storage', (t) => {
test.serial('Add Storage', t => {
const input = {
type: 'FILESYSTEM',
name: 'add-storage1',
path: v1StoragePath
}
return Promise.resolve()
.then(function doTest () {
.then(function doTest() {
return addStorage(input)
})
.then(function validateResult (data) {
.then(function validateResult(data) {
const { storage, notes } = data
// Check data.storage
@@ -48,18 +51,22 @@ test.serial('Add Storage', (t) => {
// Check data.notes
t.is(notes.length, t.context.v1StorageData.notes.length)
notes.forEach(function validateNote (note) {
notes.forEach(function validateNote(note) {
t.is(note.storage, storage.key)
})
// Check localStorage
const cacheData = _.find(JSON.parse(localStorage.getItem('storages')), {key: data.storage.key})
const cacheData = _.find(JSON.parse(localStorage.getItem('storages')), {
key: data.storage.key
})
t.is(cacheData.name, input.name)
t.is(cacheData.type, input.type)
t.is(cacheData.path, input.path)
// Check boostnote.json
const jsonData = CSON.readFileSync(path.join(storage.path, 'boostnote.json'))
const jsonData = CSON.readFileSync(
path.join(storage.path, 'boostnote.json')
)
t.true(_.isArray(jsonData.folders))
t.is(jsonData.version, '1.0')
t.is(jsonData.folders.length, t.context.v1StorageData.json.folders.length)

File diff suppressed because it is too large Load Diff

View File

@@ -13,13 +13,13 @@ const srcPath = path.join(srcFolder, testFile)
const dstFolder = path.join(__dirname, '😇')
const dstPath = path.join(dstFolder, testFile)
test.before((t) => {
test.before(t => {
if (!fs.existsSync(srcFolder)) fs.mkdirSync(srcFolder)
fs.writeFileSync(srcPath, 'test')
})
test('`copyFile` should handle encoded URI on src path', (t) => {
test('`copyFile` should handle encoded URI on src path', t => {
return copyFile(encodeURI(srcPath), dstPath)
.then(() => {
t.true(true)
@@ -29,10 +29,9 @@ test('`copyFile` should handle encoded URI on src path', (t) => {
})
})
test.after((t) => {
test.after(t => {
fs.unlinkSync(srcPath)
fs.unlinkSync(dstPath)
execSync(removeDirCommand + '"' + srcFolder + '"')
execSync(removeDirCommand + '"' + dstFolder + '"')
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const _ = require('lodash')
const TestDummy = require('../fixtures/TestDummy')
@@ -16,30 +19,32 @@ const CSON = require('@rokt33r/season')
const storagePath = path.join(os.tmpdir(), 'test/create-folder')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Create a folder', (t) => {
test.serial('Create a folder', t => {
const storageKey = t.context.storage.cache.key
const input = {
name: 'created',
color: '#ff5555'
}
return Promise.resolve()
.then(function doTest () {
.then(function doTest() {
return createFolder(storageKey, input)
})
.then(function assert (data) {
.then(function assert(data) {
t.true(_.find(data.storage.folders, input) != null)
const jsonData = CSON.readFileSync(path.join(data.storage.path, 'boostnote.json'))
const jsonData = CSON.readFileSync(
path.join(data.storage.path, 'boostnote.json')
)
console.log(path.join(data.storage.path, 'boostnote.json'))
t.true(_.find(jsonData.folders, input) != null)
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const sander = require('sander')
@@ -16,26 +19,30 @@ const faker = require('faker')
const storagePath = path.join(os.tmpdir(), 'test/create-note')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Create a note', (t) => {
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 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(),
linesHighlighted: randLinesHighlightedArray
}],
snippets: [
{
name: faker.system.fileName(),
mode: 'text',
content: faker.lorem.lines(),
linesHighlighted: randLinesHighlightedArray
}
],
tags: faker.lorem.words().split(' '),
folder: folderKey
}
@@ -51,18 +58,20 @@ test.serial('Create a note', (t) => {
input2.title = input2.content.split('\n').shift()
return Promise.resolve()
.then(function doTest () {
.then(function doTest() {
return Promise.all([
createNote(storageKey, input1),
createNote(storageKey, input2)
])
})
.then(function assert (data) {
.then(function assert(data) {
const data1 = data[0]
const data2 = data[1]
t.is(storageKey, data1.storage)
const jsonData1 = CSON.readFileSync(path.join(storagePath, 'notes', data1.key + '.cson'))
const jsonData1 = CSON.readFileSync(
path.join(storagePath, 'notes', data1.key + '.cson')
)
t.is(input1.title, data1.title)
t.is(input1.title, jsonData1.title)
@@ -76,11 +85,19 @@ 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.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'))
const jsonData2 = CSON.readFileSync(
path.join(storagePath, 'notes', data2.key + '.cson')
)
t.is(input2.title, data2.title)
t.is(input2.title, jsonData2.title)
t.is(input2.content, data2.content)
@@ -92,7 +109,7 @@ test.serial('Create a note', (t) => {
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const sander = require('sander')
@@ -15,29 +18,32 @@ const CSON = require('@rokt33r/season')
const storagePath = path.join(os.tmpdir(), 'test/create-note-from-url')
test.beforeEach((t) => {
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) => {
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'))
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 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 () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -7,21 +7,21 @@ const path = require('path')
const snippetFilePath = path.join(os.tmpdir(), 'test', 'create-snippet')
const snippetFile = path.join(snippetFilePath, 'snippets.json')
test.beforeEach((t) => {
test.beforeEach(t => {
sander.writeFileSync(snippetFile, '[]')
})
test.serial('Create a snippet', (t) => {
test.serial('Create a snippet', t => {
return Promise.resolve()
.then(function doTest () {
return Promise.all([
createSnippet(snippetFile)
])
.then(function doTest() {
return Promise.all([createSnippet(snippetFile)])
})
.then(function assert (data) {
.then(function assert(data) {
data = data[0]
const snippets = JSON.parse(sander.readFileSync(snippetFile))
const snippet = snippets.find(currentSnippet => currentSnippet.id === data.id)
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)

View File

@@ -10,7 +10,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const _ = require('lodash')
const TestDummy = require('../fixtures/TestDummy')
@@ -20,12 +23,12 @@ const CSON = require('@rokt33r/season')
const storagePath = path.join(os.tmpdir(), 'test/delete-folder')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Delete a folder', (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
@@ -33,44 +36,64 @@ test.serial('Delete a folder', (t) => {
const input1 = {
type: 'SNIPPET_NOTE',
description: faker.lorem.lines(),
snippets: [{
name: faker.system.fileName(),
mode: 'text',
content: 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))
.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 () {
.then(function doTest() {
return deleteFolder(storageKey, folderKey)
})
.then(function assert (data) {
t.true(_.find(data.storage.folders, {key: folderKey}) == null)
const jsonData = CSON.readFileSync(path.join(data.storage.path, 'boostnote.json'))
.then(function assert(data) {
t.true(_.find(data.storage.folders, { key: folderKey }) == null)
const jsonData = CSON.readFileSync(
path.join(data.storage.path, 'boostnote.json')
)
t.true(_.find(jsonData.folders, {key: folderKey}) == null)
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)
t.is(
notePaths.length,
t.context.storage.notes.filter(note => note.folder !== folderKey).length
)
const attachmentFolderPath = path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, noteKey)
const attachmentFolderPath = path.join(
storagePath,
attachmentManagement.DESTINATION_FOLDER,
noteKey
)
t.false(fs.existsSync(attachmentFolderPath))
})
})
test.after.always(function after () {
test.after.always(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -7,7 +7,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const sander = require('sander')
@@ -19,56 +22,72 @@ const attachmentManagement = require('browser/main/lib/dataApi/attachmentManagem
const storagePath = path.join(os.tmpdir(), 'test/delete-note')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Delete a note', (t) => {
test.serial('Delete a note', t => {
const storageKey = t.context.storage.cache.key
const folderKey = t.context.storage.json.folders[0].key
const input1 = {
type: 'SNIPPET_NOTE',
description: faker.lorem.lines(),
snippets: [{
name: faker.system.fileName(),
mode: 'text',
content: 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 doTest () {
.then(function doTest() {
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))
.then(function createAttachmentFolder(data) {
fs.mkdirSync(
path.join(storagePath, attachmentManagement.DESTINATION_FOLDER)
)
fs.mkdirSync(
path.join(
storagePath,
attachmentManagement.DESTINATION_FOLDER,
data.key
)
)
return data
})
.then(function (data) {
.then(function(data) {
return deleteNote(storageKey, data.key)
})
})
.then(function assert (data) {
.then(function assert(data) {
try {
CSON.readFileSync(path.join(storagePath, '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, attachmentManagement.DESTINATION_FOLDER, data.noteKey)
.then(function assertAttachmentFolderDeleted(data) {
const attachmentFolderPath = path.join(
storagePath,
attachmentManagement.DESTINATION_FOLDER,
data.noteKey
)
t.is(fs.existsSync(attachmentFolderPath), false)
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -14,18 +14,16 @@ const newSnippet = {
content: ''
}
test.beforeEach((t) => {
test.beforeEach(t => {
sander.writeFileSync(snippetFile, JSON.stringify([newSnippet]))
})
test.serial('Delete a snippet', (t) => {
test.serial('Delete a snippet', t => {
return Promise.resolve()
.then(function doTest () {
return Promise.all([
deleteSnippet(newSnippet, snippetFile)
])
.then(function doTest() {
return Promise.all([deleteSnippet(newSnippet, snippetFile)])
})
.then(function assert (data) {
.then(function assert(data) {
data = data[0]
const snippets = JSON.parse(sander.readFileSync(snippetFile))
t.is(snippets.length, 0)

View File

@@ -7,7 +7,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const os = require('os')
@@ -17,12 +20,12 @@ const sander = require('sander')
const storagePath = path.join(os.tmpdir(), 'test/export-note')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Export a folder', (t) => {
test.serial('Export a folder', t => {
const storageKey = t.context.storage.cache.key
const folderKey = t.context.storage.json.folders[0].key
@@ -37,24 +40,26 @@ test.serial('Export a folder', (t) => {
const input2 = {
type: 'SNIPPET_NOTE',
description: 'Some normal text',
snippets: [{
name: faker.system.fileName(),
mode: 'text',
content: faker.lorem.lines()
}],
snippets: [
{
name: faker.system.fileName(),
mode: 'text',
content: faker.lorem.lines()
}
],
tags: faker.lorem.words().split(' '),
folder: folderKey
}
input2.title = 'input2'
return createNote(storageKey, input1)
.then(function () {
.then(function() {
return createNote(storageKey, input2)
})
.then(function () {
.then(function() {
return exportFolder(storageKey, folderKey, 'md', storagePath)
})
.then(function assert () {
.then(function assert() {
let filePath = path.join(storagePath, 'input1.md')
t.true(fs.existsSync(filePath))
filePath = path.join(storagePath, 'input2.md')
@@ -62,7 +67,7 @@ test.serial('Export a folder', (t) => {
})
})
test.after.always(function after () {
test.after.always(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const os = require('os')
@@ -17,7 +20,9 @@ test.beforeEach(t => {
t.context.storageDir = path.join(os.tmpdir(), 'test/export-storage')
t.context.storage = TestDummy.dummyStorage(t.context.storageDir)
t.context.exportDir = path.join(os.tmpdir(), 'test/export-storage-output')
try { fs.mkdirSync(t.context.exportDir) } catch (e) {}
try {
fs.mkdirSync(t.context.exportDir)
} catch (e) {}
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
@@ -26,23 +31,25 @@ test.serial('Export a storage', t => {
const folders = t.context.storage.json.folders
const notes = t.context.storage.notes
const exportDir = t.context.exportDir
const folderKeyToName = folders.reduce(
(acc, folder) => {
acc[folder.key] = folder.name
return acc
}, {})
return exportStorage(storageKey, 'md', exportDir)
.then(() => {
notes.forEach(note => {
const noteDir = path.join(exportDir, folderKeyToName[note.folder], `${note.title}.md`)
if (note.type === 'MARKDOWN_NOTE') {
t.true(fs.existsSync(noteDir))
t.is(fs.readFileSync(noteDir, 'utf8'), note.content)
} else if (note.type === 'SNIPPET_NOTE') {
t.false(fs.existsSync(noteDir))
}
})
const folderKeyToName = folders.reduce((acc, folder) => {
acc[folder.key] = folder.name
return acc
}, {})
return exportStorage(storageKey, 'md', exportDir).then(() => {
notes.forEach(note => {
const noteDir = path.join(
exportDir,
folderKeyToName[note.folder],
`${note.title}.md`
)
if (note.type === 'MARKDOWN_NOTE') {
t.true(fs.existsSync(noteDir))
t.is(fs.readFileSync(noteDir, 'utf8'), note.content)
} else if (note.type === 'SNIPPET_NOTE') {
t.false(fs.existsSync(noteDir))
}
})
})
})
test.afterEach.always(t => {

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const keygen = require('browser/lib/keygen')
@@ -18,11 +21,16 @@ const v1StoragePath = path.join(os.tmpdir(), 'test/init-v1-storage')
const legacyStoragePath = path.join(os.tmpdir(), 'test/init-legacy-storage')
const emptyDirPath = path.join(os.tmpdir(), 'test/init-empty-storage')
test.beforeEach((t) => {
test.beforeEach(t => {
localStorage.clear()
// Prepare 3 types of dir
t.context.v1StorageData = TestDummy.dummyStorage(v1StoragePath, {cache: {name: 'v1'}})
t.context.legacyStorageData = TestDummy.dummyLegacyStorage(legacyStoragePath, {cache: {name: 'legacy'}})
t.context.v1StorageData = TestDummy.dummyStorage(v1StoragePath, {
cache: { name: 'v1' }
})
t.context.legacyStorageData = TestDummy.dummyLegacyStorage(
legacyStoragePath,
{ cache: { name: 'legacy' } }
)
t.context.emptyStorageData = {
cache: {
type: 'FILESYSTEM',
@@ -32,27 +40,37 @@ test.beforeEach((t) => {
}
}
localStorage.setItem('storages', JSON.stringify([t.context.v1StorageData.cache, t.context.legacyStorageData.cache, t.context.emptyStorageData.cache]))
localStorage.setItem(
'storages',
JSON.stringify([
t.context.v1StorageData.cache,
t.context.legacyStorageData.cache,
t.context.emptyStorageData.cache
])
)
})
test.serial('Initialize All Storages', (t) => {
test.serial('Initialize All Storages', t => {
const { v1StorageData, legacyStorageData } = t.context
return Promise.resolve()
.then(function test () {
.then(function test() {
return init()
})
.then(function assert (data) {
.then(function assert(data) {
t.true(Array.isArray(data.storages))
t.is(data.notes.length, v1StorageData.notes.length + legacyStorageData.notes.length)
t.is(
data.notes.length,
v1StorageData.notes.length + legacyStorageData.notes.length
)
t.is(data.storages.length, 3)
data.storages.forEach(function assertStorage (storage) {
data.storages.forEach(function assertStorage(storage) {
t.true(_.isString(storage.key))
t.true(_.isString(storage.name))
t.true(storage.type === 'FILESYSTEM')
t.true(_.isString(storage.path))
})
})
.then(function after () {
.then(function after() {
localStorage.clear()
})
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const sander = require('sander')
@@ -16,18 +19,20 @@ const os = require('os')
const dummyStoragePath = path.join(os.tmpdir(), 'test/migrate-test-storage')
test.beforeEach((t) => {
const dummyData = t.context.dummyData = TestDummy.dummyLegacyStorage(dummyStoragePath)
test.beforeEach(t => {
const dummyData = (t.context.dummyData = TestDummy.dummyLegacyStorage(
dummyStoragePath
))
console.log('init count', dummyData.notes.length)
localStorage.setItem('storages', JSON.stringify([dummyData.cache]))
})
test.serial('Migrate legacy storage into v1 storage', (t) => {
test.serial('Migrate legacy storage into v1 storage', t => {
return Promise.resolve()
.then(function test () {
.then(function test() {
return migrateFromV6Storage(dummyStoragePath)
})
.then(function assert (data) {
.then(function assert(data) {
// Check the result. It must be true if succeed.
t.true(data)
@@ -36,29 +41,31 @@ test.serial('Migrate legacy storage into v1 storage', (t) => {
const noteDirPath = path.join(dummyStoragePath, 'notes')
const fileList = sander.readdirSync(noteDirPath)
t.is(dummyData.notes.length, fileList.length)
const noteMap = fileList
.map((filePath) => {
return CSON.readFileSync(path.join(noteDirPath, filePath))
})
dummyData.notes
.forEach(function (targetNote) {
t.true(_.find(noteMap, {title: targetNote.title, folder: targetNote.folder}) != null)
})
const noteMap = fileList.map(filePath => {
return CSON.readFileSync(path.join(noteDirPath, filePath))
})
dummyData.notes.forEach(function(targetNote) {
t.true(
_.find(noteMap, {
title: targetNote.title,
folder: targetNote.folder
}) != null
)
})
// Check legacy folder directory is removed
dummyData.json.folders
.forEach(function (folder) {
try {
sander.statSync(dummyStoragePath, folder.key)
t.fail('Folder still remains. ENOENT error must be occured.')
} catch (err) {
t.is(err.code, 'ENOENT')
}
})
dummyData.json.folders.forEach(function(folder) {
try {
sander.statSync(dummyStoragePath, folder.key)
t.fail('Folder still remains. ENOENT error must be occured.')
} catch (err) {
t.is(err.code, 'ENOENT')
}
})
})
})
test.after.always(function () {
test.after.always(function() {
localStorage.clear()
sander.rimrafSync(dummyStoragePath)
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const sander = require('sander')
@@ -16,13 +19,16 @@ const CSON = require('@rokt33r/season')
const storagePath = path.join(os.tmpdir(), 'test/move-note')
const storagePath2 = path.join(os.tmpdir(), 'test/move-note2')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage1 = TestDummy.dummyStorage(storagePath)
t.context.storage2 = TestDummy.dummyStorage(storagePath2)
localStorage.setItem('storages', JSON.stringify([t.context.storage1.cache, t.context.storage2.cache]))
localStorage.setItem(
'storages',
JSON.stringify([t.context.storage1.cache, t.context.storage2.cache])
)
})
test.serial('Move a note', (t) => {
test.serial('Move a note', t => {
const storageKey1 = t.context.storage1.cache.key
const folderKey1 = t.context.storage1.json.folders[0].key
const note1 = t.context.storage1.notes[0]
@@ -31,22 +37,26 @@ test.serial('Move a note', (t) => {
const folderKey2 = t.context.storage2.json.folders[0].key
return Promise.resolve()
.then(function doTest () {
.then(function doTest() {
return Promise.all([
moveNote(storageKey1, note1.key, storageKey1, folderKey1),
moveNote(storageKey1, note2.key, storageKey2, folderKey2)
])
})
.then(function assert (data) {
.then(function assert(data) {
const data1 = data[0]
const data2 = data[1]
const jsonData1 = CSON.readFileSync(path.join(storagePath, 'notes', data1.key + '.cson'))
const jsonData1 = CSON.readFileSync(
path.join(storagePath, 'notes', data1.key + '.cson')
)
t.is(jsonData1.folder, folderKey1)
t.is(jsonData1.title, note1.title)
const jsonData2 = CSON.readFileSync(path.join(storagePath2, 'notes', data2.key + '.cson'))
const jsonData2 = CSON.readFileSync(
path.join(storagePath2, 'notes', data2.key + '.cson')
)
t.is(jsonData2.folder, folderKey2)
t.is(jsonData2.title, note2.title)
try {
@@ -58,7 +68,7 @@ test.serial('Move a note', (t) => {
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
sander.rimrafSync(storagePath2)

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const sander = require('sander')
@@ -14,23 +17,23 @@ const os = require('os')
const storagePath = path.join(os.tmpdir(), 'test/remove-storage')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test('Remove a storage', (t) => {
test('Remove a storage', t => {
const storageKey = t.context.storage.cache.key
return Promise.resolve()
.then(function doTest () {
.then(function doTest() {
return removeStorage(storageKey)
})
.then(function assert (data) {
.then(function assert(data) {
t.is(JSON.parse(localStorage.getItem('storages')).length, 0)
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const _ = require('lodash')
const TestDummy = require('../fixtures/TestDummy')
@@ -15,24 +18,24 @@ const os = require('os')
const storagePath = path.join(os.tmpdir(), 'test/rename-storage')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Rename a storage', (t) => {
test.serial('Rename a storage', t => {
const storageKey = t.context.storage.cache.key
return Promise.resolve()
.then(function doTest () {
.then(function doTest() {
return renameStorage(storageKey, 'changed')
})
.then(function assert (data) {
.then(function assert(data) {
const cachedStorageList = JSON.parse(localStorage.getItem('storages'))
t.true(_.find(cachedStorageList, {key: storageKey}).name === 'changed')
t.true(_.find(cachedStorageList, { key: storageKey }).name === 'changed')
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const _ = require('lodash')
const TestDummy = require('../fixtures/TestDummy')
@@ -16,32 +19,34 @@ const CSON = require('@rokt33r/season')
const storagePath = path.join(os.tmpdir(), 'test/reorder-folder')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Reorder a folder', (t) => {
test.serial('Reorder a folder', t => {
const storageKey = t.context.storage.cache.key
const firstFolderKey = t.context.storage.json.folders[0].key
const secondFolderKey = t.context.storage.json.folders[1].key
return Promise.resolve()
.then(function doTest () {
.then(function doTest() {
return reorderFolder(storageKey, 0, 1)
})
.then(function assert (data) {
.then(function assert(data) {
t.true(_.nth(data.storage.folders, 0).key === secondFolderKey)
t.true(_.nth(data.storage.folders, 1).key === firstFolderKey)
const jsonData = CSON.readFileSync(path.join(data.storage.path, 'boostnote.json'))
const jsonData = CSON.readFileSync(
path.join(data.storage.path, 'boostnote.json')
)
t.true(_.nth(jsonData.folders, 0).key === secondFolderKey)
t.true(_.nth(jsonData.folders, 1).key === firstFolderKey)
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const _ = require('lodash')
const TestDummy = require('../fixtures/TestDummy')
@@ -15,24 +18,24 @@ const os = require('os')
const storagePath = path.join(os.tmpdir(), 'test/toggle-storage')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Toggle a storage location', (t) => {
test.serial('Toggle a storage location', t => {
const storageKey = t.context.storage.cache.key
return Promise.resolve()
.then(function doTest () {
.then(function doTest() {
return toggleStorage(storageKey, true)
})
.then(function assert (data) {
.then(function assert(data) {
const cachedStorageList = JSON.parse(localStorage.getItem('storages'))
t.true(_.find(cachedStorageList, {key: storageKey}).isOpen === true)
t.true(_.find(cachedStorageList, { key: storageKey }).isOpen === true)
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const _ = require('lodash')
const TestDummy = require('../fixtures/TestDummy')
@@ -16,12 +19,12 @@ const CSON = require('@rokt33r/season')
const storagePath = path.join(os.tmpdir(), 'test/update-folder')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Update a folder', (t) => {
test.serial('Update a folder', t => {
const storageKey = t.context.storage.cache.key
const folderKey = t.context.storage.json.folders[0].key
const input = {
@@ -29,18 +32,20 @@ test.serial('Update a folder', (t) => {
color: '#FF0000'
}
return Promise.resolve()
.then(function doTest () {
.then(function doTest() {
return updateFolder(storageKey, folderKey, input)
})
.then(function assert (data) {
.then(function assert(data) {
t.true(_.find(data.storage.folders, input) != null)
const jsonData = CSON.readFileSync(path.join(data.storage.path, 'boostnote.json'))
const jsonData = CSON.readFileSync(
path.join(data.storage.path, 'boostnote.json')
)
console.log(path.join(data.storage.path, 'boostnote.json'))
t.true(_.find(jsonData.folders, input) != null)
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -7,7 +7,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
null,
{ strict: true }
))
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const sander = require('sander')
@@ -17,27 +20,33 @@ const faker = require('faker')
const storagePath = path.join(os.tmpdir(), 'test/update-note')
test.beforeEach((t) => {
test.beforeEach(t => {
t.context.storage = TestDummy.dummyStorage(storagePath)
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
})
test.serial('Update a note', (t) => {
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 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(),
linesHighlighted: randLinesHighlightedArray
}],
snippets: [
{
name: faker.system.fileName(),
mode: 'text',
content: faker.lorem.lines(),
linesHighlighted: randLinesHighlightedArray
}
],
tags: faker.lorem.words().split(' '),
folder: folderKey
}
@@ -55,12 +64,14 @@ test.serial('Update a note', (t) => {
const input3 = {
type: 'SNIPPET_NOTE',
description: faker.lorem.lines(),
snippets: [{
name: faker.system.fileName(),
mode: 'text',
content: faker.lorem.lines(),
linesHighlighted: randLinesHighlightedArray2
}],
snippets: [
{
name: faker.system.fileName(),
mode: 'text',
content: faker.lorem.lines(),
linesHighlighted: randLinesHighlightedArray2
}
],
tags: faker.lorem.words().split(' ')
}
input3.title = input3.description.split('\n').shift()
@@ -74,26 +85,26 @@ test.serial('Update a note', (t) => {
input4.title = input4.content.split('\n').shift()
return Promise.resolve()
.then(function doTest () {
return Promise
.all([
createNote(storageKey, input1),
createNote(storageKey, input2)
.then(function doTest() {
return Promise.all([
createNote(storageKey, input1),
createNote(storageKey, input2)
]).then(function updateNotes(data) {
const data1 = data[0]
const data2 = data[1]
return Promise.all([
updateNote(data1.storage, data1.key, input3),
updateNote(data1.storage, data2.key, input4)
])
.then(function updateNotes (data) {
const data1 = data[0]
const data2 = data[1]
return Promise.all([
updateNote(data1.storage, data1.key, input3),
updateNote(data1.storage, data2.key, input4)
])
})
})
})
.then(function assert (data) {
.then(function assert(data) {
const data1 = data[0]
const data2 = data[1]
const jsonData1 = CSON.readFileSync(path.join(storagePath, 'notes', data1.key + '.cson'))
const jsonData1 = CSON.readFileSync(
path.join(storagePath, 'notes', data1.key + '.cson')
)
t.is(input3.title, data1.title)
t.is(input3.title, jsonData1.title)
t.is(input3.description, data1.description)
@@ -106,10 +117,18 @@ 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)
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'))
const jsonData2 = CSON.readFileSync(
path.join(storagePath, 'notes', data2.key + '.cson')
)
t.is(input4.title, data2.title)
t.is(input4.title, jsonData2.title)
t.is(input4.content, data2.content)
@@ -121,7 +140,7 @@ test.serial('Update a note', (t) => {
})
})
test.after(function after () {
test.after(function after() {
localStorage.clear()
sander.rimrafSync(storagePath)
})

View File

@@ -21,20 +21,20 @@ const newSnippet = {
content: 'new content'
}
test.beforeEach((t) => {
test.beforeEach(t => {
sander.writeFileSync(snippetFile, JSON.stringify([oldSnippet]))
})
test.serial('Update a snippet', (t) => {
test.serial('Update a snippet', t => {
return Promise.resolve()
.then(function doTest () {
return Promise.all([
updateSnippet(newSnippet, snippetFile)
])
.then(function doTest() {
return Promise.all([updateSnippet(newSnippet, snippetFile)])
})
.then(function assert () {
.then(function assert() {
const snippets = JSON.parse(sander.readFileSync(snippetFile))
const snippet = snippets.find(currentSnippet => currentSnippet.id === newSnippet.id)
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)