mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge branch 'master' into export-yfm
This commit is contained in:
@@ -3,7 +3,9 @@ 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"
|
||||
>
|
||||
|
||||
@@ -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
@@ -1,8 +1,10 @@
|
||||
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, '🤔')
|
||||
@@ -10,26 +12,27 @@ const srcPath = path.join(srcFolder, testFile)
|
||||
const dstFolder = path.join(__dirname, '😇')
|
||||
const dstPath = path.join(dstFolder, testFile)
|
||||
|
||||
test.before((t) => {
|
||||
beforeAll(() => {
|
||||
if (!fs.existsSync(srcFolder)) fs.mkdirSync(srcFolder)
|
||||
|
||||
fs.writeFileSync(srcPath, 'test')
|
||||
})
|
||||
|
||||
test('`copyFile` should handle encoded URI on src path', (t) => {
|
||||
it('`copyFile` should handle encoded URI on src path', done => {
|
||||
return copyFile(encodeURI(srcPath), dstPath)
|
||||
.then(() => {
|
||||
t.true(true)
|
||||
expect(true).toBe(true)
|
||||
done()
|
||||
})
|
||||
.catch(() => {
|
||||
t.true(false)
|
||||
expect(false).toBe(true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
test.after((t) => {
|
||||
afterAll(() => {
|
||||
fs.unlinkSync(srcPath)
|
||||
fs.unlinkSync(dstPath)
|
||||
fs.rmdirSync(srcFolder)
|
||||
fs.rmdirSync(dstFolder)
|
||||
execSync(removeDirCommand + '"' + srcFolder + '"')
|
||||
execSync(removeDirCommand + '"' + dstFolder + '"')
|
||||
})
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
const test = require('ava')
|
||||
const createFolder = require('browser/main/lib/dataApi/createFolder')
|
||||
|
||||
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 _ = require('lodash')
|
||||
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-folder')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
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 () {
|
||||
return createFolder(storageKey, input)
|
||||
})
|
||||
.then(function assert (data) {
|
||||
t.true(_.find(data.storage.folders, input) != null)
|
||||
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 () {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
51
tests/dataApi/createFolder.test.js
Normal file
51
tests/dataApi/createFolder.test.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const createFolder = require('browser/main/lib/dataApi/createFolder')
|
||||
|
||||
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 _ = require('lodash')
|
||||
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-folder')
|
||||
|
||||
let storageContext
|
||||
|
||||
beforeAll(() => {
|
||||
storageContext = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([storageContext.cache]))
|
||||
})
|
||||
|
||||
it('Create a folder', done => {
|
||||
const storageKey = storageContext.cache.key
|
||||
const input = {
|
||||
name: 'created',
|
||||
color: '#ff5555'
|
||||
}
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
return createFolder(storageKey, input)
|
||||
})
|
||||
.then(data => {
|
||||
expect(_.find(data.storage.folders, input)).not.toBeNull()
|
||||
const jsonData = CSON.readFileSync(
|
||||
path.join(data.storage.path, 'boostnote.json')
|
||||
)
|
||||
expect(_.find(jsonData.folders, input)).not.toBeNull()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
@@ -1,98 +0,0 @@
|
||||
const test = require('ava')
|
||||
const createNote = require('browser/main/lib/dataApi/createNote')
|
||||
|
||||
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 faker = require('faker')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/create-note')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
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(),
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}],
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
}
|
||||
input1.title = input1.description.split('\n').shift()
|
||||
|
||||
const input2 = {
|
||||
type: 'MARKDOWN_NOTE',
|
||||
content: faker.lorem.lines(),
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey,
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}
|
||||
input2.title = input2.content.split('\n').shift()
|
||||
|
||||
return Promise.resolve()
|
||||
.then(function doTest () {
|
||||
return Promise.all([
|
||||
createNote(storageKey, input1),
|
||||
createNote(storageKey, input2)
|
||||
])
|
||||
})
|
||||
.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'))
|
||||
|
||||
t.is(input1.title, data1.title)
|
||||
t.is(input1.title, jsonData1.title)
|
||||
t.is(input1.description, data1.description)
|
||||
t.is(input1.description, jsonData1.description)
|
||||
t.is(input1.tags.length, data1.tags.length)
|
||||
t.is(input1.tags.length, jsonData1.tags.length)
|
||||
t.is(input1.snippets.length, data1.snippets.length)
|
||||
t.is(input1.snippets.length, jsonData1.snippets.length)
|
||||
t.is(input1.snippets[0].content, data1.snippets[0].content)
|
||||
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'))
|
||||
t.is(input2.title, data2.title)
|
||||
t.is(input2.title, jsonData2.title)
|
||||
t.is(input2.content, data2.content)
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
||||
test.after(function after () {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
116
tests/dataApi/createNote.test.js
Normal file
116
tests/dataApi/createNote.test.js
Normal file
@@ -0,0 +1,116 @@
|
||||
const createNote = require('browser/main/lib/dataApi/createNote')
|
||||
|
||||
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 faker = require('faker')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/create-note')
|
||||
|
||||
let storageContext
|
||||
|
||||
beforeEach(() => {
|
||||
storageContext = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([storageContext.cache]))
|
||||
})
|
||||
|
||||
it('Create a note', done => {
|
||||
const storageKey = storageContext.cache.key
|
||||
const folderKey = storageContext.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(),
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}
|
||||
],
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
}
|
||||
input1.title = input1.description.split('\n').shift()
|
||||
|
||||
const input2 = {
|
||||
type: 'MARKDOWN_NOTE',
|
||||
content: faker.lorem.lines(),
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey,
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}
|
||||
input2.title = input2.content.split('\n').shift()
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
return Promise.all([
|
||||
createNote(storageKey, input1),
|
||||
createNote(storageKey, input2)
|
||||
])
|
||||
})
|
||||
.then(data => {
|
||||
const data1 = data[0]
|
||||
const data2 = data[1]
|
||||
|
||||
expect(storageKey).toEqual(data1.storage)
|
||||
const jsonData1 = CSON.readFileSync(
|
||||
path.join(storagePath, 'notes', data1.key + '.cson')
|
||||
)
|
||||
|
||||
expect(input1.title).toEqual(data1.title)
|
||||
expect(input1.title).toEqual(jsonData1.title)
|
||||
expect(input1.description).toEqual(data1.description)
|
||||
expect(input1.description).toEqual(jsonData1.description)
|
||||
expect(input1.tags.length).toEqual(data1.tags.length)
|
||||
expect(input1.tags.length).toEqual(jsonData1.tags.length)
|
||||
expect(input1.snippets.length).toEqual(data1.snippets.length)
|
||||
expect(input1.snippets.length).toEqual(jsonData1.snippets.length)
|
||||
expect(input1.snippets[0].content).toEqual(data1.snippets[0].content)
|
||||
expect(input1.snippets[0].content).toEqual(jsonData1.snippets[0].content)
|
||||
expect(input1.snippets[0].name).toEqual(data1.snippets[0].name)
|
||||
expect(input1.snippets[0].name).toEqual(jsonData1.snippets[0].name)
|
||||
expect(input1.snippets[0].linesHighlighted).toEqual(
|
||||
data1.snippets[0].linesHighlighted
|
||||
)
|
||||
expect(input1.snippets[0].linesHighlighted).toEqual(
|
||||
jsonData1.snippets[0].linesHighlighted
|
||||
)
|
||||
|
||||
expect(storageKey).toEqual(data2.storage)
|
||||
const jsonData2 = CSON.readFileSync(
|
||||
path.join(storagePath, 'notes', data2.key + '.cson')
|
||||
)
|
||||
expect(input2.title).toEqual(data2.title)
|
||||
expect(input2.title).toEqual(jsonData2.title)
|
||||
expect(input2.content).toEqual(data2.content)
|
||||
expect(input2.content).toEqual(jsonData2.content)
|
||||
expect(input2.tags.length).toEqual(data2.tags.length)
|
||||
expect(input2.tags.length).toEqual(jsonData2.tags.length)
|
||||
expect(input2.linesHighlighted).toEqual(data2.linesHighlighted)
|
||||
expect(input2.linesHighlighted).toEqual(jsonData2.linesHighlighted)
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
50
tests/dataApi/createNoteFromUrl.test.js
Normal file
50
tests/dataApi/createNoteFromUrl.test.js
Normal file
@@ -0,0 +1,50 @@
|
||||
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')
|
||||
|
||||
let storageContext
|
||||
|
||||
beforeEach(() => {
|
||||
storageContext = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([storageContext.cache]))
|
||||
})
|
||||
|
||||
it('Create a note from URL', () => {
|
||||
const storageKey = storageContext.cache.key
|
||||
const folderKey = storageContext.json.folders[0].key
|
||||
|
||||
const url = 'https://shapeshed.com/writing-cross-platform-node/'
|
||||
|
||||
return createNoteFromUrl(url, storageKey, folderKey).then(function assert({
|
||||
note
|
||||
}) {
|
||||
expect(storageKey).toEqual(note.storage)
|
||||
const jsonData = CSON.readFileSync(
|
||||
path.join(storagePath, 'notes', note.key + '.cson')
|
||||
)
|
||||
|
||||
// Test if saved content is matching the created in memory note
|
||||
expect(note.content).toEqual(jsonData.content)
|
||||
expect(note.tags.length).toEqual(jsonData.tags.length)
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
t.deepEqual(snippet.linesHighlighted, data.linesHighlighted)
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(() => {
|
||||
sander.rimrafSync(snippetFilePath)
|
||||
})
|
||||
32
tests/dataApi/createSnippet.test.js
Normal file
32
tests/dataApi/createSnippet.test.js
Normal file
@@ -0,0 +1,32 @@
|
||||
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')
|
||||
|
||||
beforeEach(() => {
|
||||
sander.writeFileSync(snippetFile, '[]')
|
||||
})
|
||||
|
||||
it('Create a snippet', () => {
|
||||
return Promise.resolve()
|
||||
.then(() => 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
|
||||
)
|
||||
expect(snippet).not.toBeUndefined()
|
||||
expect(snippet.name).toEqual(data.name)
|
||||
expect(snippet.prefix).toEqual(data.prefix)
|
||||
expect(snippet.content).toEqual(data.content)
|
||||
expect(snippet.linesHighlighted).toEqual(data.linesHighlighted)
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
sander.rimrafSync(snippetFilePath)
|
||||
})
|
||||
@@ -1,76 +0,0 @@
|
||||
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
|
||||
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 _ = require('lodash')
|
||||
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/delete-folder')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
.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)
|
||||
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))
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(function after () {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
99
tests/dataApi/deleteFolder.test.js
Normal file
99
tests/dataApi/deleteFolder.test.js
Normal file
@@ -0,0 +1,99 @@
|
||||
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
|
||||
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 _ = require('lodash')
|
||||
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/delete-folder')
|
||||
|
||||
let storageContext
|
||||
|
||||
beforeEach(() => {
|
||||
storageContext = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([storageContext.cache]))
|
||||
})
|
||||
|
||||
it('Delete a folder', () => {
|
||||
const storageKey = storageContext.cache.key
|
||||
const folderKey = storageContext.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)
|
||||
})
|
||||
.then(function assert(data) {
|
||||
expect(_.find(data.storage.folders, { key: folderKey })).toBeUndefined()
|
||||
const jsonData = CSON.readFileSync(
|
||||
path.join(data.storage.path, 'boostnote.json')
|
||||
)
|
||||
|
||||
expect(_.find(jsonData.folders, { key: folderKey })).toBeUndefined()
|
||||
const notePaths = sander.readdirSync(data.storage.path, 'notes')
|
||||
expect(notePaths.length).toBe(
|
||||
storageContext.notes.filter(note => note.folder !== folderKey).length
|
||||
)
|
||||
|
||||
const attachmentFolderPath = path.join(
|
||||
storagePath,
|
||||
attachmentManagement.DESTINATION_FOLDER,
|
||||
noteKey
|
||||
)
|
||||
expect(fs.existsSync(attachmentFolderPath)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,11 +40,13 @@ 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
|
||||
}
|
||||
@@ -56,13 +61,13 @@ test.serial('Export a folder', (t) => {
|
||||
}
|
||||
|
||||
return createNote(storageKey, input1)
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
return createNote(storageKey, input2)
|
||||
})
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
return exportFolder(storageKey, folderKey, 'md', storagePath, config)
|
||||
})
|
||||
.then(function assert () {
|
||||
.then(function assert() {
|
||||
let filePath = path.join(storagePath, 'input1.md')
|
||||
t.true(fs.existsSync(filePath))
|
||||
filePath = path.join(storagePath, 'input2.md')
|
||||
@@ -70,7 +75,7 @@ test.serial('Export a folder', (t) => {
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(function after () {
|
||||
test.after.always(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
|
||||
@@ -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,11 +31,10 @@ 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
|
||||
}, {})
|
||||
const folderKeyToName = folders.reduce((acc, folder) => {
|
||||
acc[folder.key] = folder.name
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
const config = {
|
||||
export: {
|
||||
@@ -40,18 +44,21 @@ test.serial('Export a storage', t => {
|
||||
}
|
||||
}
|
||||
|
||||
return exportStorage(storageKey, 'md', exportDir, config)
|
||||
.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))
|
||||
}
|
||||
})
|
||||
return exportStorage(storageKey, 'md', exportDir, config).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 => {
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -5,8 +5,5 @@ const test = require('ava')
|
||||
const { formatDate } = require('browser/lib/date-formatter')
|
||||
|
||||
test(t => {
|
||||
t.throws(
|
||||
() => formatDate('invalid argument'),
|
||||
'Invalid argument.'
|
||||
)
|
||||
t.throws(() => formatDate('invalid argument'), 'Invalid argument.')
|
||||
})
|
||||
|
||||
112
tests/fixtures/TestDummy.js
vendored
112
tests/fixtures/TestDummy.js
vendored
@@ -5,7 +5,7 @@ const sander = require('sander')
|
||||
const CSON = require('@rokt33r/season')
|
||||
const path = require('path')
|
||||
|
||||
function dummyFolder (override = {}) {
|
||||
function dummyFolder(override = {}) {
|
||||
var data = {
|
||||
name: faker.lorem.word(),
|
||||
color: faker.internet.color()
|
||||
@@ -17,21 +17,23 @@ function dummyFolder (override = {}) {
|
||||
return data
|
||||
}
|
||||
|
||||
function dummyBoostnoteJSONData (override = {}, isLegacy = false) {
|
||||
function dummyBoostnoteJSONData(override = {}, isLegacy = false) {
|
||||
var data = {}
|
||||
if (override.folders == null) {
|
||||
data.folders = []
|
||||
|
||||
var folderCount = Math.floor((Math.random() * 5)) + 2
|
||||
var folderCount = Math.floor(Math.random() * 5) + 2
|
||||
for (var i = 0; i < folderCount; i++) {
|
||||
var key = keygen()
|
||||
while (data.folders.some((folder) => folder.key === key)) {
|
||||
while (data.folders.some(folder => folder.key === key)) {
|
||||
key = keygen()
|
||||
}
|
||||
|
||||
data.folders.push(dummyFolder({
|
||||
key
|
||||
}))
|
||||
data.folders.push(
|
||||
dummyFolder({
|
||||
key
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
if (!isLegacy) data.version = '1.0'
|
||||
@@ -41,24 +43,28 @@ function dummyBoostnoteJSONData (override = {}, isLegacy = false) {
|
||||
return data
|
||||
}
|
||||
|
||||
function dummyNote (override = {}) {
|
||||
var data = Math.random() > 0.5
|
||||
? {
|
||||
type: 'MARKDOWN_NOTE',
|
||||
content: faker.lorem.lines()
|
||||
}
|
||||
: {
|
||||
type: 'SNIPPET_NOTE',
|
||||
description: faker.lorem.lines(),
|
||||
snippets: [{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
}]
|
||||
}
|
||||
data.title = data.type === 'MARKDOWN_NOTE'
|
||||
? data.content.split('\n').shift()
|
||||
: data.description.split('\n').shift()
|
||||
function dummyNote(override = {}) {
|
||||
var data =
|
||||
Math.random() > 0.5
|
||||
? {
|
||||
type: 'MARKDOWN_NOTE',
|
||||
content: faker.lorem.lines()
|
||||
}
|
||||
: {
|
||||
type: 'SNIPPET_NOTE',
|
||||
description: faker.lorem.lines(),
|
||||
snippets: [
|
||||
{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
}
|
||||
]
|
||||
}
|
||||
data.title =
|
||||
data.type === 'MARKDOWN_NOTE'
|
||||
? data.content.split('\n').shift()
|
||||
: data.description.split('\n').shift()
|
||||
data.createdAt = faker.date.past()
|
||||
data.updatedAt = faker.date.recent()
|
||||
data.isStarred = false
|
||||
@@ -91,36 +97,41 @@ function dummyNote (override = {}) {
|
||||
* ```
|
||||
* @return {[type]}
|
||||
*/
|
||||
function dummyStorage (storagePath, override = {}) {
|
||||
var jsonData = override.json != null
|
||||
? override.json
|
||||
: dummyBoostnoteJSONData()
|
||||
var cacheData = override.cache != null
|
||||
? override.cache
|
||||
: {}
|
||||
function dummyStorage(storagePath, override = {}) {
|
||||
var jsonData =
|
||||
override.json != null ? override.json : dummyBoostnoteJSONData()
|
||||
var cacheData = override.cache != null ? override.cache : {}
|
||||
if (cacheData.key == null) cacheData.key = keygen()
|
||||
if (cacheData.name == null) cacheData.name = faker.random.word()
|
||||
if (cacheData.type == null) cacheData.type = 'FILESYSTEM'
|
||||
cacheData.path = storagePath
|
||||
|
||||
sander.writeFileSync(path.join(storagePath, 'boostnote.json'), JSON.stringify(jsonData))
|
||||
sander.writeFileSync(
|
||||
path.join(storagePath, 'boostnote.json'),
|
||||
JSON.stringify(jsonData)
|
||||
)
|
||||
var notesData = []
|
||||
var noteCount = Math.floor((Math.random() * 15)) + 2
|
||||
var noteCount = Math.floor(Math.random() * 15) + 2
|
||||
for (var i = 0; i < noteCount; i++) {
|
||||
var key = keygen(true)
|
||||
while (notesData.some((note) => note.key === key)) {
|
||||
while (notesData.some(note => note.key === key)) {
|
||||
key = keygen(true)
|
||||
}
|
||||
|
||||
var noteData = dummyNote({
|
||||
key,
|
||||
folder: jsonData.folders[Math.floor(Math.random() * jsonData.folders.length)].key
|
||||
folder:
|
||||
jsonData.folders[Math.floor(Math.random() * jsonData.folders.length)]
|
||||
.key
|
||||
})
|
||||
|
||||
notesData.push(noteData)
|
||||
}
|
||||
notesData.forEach(function saveNoteCSON (note) {
|
||||
CSON.writeFileSync(path.join(storagePath, 'notes', note.key + '.cson'), _.omit(note, ['key']))
|
||||
notesData.forEach(function saveNoteCSON(note) {
|
||||
CSON.writeFileSync(
|
||||
path.join(storagePath, 'notes', note.key + '.cson'),
|
||||
_.omit(note, ['key'])
|
||||
)
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -130,27 +141,27 @@ function dummyStorage (storagePath, override = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
function dummyLegacyStorage (storagePath, override = {}) {
|
||||
var jsonData = override.json != null
|
||||
? override.json
|
||||
: dummyBoostnoteJSONData({}, true)
|
||||
var cacheData = override.cache != null
|
||||
? override.cache
|
||||
: {}
|
||||
function dummyLegacyStorage(storagePath, override = {}) {
|
||||
var jsonData =
|
||||
override.json != null ? override.json : dummyBoostnoteJSONData({}, true)
|
||||
var cacheData = override.cache != null ? override.cache : {}
|
||||
if (cacheData.key == null) cacheData.key = keygen()
|
||||
if (cacheData.name == null) cacheData.name = faker.random.word()
|
||||
if (cacheData.type == null) cacheData.type = 'FILESYSTEM'
|
||||
cacheData.path = storagePath
|
||||
|
||||
sander.writeFileSync(path.join(storagePath, 'boostnote.json'), JSON.stringify(jsonData))
|
||||
sander.writeFileSync(
|
||||
path.join(storagePath, 'boostnote.json'),
|
||||
JSON.stringify(jsonData)
|
||||
)
|
||||
|
||||
var notesData = []
|
||||
for (var j = 0; j < jsonData.folders.length; j++) {
|
||||
var folderNotes = []
|
||||
var noteCount = Math.floor((Math.random() * 5)) + 1
|
||||
var noteCount = Math.floor(Math.random() * 5) + 1
|
||||
for (var i = 0; i < noteCount; i++) {
|
||||
var key = keygen(true)
|
||||
while (folderNotes.some((note) => note.key === key)) {
|
||||
while (folderNotes.some(note => note.key === key)) {
|
||||
key = keygen(true)
|
||||
}
|
||||
|
||||
@@ -161,7 +172,10 @@ function dummyLegacyStorage (storagePath, override = {}) {
|
||||
folderNotes.push(noteData)
|
||||
}
|
||||
notesData = notesData.concat(folderNotes)
|
||||
CSON.writeFileSync(path.join(storagePath, jsonData.folders[j].key, 'data.json'), {notes: folderNotes.map((note) => _.omit(note, ['folder']))})
|
||||
CSON.writeFileSync(
|
||||
path.join(storagePath, jsonData.folders[j].key, 'data.json'),
|
||||
{ notes: folderNotes.map(note => _.omit(note, ['folder'])) }
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ import browserEnv from 'browser-env'
|
||||
browserEnv(['window', 'document', 'navigator'])
|
||||
|
||||
// for CodeMirror mockup
|
||||
document.body.createTextRange = function () {
|
||||
document.body.createTextRange = function() {
|
||||
return {
|
||||
setEnd: function () {},
|
||||
setStart: function () {},
|
||||
getBoundingClientRect: function () {
|
||||
return {right: 0}
|
||||
setEnd: function() {},
|
||||
setStart: function() {},
|
||||
getBoundingClientRect: function() {
|
||||
return { right: 0 }
|
||||
},
|
||||
getClientRects: function () {
|
||||
getClientRects: function() {
|
||||
return {
|
||||
length: 0,
|
||||
left: 0,
|
||||
@@ -21,7 +21,7 @@ document.body.createTextRange = function () {
|
||||
|
||||
window.localStorage = {
|
||||
// polyfill
|
||||
getItem () {
|
||||
getItem() {
|
||||
return '{}'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ const noop = () => {}
|
||||
mock('electron', {
|
||||
remote: {
|
||||
app: {
|
||||
getAppPath: noop
|
||||
getAppPath: noop,
|
||||
getPath: noop
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
global.Raphael = {
|
||||
setWindow: jest.fn(),
|
||||
registerFont: jest.fn(),
|
||||
fn: function () {
|
||||
fn: function() {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
189
tests/lib/__snapshots__/markdown.test.js.snap
Normal file
189
tests/lib/__snapshots__/markdown.test.js.snap
Normal file
@@ -0,0 +1,189 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Markdown.render() should render PlantUML Ditaa correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/png/SoWkIImgISaiIKpaqjQ50cq51GLj93Q2mrMZ00NQO3cmHX3RJW4cKmDI4v9QKQ805a8nfyObCp6zA34NgCObFxiqDpMl1AIcHj4tCJqpLH5i18evG52TKbk3B8og1kmC0cvMKB1Im0NYkA2ckMRcANWabgQbvYau5YMbPfP0p4UOWmcqkHnIyrB0GG00\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render PlantUML Gantt correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/svg/SoWkIImgIK_CAodXYWueoY_9BwaiI5L8IItEJC-BLSX9B2ufLZ0qLKX9h2pcYWv9BIvHA82fWaiRu906crsia5YYW6cqUh52QbuAbmEG0DiE0000\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render PlantUML MindMaps correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/svg/JOzD3e8m44Rtd6BMtNW192IM5I29HEDsAbKdeLD2MvNRIsjCMCsRlFd9LpgFipV4Wy4f4o2r8kHC23Yhm3wi9A0X3XzeYNrgwx1H6wvb1KTjqtRJoYhMtexBSAqJUescwoEUq4tn3xp9Fm7XfUS5HiiFO3Gw7SjT4QUCkkKxLy2-WAvl3rkrtEclBdOCXcnMwZN7ByiN\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render PlantUML Umls correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/svg/LOzD2eCm44RtESMtj0jx01V5E_G4Gvngo2_912gbTsz4LBfylCV7p5Y4ibJlbEENG2AocHV1P39hCJ6eOar8bCaZaROqyrDMnzWqXTcn8YqnGzSYqNC-q76sweoW5zOsLi57uMpHz-WESslY0jmVw1AjdaE30IPeLoVUceLTslrL3-2tS9ZA_qZRtm_vgh7PzkOF\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render PlantUML WBS correctly 1`] = `
|
||||
"<img src=\\"http://www.plantuml.com/plantuml/svg/ZP2_JiD03CRtFeNdRF04fR140gdGeREv-z8plVYYimFYxSabKbaxsR9-ylTdRyxLVpvjrz5XDb6OqR6MqEPRYSXPz4BdmsdNTVJAiuP4da1JBLy8lbmxUYxZbE6Wa_CLgUI8IXymS0rf9NeL5yxKDt24EhiKfMDcRNzVO79HcX8RLdvLfZBGa_KtFx2RKcpK7TZ3dTpZfWgskMAZ9jIXr94rW4PubM1RbBZOb-6NtcS9LpgBjlj_1w9QldbPjZHxQ5pg_GC0\\" alt=\\"uml diagram\\" />
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render footnote correctly 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>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render line breaks correctly 1`] = `
|
||||
"<p data-line=\\"0\\">This is the first line.<br />
|
||||
This is the second line.</p>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render line breaks correctly 2`] = `
|
||||
"<p data-line=\\"0\\">This is the first line.
|
||||
This is the second line.</p>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should render shortcuts correctly 1`] = `
|
||||
"<p data-line=\\"0\\"><kbd>Ctrl</kbd></p>
|
||||
<p data-line=\\"2\\"><kbd>Ctrl</kbd></p>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should renders [TOC] placholder correctly 1`] = `
|
||||
"<p data-line=\\"1\\"><div class=\\"markdownIt-TOC-wrapper\\"><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>
|
||||
</div></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>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should renders KaTeX correctly 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=\\"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>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should renders abbrevations correctly 1`] = `
|
||||
"<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>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should renders checkboxes 1`] = `
|
||||
"<ul>
|
||||
<li class=\\"taskListItem\\" data-line=\\"1\\"><input type=\\"checkbox\\" id=\\"checkbox-2\\" /> Unchecked</li>
|
||||
<li class=\\"taskListItem checked\\" data-line=\\"2\\"><input type=\\"checkbox\\" checked id=\\"checkbox-3\\" /> Checked</li>
|
||||
</ul>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should renders codeblock correctly 1`] = `
|
||||
"<pre class=\\"code CodeMirror\\" data-line=\\"1\\">
|
||||
<span class=\\"filename\\">filename.js</span>
|
||||
<span class=\\"lineNumber CodeMirror-gutters\\"><span class=\\"CodeMirror-linenumber\\">2</span></span>
|
||||
<code class=\\"js\\">var project = 'boostnote';
|
||||
</code>
|
||||
</pre>"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should renders definition lists correctly 1`] = `
|
||||
"<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>
|
||||
<dt data-line=\\"8\\">Term 2</dt>
|
||||
<dd data-line=\\"9\\">Definition 2a</dd>
|
||||
<dd data-line=\\"10\\">Definition 2b</dd>
|
||||
</dl>
|
||||
<p data-line=\\"12\\">Term 3<br />
|
||||
~</p>
|
||||
<h3 id=\\"list-2\\" data-line=\\"16\\">list 2</h3>
|
||||
<dl>
|
||||
<dt data-line=\\"18\\">Term 1</dt>
|
||||
<dd data-line=\\"20\\">
|
||||
<p data-line=\\"20\\">Definition 1</p>
|
||||
</dd>
|
||||
<dt data-line=\\"22\\">Term 2 with <em>inline markup</em></dt>
|
||||
<dd data-line=\\"24\\">
|
||||
<p data-line=\\"24\\">Definition 2</p>
|
||||
<pre><code> { some code, part of Definition 2 }
|
||||
</code></pre>
|
||||
<p data-line=\\"28\\">Third paragraph of definition 2.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should renders markdown correctly 1`] = `
|
||||
"<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 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>
|
||||
<li data-line=\\"9\\"><a href=\\"https://github.com/BoostIO/Boostnote/wiki/Sync-Data-Across-Desktop-and-Mobile-apps\\">How to sync your data across Desktop and Mobile apps</a></li>
|
||||
<li data-line=\\"10\\"><a href=\\"https://github.com/BoostIO/Boostnote/wiki/Evernote\\">Convert data from <strong>Evernote</strong> to Boostnote.</a></li>
|
||||
<li data-line=\\"11\\"><a href=\\"https://github.com/BoostIO/Boostnote/wiki/Keyboard-Shortcuts\\">Keyboard Shortcuts</a></li>
|
||||
<li data-line=\\"12\\"><a href=\\"https://github.com/BoostIO/Boostnote/wiki/Keymaps-in-Editor-mode\\">Keymaps in Editor mode</a></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 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>
|
||||
<li data-line=\\"20\\"><a href=\\"https://www.reddit.com/r/boostnote_cn/\\">Reddit Chinese</a></li>
|
||||
<li data-line=\\"21\\"><a href=\\"https://www.reddit.com/r/boostnote_jp/\\">Reddit Japanese</a></li>
|
||||
</ul>
|
||||
<hr />
|
||||
<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>
|
||||
<li data-line=\\"28\\"><a href=\\"http://bit.ly/2jcca8t\\">Facebook Group</a></li>
|
||||
</ul>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should renders sub correctly 1`] = `
|
||||
"<h2 id=\\"sub\\" data-line=\\"1\\">sub</h2>
|
||||
<p data-line=\\"3\\">H<sub>2</sub>0</p>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should renders sup correctly 1`] = `
|
||||
"<h2 id=\\"sup\\" data-line=\\"1\\">sup</h2>
|
||||
<p data-line=\\"3\\">29<sup>th</sup></p>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should text with quotes correctly 1`] = `
|
||||
"<p data-line=\\"0\\">This is a “QUOTE”.</p>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Markdown.render() should text with quotes correctly 2`] = `
|
||||
"<p data-line=\\"0\\">This is a "QUOTE".</p>
|
||||
"
|
||||
`;
|
||||
@@ -1,16 +1,32 @@
|
||||
let menuBuilderParameter
|
||||
jest.mock('electron', () => {
|
||||
return {remote: {require: jest.fn(() => { return {Menu: {buildFromTemplate: jest.fn((param) => { menuBuilderParameter = param })}} })}}
|
||||
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
|
||||
})
|
||||
|
||||
it('should make sure that no context menu is build if the passed editor instance was null', function () {
|
||||
// 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
|
||||
@@ -19,89 +35,96 @@ it('should make sure that no context menu is build if the passed editor instance
|
||||
expect(menuBuilderParameter).toEqual(null)
|
||||
})
|
||||
|
||||
it('should make sure that word suggestions are only requested if the word contained a typo', function () {
|
||||
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.findWordAt = jest.fn(() => {
|
||||
return { anchor: {}, head: {} }
|
||||
})
|
||||
editor.getRange = jest.fn()
|
||||
editor.findMarks = jest.fn(() => [])
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
}
|
||||
const expectedMenuParameter = [ { role: 'cut' },
|
||||
const expectedMenuParameter = [
|
||||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'selectall' } ]
|
||||
{ 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 () {
|
||||
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.findWordAt = jest.fn(() => {
|
||||
return { anchor: {}, head: {} }
|
||||
})
|
||||
editor.getRange = jest.fn()
|
||||
const dummyMarks = [
|
||||
{className: 'someStupidClassName'}
|
||||
]
|
||||
const dummyMarks = [{ className: 'someStupidClassName' }]
|
||||
editor.findMarks = jest.fn(() => dummyMarks)
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
}
|
||||
const expectedMenuParameter = [ { role: 'cut' },
|
||||
const expectedMenuParameter = [
|
||||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'selectall' } ]
|
||||
{ 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 () {
|
||||
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 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'}
|
||||
]
|
||||
const dummyMarks = [{ className: 'someStupidClassName' }]
|
||||
editor.findMarks = jest.fn(() => dummyMarks)
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 21
|
||||
}
|
||||
|
||||
const expectedCoordsCharCall = {left: event.pageX, top: event.pageY}
|
||||
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)
|
||||
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 () {
|
||||
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}
|
||||
]
|
||||
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.findWordAt = jest.fn(() => {
|
||||
return { anchor: {}, head: {} }
|
||||
})
|
||||
editor.getRange = jest.fn(() => wordToCorrect)
|
||||
editor.findMarks = jest.fn(() => [])
|
||||
|
||||
@@ -124,3 +147,13 @@ it('should make sure that word suggestions creates a correct menu if there was a
|
||||
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)
|
||||
})
|
||||
|
||||
@@ -1,46 +1,45 @@
|
||||
const { escapeHtmlCharacters } = require('browser/lib/utils')
|
||||
const test = require('ava')
|
||||
|
||||
test('escapeHtmlCharacters should return the original string if nothing needed to escape', t => {
|
||||
test('escapeHtmlCharacters should return the original string if nothing needed to escape', () => {
|
||||
const input = 'Nothing to be escaped'
|
||||
const expected = 'Nothing to be escaped'
|
||||
const actual = escapeHtmlCharacters(input)
|
||||
t.is(actual, expected)
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
|
||||
test('escapeHtmlCharacters should skip code block if that option is enabled', t => {
|
||||
test('escapeHtmlCharacters should skip code block if that option is enabled', () => {
|
||||
const input = ` <no escape>
|
||||
<escapeMe>`
|
||||
const expected = ` <no escape>
|
||||
<escapeMe>`
|
||||
const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
|
||||
t.is(actual, expected)
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
|
||||
test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', t => {
|
||||
test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', () => {
|
||||
const input = '4 spaces &'
|
||||
const expected = '4 spaces &'
|
||||
const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
|
||||
t.is(actual, expected)
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
|
||||
test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', t => {
|
||||
test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', () => {
|
||||
const input = ` <no escape>
|
||||
<escapeMe>`
|
||||
const expected = ` <no escape>
|
||||
<escapeMe>`
|
||||
const actual = escapeHtmlCharacters(input)
|
||||
t.is(actual, expected)
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
|
||||
test("escapeHtmlCharacters should NOT escape & character if it's a part of an escaped character", t => {
|
||||
test("escapeHtmlCharacters should NOT escape & character if it's a part of an escaped character", () => {
|
||||
const input = 'Do not escape & or " but do escape &'
|
||||
const expected = 'Do not escape & or " but do escape &'
|
||||
const actual = escapeHtmlCharacters(input)
|
||||
t.is(actual, expected)
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
|
||||
test('escapeHtmlCharacters should skip char if in code block', t => {
|
||||
test('escapeHtmlCharacters should skip char if in code block', () => {
|
||||
const input = `
|
||||
\`\`\`
|
||||
<dontescapeme>
|
||||
@@ -62,12 +61,12 @@ dasdasdasd
|
||||
\`\`\`
|
||||
`
|
||||
const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
|
||||
t.is(actual, expected)
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
|
||||
test('escapeHtmlCharacters should return the correct result', t => {
|
||||
test('escapeHtmlCharacters should return the correct result', () => {
|
||||
const input = '& < > " \''
|
||||
const expected = '& < > " ''
|
||||
const actual = escapeHtmlCharacters(input)
|
||||
t.is(actual, expected)
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
@@ -1,4 +1,3 @@
|
||||
const test = require('ava')
|
||||
const { findStorage } = require('browser/lib/findStorage')
|
||||
|
||||
global.document = require('jsdom').jsdom('<body></body>')
|
||||
@@ -6,27 +5,32 @@ 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')
|
||||
const os = require('os')
|
||||
const storagePath = path.join(os.tmpdir(), 'test/find-storage')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
let storageContext
|
||||
|
||||
beforeEach(() => {
|
||||
storageContext = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([storageContext.cache]))
|
||||
})
|
||||
|
||||
// Unit test
|
||||
test('findStorage() should return a correct storage path(string)', t => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
test('findStorage() should return a correct storage path(string)', () => {
|
||||
const storageKey = storageContext.cache.key
|
||||
|
||||
t.is(findStorage(storageKey).key, storageKey)
|
||||
t.is(findStorage(storageKey).path, storagePath)
|
||||
expect(findStorage(storageKey).key).toBe(storageKey)
|
||||
expect(findStorage(storageKey).path).toBe(storagePath)
|
||||
})
|
||||
|
||||
test.after(function after () {
|
||||
afterAll(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
@@ -2,11 +2,10 @@
|
||||
* @fileoverview Unit test for browser/lib/findTitle
|
||||
*/
|
||||
|
||||
const test = require('ava')
|
||||
const { findNoteTitle } = require('browser/lib/findNoteTitle')
|
||||
|
||||
// Unit test
|
||||
test('findNoteTitle#find should return a correct title (string)', t => {
|
||||
test('findNoteTitle#find should return a correct title (string)', () => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
['# hoge\nfuga', '# hoge'],
|
||||
@@ -20,11 +19,11 @@ test('findNoteTitle#find should return a correct title (string)', t => {
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
t.is(findNoteTitle(input, false), expected, `Test for find() input: ${input} expected: ${expected}`)
|
||||
expect(findNoteTitle(input, false)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
test('findNoteTitle#find should ignore front matter when enableFrontMatterTitle=false', t => {
|
||||
test('findNoteTitle#find should ignore front matter when enableFrontMatterTitle=false', () => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
['---\nlayout: test\ntitle: hoge hoge hoge \n---\n# fuga', '# fuga'],
|
||||
@@ -34,25 +33,28 @@ test('findNoteTitle#find should ignore front matter when enableFrontMatterTitle
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
t.is(findNoteTitle(input, false), expected, `Test for find() input: ${input} expected: ${expected}`)
|
||||
expect(findNoteTitle(input, false)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
test('findNoteTitle#find should respect front matter when enableFrontMatterTitle=true', t => {
|
||||
test('findNoteTitle#find should respect front matter when enableFrontMatterTitle=true', () => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
['---\nlayout: test\ntitle: hoge hoge hoge \n---\n# fuga', 'hoge hoge hoge'],
|
||||
[
|
||||
'---\nlayout: test\ntitle: hoge hoge hoge \n---\n# fuga',
|
||||
'hoge hoge hoge'
|
||||
],
|
||||
['---\ntitle:hoge\n---\n# fuga', 'hoge'],
|
||||
['title: fuga\n# hoge', '# hoge']
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
t.is(findNoteTitle(input, true), expected, `Test for find() input: ${input} expected: ${expected}`)
|
||||
expect(findNoteTitle(input, true)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
test('findNoteTitle#find should respect frontMatterTitleField when provided', t => {
|
||||
test('findNoteTitle#find should respect frontMatterTitleField when provided', () => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
['---\ntitle: hoge\n---\n# fuga', '# fuga'],
|
||||
@@ -61,6 +63,6 @@ test('findNoteTitle#find should respect frontMatterTitleField when provided', t
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
t.is(findNoteTitle(input, true, 'custom'), expected, `Test for find() input: ${input} expected: ${expected}`)
|
||||
expect(findNoteTitle(input, true, 'custom')).toBe(expected)
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,7 @@
|
||||
const test = require('ava')
|
||||
const { getTodoStatus } = require('browser/lib/getTodoStatus')
|
||||
|
||||
// Unit test
|
||||
test('getTodoStatus should return a correct hash object', t => {
|
||||
test('getTodoStatus should return a correct hash object', () => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
['', { total: 0, completed: 0 }],
|
||||
@@ -28,13 +27,19 @@ 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 => {
|
||||
const [input, expected] = testCase
|
||||
t.is(getTodoStatus(input).total, expected.total, `Test for getTodoStatus() input: ${input} expected: ${expected.total}`)
|
||||
t.is(getTodoStatus(input).completed, expected.completed, `Test for getTodoStatus() input: ${input} expected: ${expected.completed}`)
|
||||
expect(getTodoStatus(input).total).toBe(expected.total)
|
||||
expect(getTodoStatus(input).completed).toBe(expected.completed)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/**
|
||||
* @fileoverview Unit test for browser/lib/htmlTextHelper
|
||||
*/
|
||||
const test = require('ava')
|
||||
const htmlTextHelper = require('browser/lib/htmlTextHelper')
|
||||
|
||||
// Unit test
|
||||
test('htmlTextHelper#decodeEntities should return encoded text (string)', t => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
['<a href=', '<a href='],
|
||||
['var test = 'test'', 'var test = \'test\''],
|
||||
['<a href='https://boostnote.io'>Boostnote', '<a href=\'https://boostnote.io\'>Boostnote'],
|
||||
['<\\\\?php\n var = 'hoge';', '<\\\\?php\n var = \'hoge\';'],
|
||||
['&', '&'],
|
||||
['a$'', 'a\\$\'']
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
t.is(htmlTextHelper.decodeEntities(input), expected, `Test for decodeEntities() input: ${input} expected: ${expected}`)
|
||||
})
|
||||
})
|
||||
|
||||
test('htmlTextHelper#decodeEntities() should return decoded text (string)', t => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
['<a href=', '<a href='],
|
||||
['var test = \'test\'', 'var test = 'test''],
|
||||
['<a href=\'https://boostnote.io\'>Boostnote', '<a href='https://boostnote.io'>Boostnote'],
|
||||
['<?php\n var = \'hoge\';', '<?php\n var = 'hoge';'],
|
||||
['a$\'', 'a$'']
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
t.is(htmlTextHelper.encodeEntities(input), expected, `Test for encodeEntities() input: ${input} expected: ${expected}`)
|
||||
})
|
||||
})
|
||||
|
||||
// Integration test
|
||||
test(t => {
|
||||
const testCases = [
|
||||
'var test = \'test\'',
|
||||
'<a href=\'https://boostnote.io\'>Boostnote',
|
||||
'<Component styleName=\'test\' />'
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const encodedText = htmlTextHelper.encodeEntities(testCase)
|
||||
const decodedText = htmlTextHelper.decodeEntities(encodedText)
|
||||
t.is(decodedText, testCase, 'Integration test through encodedText() and decodedText()')
|
||||
})
|
||||
})
|
||||
59
tests/lib/html-text-helper.test.js
Normal file
59
tests/lib/html-text-helper.test.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @fileoverview Unit test for browser/lib/htmlTextHelper
|
||||
*/
|
||||
const htmlTextHelper = require('browser/lib/htmlTextHelper')
|
||||
|
||||
// Unit test
|
||||
test('htmlTextHelper#decodeEntities should return encoded text (string)', () => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
['<a href=', '<a href='],
|
||||
['var test = 'test'', "var test = 'test'"],
|
||||
[
|
||||
'<a href='https://boostnote.io'>Boostnote',
|
||||
"<a href='https://boostnote.io'>Boostnote"
|
||||
],
|
||||
['<\\\\?php\n var = 'hoge';', "<\\\\?php\n var = 'hoge';"],
|
||||
['&', '&'],
|
||||
['a$'', "a\\$'"]
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
expect(htmlTextHelper.decodeEntities(input)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
test('htmlTextHelper#decodeEntities() should return decoded text (string)', () => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
['<a href=', '<a href='],
|
||||
["var test = 'test'", 'var test = 'test''],
|
||||
[
|
||||
"<a href='https://boostnote.io'>Boostnote",
|
||||
'<a href='https://boostnote.io'>Boostnote'
|
||||
],
|
||||
["<?php\n var = 'hoge';", '<?php\n var = 'hoge';'],
|
||||
["a$'", 'a$'']
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
expect(htmlTextHelper.encodeEntities(input)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
// Integration test
|
||||
test(() => {
|
||||
const testCases = [
|
||||
"var test = 'test'",
|
||||
"<a href='https://boostnote.io'>Boostnote",
|
||||
"<Component styleName='test' />"
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const encodedText = htmlTextHelper.encodeEntities(testCase)
|
||||
const decodedText = htmlTextHelper.decodeEntities(encodedText)
|
||||
expect(decodedText).toBe(testCase)
|
||||
})
|
||||
})
|
||||
@@ -1,70 +0,0 @@
|
||||
import test from 'ava'
|
||||
import Markdown from 'browser/lib/markdown'
|
||||
import markdownFixtures from '../fixtures/markdowns'
|
||||
|
||||
// basic markdown instance which meant to be used in every test cases.
|
||||
// To test markdown options, initialize a new instance in your test case
|
||||
const md = new Markdown()
|
||||
|
||||
test('Markdown.render() should renders markdown correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.basic)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders codeblock correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.codeblock)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders KaTeX correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.katex)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders checkboxes', t => {
|
||||
const rendered = md.render(markdownFixtures.checkboxes)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should text with quotes correctly', t => {
|
||||
const renderedSmartQuotes = md.render(markdownFixtures.smartQuotes)
|
||||
t.snapshot(renderedSmartQuotes)
|
||||
|
||||
const newmd = new Markdown({ typographer: false })
|
||||
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)
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders abbrevations correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.abbrevations)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders sub correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.subTexts)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders sup correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.supTexts)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders definition lists correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.deflists)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
|
||||
test('Markdown.render() should render shortcuts correctly', t => {
|
||||
const rendered = md.render(markdownFixtures.shortcuts)
|
||||
t.snapshot(rendered)
|
||||
})
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* @fileoverview Unit test for browser/lib/markdown
|
||||
*/
|
||||
const test = require('ava')
|
||||
const markdown = require('browser/lib/markdownTextHelper')
|
||||
|
||||
test(t => {
|
||||
test(() => {
|
||||
// [input, expected]
|
||||
const testCases = [
|
||||
// List
|
||||
@@ -36,11 +35,12 @@ 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 => {
|
||||
const [input, expected] = testCase
|
||||
t.is(markdown.strip(input), expected, `Test for strip() input: ${input} expected: ${expected}`)
|
||||
expect(markdown.strip(input)).toBe(expected)
|
||||
})
|
||||
})
|
||||
@@ -4,11 +4,10 @@
|
||||
|
||||
import CodeMirror from 'codemirror'
|
||||
require('codemirror/addon/search/searchcursor.js')
|
||||
const test = require('ava')
|
||||
const markdownToc = require('browser/lib/markdown-toc-generator')
|
||||
const EOL = require('os').EOL
|
||||
|
||||
test(t => {
|
||||
test(() => {
|
||||
/**
|
||||
* Contains array of test cases in format :
|
||||
* [
|
||||
@@ -261,11 +260,11 @@ this is a text
|
||||
const expectedToc = testCase[2].trim()
|
||||
const generatedToc = markdownToc.generate(inputMd)
|
||||
|
||||
t.is(generatedToc, expectedToc, `generate test : ${title} , generated : ${EOL}${generatedToc}, expected : ${EOL}${expectedToc}`)
|
||||
expect(generatedToc).toBe(expectedToc)
|
||||
})
|
||||
})
|
||||
|
||||
test(t => {
|
||||
test(() => {
|
||||
/**
|
||||
* Contains array of test cases in format :
|
||||
* [
|
||||
@@ -279,7 +278,7 @@ test(t => {
|
||||
const testCases = [
|
||||
[
|
||||
`***************************** Empty note, cursor at the top`,
|
||||
{line: 0, ch: 0},
|
||||
{ line: 0, ch: 0 },
|
||||
``,
|
||||
`
|
||||
<!-- toc -->
|
||||
@@ -291,7 +290,7 @@ test(t => {
|
||||
],
|
||||
[
|
||||
`***************************** Two level note,TOC at the beginning `,
|
||||
{line: 0, ch: 0},
|
||||
{ line: 0, ch: 0 },
|
||||
`
|
||||
# one
|
||||
this is a level one text
|
||||
@@ -329,7 +328,7 @@ this is a level one text
|
||||
],
|
||||
[
|
||||
`***************************** Two level note, cursor just after 'header text' `,
|
||||
{line: 1, ch: 12},
|
||||
{ line: 1, ch: 12 },
|
||||
`
|
||||
# header
|
||||
header text
|
||||
@@ -373,7 +372,7 @@ this is a level one text
|
||||
],
|
||||
[
|
||||
`***************************** Two level note, cursor at empty line under 'header text' `,
|
||||
{line: 2, ch: 0},
|
||||
{ line: 2, ch: 0 },
|
||||
`
|
||||
# header
|
||||
header text
|
||||
@@ -416,7 +415,7 @@ this is a level one text
|
||||
],
|
||||
[
|
||||
`***************************** Two level note, cursor just before 'text' word`,
|
||||
{line: 1, ch: 8},
|
||||
{ line: 1, ch: 8 },
|
||||
`
|
||||
# header
|
||||
header text
|
||||
@@ -461,7 +460,7 @@ this is a level one text
|
||||
],
|
||||
[
|
||||
`***************************** Already generated TOC without header file, regenerate TOC in place, no changes`,
|
||||
{line: 13, ch: 0},
|
||||
{ line: 13, ch: 0 },
|
||||
`
|
||||
# header
|
||||
header text
|
||||
@@ -511,7 +510,7 @@ this is a level one text
|
||||
],
|
||||
[
|
||||
`***************************** Already generated TOC, needs updating in place`,
|
||||
{line: 0, ch: 0},
|
||||
{ line: 0, ch: 0 },
|
||||
`
|
||||
# header
|
||||
header text
|
||||
@@ -561,7 +560,7 @@ this is a level one text
|
||||
],
|
||||
[
|
||||
`***************************** Document with cursor at the last line, expecting empty TOC `,
|
||||
{line: 13, ch: 30},
|
||||
{ line: 13, ch: 30 },
|
||||
`
|
||||
# header
|
||||
header text
|
||||
@@ -602,7 +601,7 @@ this is a level one text
|
||||
],
|
||||
[
|
||||
`***************************** Empty, not actual TOC , should be supplemented with two new points beneath`,
|
||||
{line: 0, ch: 0},
|
||||
{ line: 0, ch: 0 },
|
||||
`
|
||||
# header
|
||||
header text
|
||||
@@ -663,6 +662,6 @@ this is a level one text
|
||||
editor.setCursor(cursor)
|
||||
markdownToc.generateInEditor(editor)
|
||||
|
||||
t.is(expectedMd, editor.getValue(), `generateInEditor test : ${title} , generated : ${EOL}${editor.getValue()}, expected : ${EOL}${expectedMd}`)
|
||||
expect(expectedMd).toBe(editor.getValue())
|
||||
})
|
||||
})
|
||||
118
tests/lib/markdown.test.js
Normal file
118
tests/lib/markdown.test.js
Normal file
@@ -0,0 +1,118 @@
|
||||
jest.mock(
|
||||
'electron',
|
||||
() => {
|
||||
return {
|
||||
remote: {
|
||||
app: {
|
||||
getPath: jest.fn().mockReturnValue('.')
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ virtual: true }
|
||||
)
|
||||
|
||||
import Markdown from 'browser/lib/markdown'
|
||||
import markdownFixtures from '../fixtures/markdowns'
|
||||
|
||||
// basic markdown instance which meant to be used in every test cases.
|
||||
// To test markdown options, initialize a new instance in your test case
|
||||
const md = new Markdown()
|
||||
|
||||
test('Markdown.render() should renders markdown correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.basic)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders codeblock correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.codeblock)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders KaTeX correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.katex)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders checkboxes', () => {
|
||||
const rendered = md.render(markdownFixtures.checkboxes)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should text with quotes correctly', () => {
|
||||
const renderedSmartQuotes = md.render(markdownFixtures.smartQuotes)
|
||||
expect(renderedSmartQuotes).toMatchSnapshot()
|
||||
|
||||
const newmd = new Markdown({ typographer: false })
|
||||
const renderedNonSmartQuotes = newmd.render(markdownFixtures.smartQuotes)
|
||||
expect(renderedNonSmartQuotes).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render line breaks correctly', () => {
|
||||
const renderedBreaks = md.render(markdownFixtures.breaks)
|
||||
expect(renderedBreaks).toMatchSnapshot()
|
||||
|
||||
const newmd = new Markdown({ breaks: false })
|
||||
const renderedNonBreaks = newmd.render(markdownFixtures.breaks)
|
||||
expect(renderedNonBreaks).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders abbrevations correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.abbrevations)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders sub correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.subTexts)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders sup correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.supTexts)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders definition lists correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.deflists)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render shortcuts correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.shortcuts)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render footnote correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.footnote)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should renders [TOC] placholder correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.tocPlaceholder)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML MindMaps correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlMindMap)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML Gantt correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlGantt)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML WBS correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlWbs)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML Umls correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlUml)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Markdown.render() should render PlantUML Ditaa correctly', () => {
|
||||
const rendered = md.render(markdownFixtures.plantUmlDitaa)
|
||||
expect(rendered).toMatchSnapshot()
|
||||
})
|
||||
@@ -1,16 +1,17 @@
|
||||
/**
|
||||
* @fileoverview Unit test for browser/lib/normalizeEditorFontFamily
|
||||
*/
|
||||
import test from 'ava'
|
||||
import normalizeEditorFontFamily from '../../browser/lib/normalizeEditorFontFamily'
|
||||
import consts from '../../browser/lib/consts'
|
||||
const defaultEditorFontFamily = consts.DEFAULT_EDITOR_FONT_FAMILY
|
||||
|
||||
test('normalizeEditorFontFamily() should return default font family (string[])', t => {
|
||||
t.is(normalizeEditorFontFamily(), defaultEditorFontFamily.join(', '))
|
||||
test('normalizeEditorFontFamily() should return default font family (string[])', () => {
|
||||
expect(normalizeEditorFontFamily()).toBe(defaultEditorFontFamily.join(', '))
|
||||
})
|
||||
|
||||
test('normalizeEditorFontFamily(["hoge", "huga"]) should return default font family connected with arg.', t => {
|
||||
test('normalizeEditorFontFamily(["hoge", "huga"]) should return default font family connected with arg.', () => {
|
||||
const arg = 'font1, font2'
|
||||
t.is(normalizeEditorFontFamily(arg), `${arg}, ${defaultEditorFontFamily.join(', ')}`)
|
||||
expect(normalizeEditorFontFamily(arg)).toBe(
|
||||
`${arg}, ${defaultEditorFontFamily.join(', ')}`
|
||||
)
|
||||
})
|
||||
@@ -1,33 +0,0 @@
|
||||
const test = require('ava')
|
||||
const path = require('path')
|
||||
const { parse } = require('browser/lib/RcParser')
|
||||
|
||||
// Unit test
|
||||
test('RcParser should return a json object', t => {
|
||||
const validJson = { 'editor': { 'keyMap': 'vim', 'switchPreview': 'BLUR', 'theme': 'monokai' }, 'hotkey': { 'toggleMain': 'Control + L' }, 'listWidth': 135, 'navWidth': 135 }
|
||||
const allJson = { 'amaEnabled': true, 'editor': { 'fontFamily': 'Monaco, Consolas', 'fontSize': '14', 'indentSize': '2', 'indentType': 'space', 'keyMap': 'vim', 'switchPreview': 'BLUR', 'theme': 'monokai' }, 'hotkey': { 'toggleMain': 'Cmd + Alt + L' }, 'isSideNavFolded': false, 'listStyle': 'DEFAULT', 'listWidth': 174, 'navWidth': 200, 'preview': { 'codeBlockTheme': 'dracula', 'fontFamily': 'Lato', 'fontSize': '14', 'lineNumber': true }, 'sortBy': { 'default': 'UPDATED_AT' }, 'ui': { 'defaultNote': 'ALWAYS_ASK', 'disableDirectWrite': false, 'theme': 'default' }, 'zoom': 1 }
|
||||
|
||||
// [input, expected]
|
||||
const validTestCases = [
|
||||
['.boostnoterc.valid', validJson],
|
||||
['.boostnoterc.all', allJson]
|
||||
]
|
||||
|
||||
const invalidTestCases = [
|
||||
['.boostnoterc.invalid', {}]
|
||||
]
|
||||
|
||||
validTestCases.forEach(validTestCase => {
|
||||
const [input, expected] = validTestCase
|
||||
t.is(parse(filePath(input)).editor.keyMap, expected.editor.keyMap, `Test for getTodoStatus() input: ${input} expected: ${expected.keyMap}`)
|
||||
})
|
||||
|
||||
invalidTestCases.forEach(invalidTestCase => {
|
||||
const [input, expected] = invalidTestCase
|
||||
t.is(parse(filePath(input)).editor, expected.editor, `Test for getTodoStatus() input: ${input} expected: ${expected.editor}`)
|
||||
})
|
||||
})
|
||||
|
||||
function filePath (filename) {
|
||||
return path.join(`${__dirname}/boostnoterc`, filename)
|
||||
}
|
||||
64
tests/lib/rc-parser.test.js
Normal file
64
tests/lib/rc-parser.test.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const path = require('path')
|
||||
const { parse } = require('browser/lib/RcParser')
|
||||
|
||||
// Unit test
|
||||
test('RcParser should return a json object', () => {
|
||||
const validJson = {
|
||||
editor: { keyMap: 'vim', switchPreview: 'BLUR', theme: 'monokai' },
|
||||
hotkey: { toggleMain: 'Control + L' },
|
||||
listWidth: 135,
|
||||
navWidth: 135
|
||||
}
|
||||
const allJson = {
|
||||
amaEnabled: true,
|
||||
editor: {
|
||||
fontFamily: 'Monaco, Consolas',
|
||||
fontSize: '14',
|
||||
indentSize: '2',
|
||||
indentType: 'space',
|
||||
keyMap: 'vim',
|
||||
switchPreview: 'BLUR',
|
||||
theme: 'monokai'
|
||||
},
|
||||
hotkey: { toggleMain: 'Cmd + Alt + L' },
|
||||
isSideNavFolded: false,
|
||||
listStyle: 'DEFAULT',
|
||||
listWidth: 174,
|
||||
navWidth: 200,
|
||||
preview: {
|
||||
codeBlockTheme: 'dracula',
|
||||
fontFamily: 'Lato',
|
||||
fontSize: '14',
|
||||
lineNumber: true
|
||||
},
|
||||
sortBy: { default: 'UPDATED_AT' },
|
||||
ui: {
|
||||
defaultNote: 'ALWAYS_ASK',
|
||||
disableDirectWrite: false,
|
||||
theme: 'default'
|
||||
},
|
||||
zoom: 1
|
||||
}
|
||||
|
||||
// [input, expected]
|
||||
const validTestCases = [
|
||||
['.boostnoterc.valid', validJson],
|
||||
['.boostnoterc.all', allJson]
|
||||
]
|
||||
|
||||
const invalidTestCases = [['.boostnoterc.invalid', {}]]
|
||||
|
||||
validTestCases.forEach(validTestCase => {
|
||||
const [input, expected] = validTestCase
|
||||
expect(parse(filePath(input)).editor.keyMap).toBe(expected.editor.keyMap)
|
||||
})
|
||||
|
||||
invalidTestCases.forEach(invalidTestCase => {
|
||||
const [input, expected] = invalidTestCase
|
||||
expect(parse(filePath(input)).editor).toBe(expected.editor)
|
||||
})
|
||||
})
|
||||
|
||||
function filePath(filename) {
|
||||
return path.join(`${__dirname}/boostnoterc`, filename)
|
||||
}
|
||||
@@ -1,16 +1,22 @@
|
||||
import test from 'ava'
|
||||
import searchFromNotes from 'browser/lib/search'
|
||||
import { dummyNote } from '../fixtures/TestDummy'
|
||||
import _ from 'lodash'
|
||||
|
||||
const pickContents = (notes) => notes.map((note) => { return note.content })
|
||||
const pickContents = notes =>
|
||||
notes.map(note => {
|
||||
return note.content
|
||||
})
|
||||
|
||||
let notes = []
|
||||
let note1, note2, note3
|
||||
|
||||
test.before(t => {
|
||||
beforeAll(() => {
|
||||
const data1 = { type: 'MARKDOWN_NOTE', content: 'content1', tags: ['tag1'] }
|
||||
const data2 = { type: 'MARKDOWN_NOTE', content: 'content1\ncontent2', tags: ['tag1', 'tag2'] }
|
||||
const data2 = {
|
||||
type: 'MARKDOWN_NOTE',
|
||||
content: 'content1\ncontent2',
|
||||
tags: ['tag1', 'tag2']
|
||||
}
|
||||
const data3 = { type: 'MARKDOWN_NOTE', content: '#content4', tags: ['tag1'] }
|
||||
|
||||
note1 = dummyNote(data1)
|
||||
@@ -20,7 +26,7 @@ test.before(t => {
|
||||
notes = [note1, note2, note3]
|
||||
})
|
||||
|
||||
test('it can find notes by tags and words', t => {
|
||||
test('it can find notes by tags and words', () => {
|
||||
// [input, expected content (Array)]
|
||||
const testWithTags = [
|
||||
['#tag1', [note1.content, note2.content, note3.content]],
|
||||
@@ -34,14 +40,16 @@ test('it can find notes by tags and words', t => {
|
||||
['#tag2 content1', [note2.content]],
|
||||
['content1 #tag2', [note2.content]]
|
||||
]
|
||||
const testWithTagsWithoutHash = testWithTags.map(function (testCase) {
|
||||
const testWithTagsWithoutHash = testWithTags.map(function(testCase) {
|
||||
return [testCase[0].replace(/#/g, ''), testCase[1]]
|
||||
})
|
||||
|
||||
const testCases = testWithTags.concat(testWithTagsWithoutHash)
|
||||
testCases.forEach((testCase) => {
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expectedContents] = testCase
|
||||
const results = searchFromNotes(notes, input)
|
||||
t.true(_.isEqual(pickContents(results).sort(), expectedContents.sort()))
|
||||
expect(
|
||||
_.isEqual(pickContents(results).sort(), expectedContents.sort())
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
57
tests/lib/slugify.test.js
Normal file
57
tests/lib/slugify.test.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import slugify from 'browser/lib/slugify'
|
||||
|
||||
test('alphabet and digit', () => {
|
||||
const upperAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
const lowerAlphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
const digit = '0123456789'
|
||||
const testCase = upperAlphabet + lowerAlphabet + digit
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
expect(decodeSlug === testCase).toBe(true)
|
||||
})
|
||||
|
||||
test('should delete unavailable symbols', () => {
|
||||
const availableSymbols = '_-'
|
||||
const testCase = availableSymbols + "][!'#$%&()*+,./:;<=>?@\\^{|}~`"
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
expect(decodeSlug === availableSymbols).toBe(true)
|
||||
})
|
||||
|
||||
test('should convert from white spaces between words to hyphens', () => {
|
||||
const testCase = 'This is one'
|
||||
const expectedString = 'This-is-one'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
expect(decodeSlug === expectedString).toBe(true)
|
||||
})
|
||||
|
||||
test('should remove leading white spaces', () => {
|
||||
const testCase = ' This is one'
|
||||
const expectedString = 'This-is-one'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
expect(decodeSlug === expectedString).toBe(true)
|
||||
})
|
||||
|
||||
test('should remove trailing white spaces', () => {
|
||||
const testCase = 'This is one '
|
||||
const expectedString = 'This-is-one'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
expect(decodeSlug === expectedString).toBe(true)
|
||||
})
|
||||
|
||||
test('2-byte charactor support', () => {
|
||||
const testCase = '菠萝芒果テストÀžƁƵ'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
expect(decodeSlug === testCase).toBe(true)
|
||||
})
|
||||
|
||||
test('emoji', () => {
|
||||
const testCase = '🌸'
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
expect(decodeSlug === testCase).toBe(true)
|
||||
})
|
||||
@@ -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,7 +80,29 @@ 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"><div class="markdownIt-TOC-wrapper"><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>␊
|
||||
</div></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
|
||||
|
||||
Binary file not shown.
@@ -9,12 +9,12 @@ beforeEach(() => {
|
||||
Typo.mockClear()
|
||||
})
|
||||
|
||||
it('should test that checkWord does not marks words that do not contain a typo', function () {
|
||||
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 range = { anchor: { line: 1, ch: 0 }, head: { line: 1, ch: 10 } }
|
||||
const mockDictionary = jest.fn()
|
||||
mockDictionary.check = jest.fn(() => true)
|
||||
systemUnderTest.setDictionaryForTestsOnly(mockDictionary)
|
||||
@@ -26,12 +26,12 @@ it('should test that checkWord does not marks words that do not contain a typo',
|
||||
expect(editor.markText).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should test that checkWord should marks words that contain a typo', function () {
|
||||
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 range = { anchor: { line: 1, ch: 0 }, head: { line: 1, ch: 10 } }
|
||||
const mockDictionary = jest.fn()
|
||||
mockDictionary.check = jest.fn(() => false)
|
||||
systemUnderTest.setDictionaryForTestsOnly(mockDictionary)
|
||||
@@ -40,14 +40,16 @@ it('should test that checkWord should marks words that contain a typo', function
|
||||
|
||||
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})
|
||||
expect(editor.markText).toHaveBeenCalledWith(range.anchor, range.head, {
|
||||
className: systemUnderTest.CSS_ERROR_CLASS
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that setLanguage clears all marks', function () {
|
||||
it('should test that setLanguage clears all marks', function() {
|
||||
const dummyMarks = [
|
||||
{clear: jest.fn()},
|
||||
{clear: jest.fn()},
|
||||
{clear: jest.fn()}
|
||||
{ clear: jest.fn() },
|
||||
{ clear: jest.fn() },
|
||||
{ clear: jest.fn() }
|
||||
]
|
||||
const editor = jest.fn()
|
||||
editor.getAllMarks = jest.fn(() => dummyMarks)
|
||||
@@ -60,10 +62,12 @@ it('should test that setLanguage clears all marks', function () {
|
||||
}
|
||||
})
|
||||
|
||||
it('should test that setLanguage with DISABLED as a lang argument should not load any dictionary and not check the whole document', function () {
|
||||
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()
|
||||
const checkWholeDocumentSpy = jest
|
||||
.spyOn(systemUnderTest, 'checkWholeDocument')
|
||||
.mockImplementation()
|
||||
|
||||
systemUnderTest.setLanguage(editor, systemUnderTest.SPELLCHECK_DISABLED)
|
||||
|
||||
@@ -72,38 +76,45 @@ it('should test that setLanguage with DISABLED as a lang argument should not loa
|
||||
checkWholeDocumentSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should test that setLanguage loads the correct dictionary', function () {
|
||||
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()
|
||||
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].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 () {
|
||||
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'))
|
||||
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}
|
||||
'\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)
|
||||
|
||||
@@ -121,23 +132,26 @@ it('should test that checkMultiLineRange performs checks for each word in the st
|
||||
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 () {
|
||||
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'))
|
||||
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}
|
||||
'\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)
|
||||
|
||||
@@ -155,23 +169,26 @@ it('should test that checkMultiLineRange works correct even when the range is in
|
||||
expect(dic.check.mock.calls[10][0]).toEqual('tristique')
|
||||
})
|
||||
|
||||
it('should test that checkMultiLineRange works for single line', function () {
|
||||
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'))
|
||||
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}
|
||||
'\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)
|
||||
|
||||
@@ -181,23 +198,26 @@ it('should test that checkMultiLineRange works for single line', function () {
|
||||
expect(dic.check.mock.calls[2][0]).toEqual('ullamcorper')
|
||||
})
|
||||
|
||||
it('should test that checkMultiLineRange works for single word', function () {
|
||||
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'))
|
||||
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}
|
||||
'\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)
|
||||
|
||||
@@ -205,8 +225,10 @@ it('should test that checkMultiLineRange works for single word', function () {
|
||||
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()
|
||||
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()
|
||||
|
||||
@@ -219,61 +241,88 @@ it('should make sure that liveSpellcheck don\'t work if the spellcheck is not en
|
||||
checkMultiLineRangeSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should make sure that liveSpellcheck works for a range of changes', function () {
|
||||
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()}]
|
||||
const marks = [{ clear: jest.fn() }, { clear: jest.fn() }]
|
||||
editor.findMarks = jest.fn(() => marks)
|
||||
const checkMultiLineRangeSpy = jest.spyOn(systemUnderTest, 'checkMultiLineRange').mockImplementation()
|
||||
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}}
|
||||
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(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 () {
|
||||
it('should make sure that liveSpellcheck works if ranges are inverted', function() {
|
||||
const editor = jest.fn()
|
||||
const marks = [{clear: jest.fn()}, {clear: jest.fn()}]
|
||||
const marks = [{ clear: jest.fn() }, { clear: jest.fn() }]
|
||||
editor.findMarks = jest.fn(() => marks)
|
||||
const checkMultiLineRangeSpy = jest.spyOn(systemUnderTest, 'checkMultiLineRange').mockImplementation()
|
||||
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}}
|
||||
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(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 () {
|
||||
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'))
|
||||
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}}
|
||||
'\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)
|
||||
|
||||
@@ -281,23 +330,26 @@ it('should make sure that liveSpellcheck works for a single word with change at
|
||||
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 () {
|
||||
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'))
|
||||
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}}
|
||||
'\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)
|
||||
|
||||
@@ -305,23 +357,26 @@ it('should make sure that liveSpellcheck works for a single word with change in
|
||||
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 () {
|
||||
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'))
|
||||
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}}
|
||||
'\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)
|
||||
|
||||
|
||||
103
tests/lib/themeManager.test.js
Normal file
103
tests/lib/themeManager.test.js
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @fileoverview Unit test for browser/main/lib/ThemeManager.js
|
||||
*/
|
||||
const { chooseTheme, applyTheme } = require('browser/main/lib/ThemeManager')
|
||||
jest.mock('../../browser/main/lib/ConfigManager', () => {
|
||||
return {
|
||||
set: () => {}
|
||||
}
|
||||
})
|
||||
|
||||
const originalDate = Date
|
||||
let context = {}
|
||||
|
||||
beforeAll(() => {
|
||||
const constantDate = new Date('2017-11-27T14:33:42')
|
||||
global.Date = class extends Date {
|
||||
constructor() {
|
||||
super()
|
||||
return constantDate
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
context = {
|
||||
ui: {
|
||||
theme: 'white',
|
||||
scheduledTheme: 'dark',
|
||||
enableScheduleTheme: true,
|
||||
defaultTheme: 'monokai'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
global.Date = originalDate
|
||||
})
|
||||
|
||||
test("enableScheduleTheme is false, theme shouldn't change", () => {
|
||||
context.ui.enableScheduleTheme = false
|
||||
|
||||
const beforeTheme = context.ui.theme
|
||||
chooseTheme(context)
|
||||
const afterTheme = context.ui.theme
|
||||
|
||||
expect(afterTheme).toBe(beforeTheme)
|
||||
})
|
||||
|
||||
// NOT IN SCHEDULE
|
||||
test("scheduleEnd is bigger than scheduleStart and not in schedule, theme shouldn't change", () => {
|
||||
const beforeTheme = context.ui.defaultTheme
|
||||
context.ui.scheduleStart = 720 // 12:00
|
||||
context.ui.scheduleEnd = 870 // 14:30
|
||||
chooseTheme(context)
|
||||
const afterTheme = context.ui.theme
|
||||
|
||||
expect(afterTheme).toBe(beforeTheme)
|
||||
})
|
||||
|
||||
test("scheduleStart is bigger than scheduleEnd and not in schedule, theme shouldn't change", () => {
|
||||
const beforeTheme = context.ui.defaultTheme
|
||||
context.ui.scheduleStart = 960 // 16:00
|
||||
context.ui.scheduleEnd = 600 // 10:00
|
||||
chooseTheme(context)
|
||||
const afterTheme = context.ui.theme
|
||||
|
||||
expect(afterTheme).toBe(beforeTheme)
|
||||
})
|
||||
|
||||
// IN SCHEDULE
|
||||
test('scheduleEnd is bigger than scheduleStart and in schedule, theme should change', () => {
|
||||
const beforeTheme = context.ui.scheduledTheme
|
||||
context.ui.scheduleStart = 720 // 12:00
|
||||
context.ui.scheduleEnd = 900 // 15:00
|
||||
chooseTheme(context)
|
||||
const afterTheme = context.ui.theme
|
||||
|
||||
expect(afterTheme).toBe(beforeTheme)
|
||||
})
|
||||
|
||||
test('scheduleStart is bigger than scheduleEnd and in schedule, theme should change', () => {
|
||||
const beforeTheme = context.ui.scheduledTheme
|
||||
context.ui.scheduleStart = 1200 // 20:00
|
||||
context.ui.scheduleEnd = 900 // 15:00
|
||||
chooseTheme(context)
|
||||
const afterTheme = context.ui.theme
|
||||
|
||||
expect(afterTheme).toBe(beforeTheme)
|
||||
})
|
||||
|
||||
test("theme to apply is not a supported theme, theme shouldn't change", () => {
|
||||
applyTheme('notATheme')
|
||||
const afterTheme = document.body.dataset.theme
|
||||
|
||||
expect(afterTheme).toBe('default')
|
||||
})
|
||||
|
||||
test('theme to apply is a supported theme, theme should change', () => {
|
||||
applyTheme(context.ui.defaultTheme)
|
||||
const afterTheme = document.body.dataset.theme
|
||||
|
||||
expect(afterTheme).toBe(context.ui.defaultTheme)
|
||||
})
|
||||
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