mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge branch 'master' of https://github.com/BoostIO/Boostnote into fixIssue2534
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()} color='#000' />)
|
||||
const tagListItem = renderer.create(
|
||||
<TagListItem name='Test' handleClickTagListItem={jest.fn()} color='#000' />
|
||||
)
|
||||
|
||||
expect(tagListItem.toJSON()).toMatchSnapshot()
|
||||
})
|
||||
|
||||
@@ -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
@@ -13,13 +13,13 @@ const srcPath = path.join(srcFolder, testFile)
|
||||
const dstFolder = path.join(__dirname, '😇')
|
||||
const dstPath = path.join(dstFolder, testFile)
|
||||
|
||||
test.before((t) => {
|
||||
test.before(t => {
|
||||
if (!fs.existsSync(srcFolder)) fs.mkdirSync(srcFolder)
|
||||
|
||||
fs.writeFileSync(srcPath, 'test')
|
||||
})
|
||||
|
||||
test('`copyFile` should handle encoded URI on src path', (t) => {
|
||||
test('`copyFile` should handle encoded URI on src path', t => {
|
||||
return copyFile(encodeURI(srcPath), dstPath)
|
||||
.then(() => {
|
||||
t.true(true)
|
||||
@@ -29,10 +29,9 @@ test('`copyFile` should handle encoded URI on src path', (t) => {
|
||||
})
|
||||
})
|
||||
|
||||
test.after((t) => {
|
||||
test.after(t => {
|
||||
fs.unlinkSync(srcPath)
|
||||
fs.unlinkSync(dstPath)
|
||||
execSync(removeDirCommand + '"' + srcFolder + '"')
|
||||
execSync(removeDirCommand + '"' + dstFolder + '"')
|
||||
})
|
||||
|
||||
|
||||
@@ -6,7 +6,10 @@ global.window = document.defaultView
|
||||
global.navigator = window.navigator
|
||||
|
||||
const Storage = require('dom-storage')
|
||||
const localStorage = window.localStorage = global.localStorage = new Storage(null, { strict: true })
|
||||
const localStorage = (window.localStorage = global.localStorage = new Storage(
|
||||
null,
|
||||
{ strict: true }
|
||||
))
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
const TestDummy = require('../fixtures/TestDummy')
|
||||
@@ -16,30 +19,32 @@ const CSON = require('@rokt33r/season')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/create-folder')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
test.beforeEach(t => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
test.serial('Create a folder', (t) => {
|
||||
test.serial('Create a folder', t => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const input = {
|
||||
name: 'created',
|
||||
color: '#ff5555'
|
||||
}
|
||||
return Promise.resolve()
|
||||
.then(function doTest () {
|
||||
.then(function doTest() {
|
||||
return createFolder(storageKey, input)
|
||||
})
|
||||
.then(function assert (data) {
|
||||
.then(function assert(data) {
|
||||
t.true(_.find(data.storage.folders, input) != null)
|
||||
const jsonData = CSON.readFileSync(path.join(data.storage.path, 'boostnote.json'))
|
||||
const jsonData = CSON.readFileSync(
|
||||
path.join(data.storage.path, 'boostnote.json')
|
||||
)
|
||||
console.log(path.join(data.storage.path, 'boostnote.json'))
|
||||
t.true(_.find(jsonData.folders, input) != null)
|
||||
})
|
||||
})
|
||||
|
||||
test.after(function after () {
|
||||
test.after(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
|
||||
@@ -6,7 +6,10 @@ global.window = document.defaultView
|
||||
global.navigator = window.navigator
|
||||
|
||||
const Storage = require('dom-storage')
|
||||
const localStorage = window.localStorage = global.localStorage = new Storage(null, { strict: true })
|
||||
const localStorage = (window.localStorage = global.localStorage = new Storage(
|
||||
null,
|
||||
{ strict: true }
|
||||
))
|
||||
const path = require('path')
|
||||
const TestDummy = require('../fixtures/TestDummy')
|
||||
const sander = require('sander')
|
||||
@@ -16,26 +19,30 @@ const faker = require('faker')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/create-note')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
test.beforeEach(t => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
test.serial('Create a note', (t) => {
|
||||
test.serial('Create a note', t => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const folderKey = t.context.storage.json.folders[0].key
|
||||
|
||||
const randLinesHighlightedArray = new Array(10).fill().map(() => Math.round(Math.random() * 10))
|
||||
const randLinesHighlightedArray = new Array(10)
|
||||
.fill()
|
||||
.map(() => Math.round(Math.random() * 10))
|
||||
|
||||
const input1 = {
|
||||
type: 'SNIPPET_NOTE',
|
||||
description: faker.lorem.lines(),
|
||||
snippets: [{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines(),
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}],
|
||||
snippets: [
|
||||
{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines(),
|
||||
linesHighlighted: randLinesHighlightedArray
|
||||
}
|
||||
],
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
}
|
||||
@@ -51,18 +58,20 @@ test.serial('Create a note', (t) => {
|
||||
input2.title = input2.content.split('\n').shift()
|
||||
|
||||
return Promise.resolve()
|
||||
.then(function doTest () {
|
||||
.then(function doTest() {
|
||||
return Promise.all([
|
||||
createNote(storageKey, input1),
|
||||
createNote(storageKey, input2)
|
||||
])
|
||||
})
|
||||
.then(function assert (data) {
|
||||
.then(function assert(data) {
|
||||
const data1 = data[0]
|
||||
const data2 = data[1]
|
||||
|
||||
t.is(storageKey, data1.storage)
|
||||
const jsonData1 = CSON.readFileSync(path.join(storagePath, 'notes', data1.key + '.cson'))
|
||||
const jsonData1 = CSON.readFileSync(
|
||||
path.join(storagePath, 'notes', data1.key + '.cson')
|
||||
)
|
||||
|
||||
t.is(input1.title, data1.title)
|
||||
t.is(input1.title, jsonData1.title)
|
||||
@@ -76,11 +85,19 @@ test.serial('Create a note', (t) => {
|
||||
t.is(input1.snippets[0].content, jsonData1.snippets[0].content)
|
||||
t.is(input1.snippets[0].name, data1.snippets[0].name)
|
||||
t.is(input1.snippets[0].name, jsonData1.snippets[0].name)
|
||||
t.deepEqual(input1.snippets[0].linesHighlighted, data1.snippets[0].linesHighlighted)
|
||||
t.deepEqual(input1.snippets[0].linesHighlighted, jsonData1.snippets[0].linesHighlighted)
|
||||
t.deepEqual(
|
||||
input1.snippets[0].linesHighlighted,
|
||||
data1.snippets[0].linesHighlighted
|
||||
)
|
||||
t.deepEqual(
|
||||
input1.snippets[0].linesHighlighted,
|
||||
jsonData1.snippets[0].linesHighlighted
|
||||
)
|
||||
|
||||
t.is(storageKey, data2.storage)
|
||||
const jsonData2 = CSON.readFileSync(path.join(storagePath, 'notes', data2.key + '.cson'))
|
||||
const jsonData2 = CSON.readFileSync(
|
||||
path.join(storagePath, 'notes', data2.key + '.cson')
|
||||
)
|
||||
t.is(input2.title, data2.title)
|
||||
t.is(input2.title, jsonData2.title)
|
||||
t.is(input2.content, data2.content)
|
||||
@@ -92,7 +109,7 @@ test.serial('Create a note', (t) => {
|
||||
})
|
||||
})
|
||||
|
||||
test.after(function after () {
|
||||
test.after(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
|
||||
@@ -6,7 +6,10 @@ global.window = document.defaultView
|
||||
global.navigator = window.navigator
|
||||
|
||||
const Storage = require('dom-storage')
|
||||
const localStorage = window.localStorage = global.localStorage = new Storage(null, { strict: true })
|
||||
const localStorage = (window.localStorage = global.localStorage = new Storage(
|
||||
null,
|
||||
{ strict: true }
|
||||
))
|
||||
const path = require('path')
|
||||
const TestDummy = require('../fixtures/TestDummy')
|
||||
const sander = require('sander')
|
||||
@@ -15,29 +18,32 @@ const CSON = require('@rokt33r/season')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/create-note-from-url')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
test.beforeEach(t => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
test.serial('Create a note from URL', (t) => {
|
||||
test.serial('Create a note from URL', t => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const folderKey = t.context.storage.json.folders[0].key
|
||||
|
||||
const url = 'https://shapeshed.com/writing-cross-platform-node/'
|
||||
|
||||
return createNoteFromUrl(url, storageKey, folderKey)
|
||||
.then(function assert ({ note }) {
|
||||
t.is(storageKey, note.storage)
|
||||
const jsonData = CSON.readFileSync(path.join(storagePath, 'notes', note.key + '.cson'))
|
||||
return createNoteFromUrl(url, storageKey, folderKey).then(function assert({
|
||||
note
|
||||
}) {
|
||||
t.is(storageKey, note.storage)
|
||||
const jsonData = CSON.readFileSync(
|
||||
path.join(storagePath, 'notes', note.key + '.cson')
|
||||
)
|
||||
|
||||
// Test if saved content is matching the created in memory note
|
||||
t.is(note.content, jsonData.content)
|
||||
t.is(note.tags.length, jsonData.tags.length)
|
||||
})
|
||||
// Test if saved content is matching the created in memory note
|
||||
t.is(note.content, jsonData.content)
|
||||
t.is(note.tags.length, jsonData.tags.length)
|
||||
})
|
||||
})
|
||||
|
||||
test.after(function after () {
|
||||
test.after(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
|
||||
@@ -7,21 +7,21 @@ const path = require('path')
|
||||
const snippetFilePath = path.join(os.tmpdir(), 'test', 'create-snippet')
|
||||
const snippetFile = path.join(snippetFilePath, 'snippets.json')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
test.beforeEach(t => {
|
||||
sander.writeFileSync(snippetFile, '[]')
|
||||
})
|
||||
|
||||
test.serial('Create a snippet', (t) => {
|
||||
test.serial('Create a snippet', t => {
|
||||
return Promise.resolve()
|
||||
.then(function doTest () {
|
||||
return Promise.all([
|
||||
createSnippet(snippetFile)
|
||||
])
|
||||
.then(function doTest() {
|
||||
return Promise.all([createSnippet(snippetFile)])
|
||||
})
|
||||
.then(function assert (data) {
|
||||
.then(function assert(data) {
|
||||
data = data[0]
|
||||
const snippets = JSON.parse(sander.readFileSync(snippetFile))
|
||||
const snippet = snippets.find(currentSnippet => currentSnippet.id === data.id)
|
||||
const snippet = snippets.find(
|
||||
currentSnippet => currentSnippet.id === data.id
|
||||
)
|
||||
t.not(snippet, undefined)
|
||||
t.is(snippet.name, data.name)
|
||||
t.deepEqual(snippet.prefix, data.prefix)
|
||||
|
||||
@@ -10,7 +10,10 @@ global.window = document.defaultView
|
||||
global.navigator = window.navigator
|
||||
|
||||
const Storage = require('dom-storage')
|
||||
const localStorage = window.localStorage = global.localStorage = new Storage(null, { strict: true })
|
||||
const localStorage = (window.localStorage = global.localStorage = new Storage(
|
||||
null,
|
||||
{ strict: true }
|
||||
))
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
const TestDummy = require('../fixtures/TestDummy')
|
||||
@@ -20,12 +23,12 @@ const CSON = require('@rokt33r/season')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/delete-folder')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
test.beforeEach(t => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
test.serial('Delete a folder', (t) => {
|
||||
test.serial('Delete a folder', t => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const folderKey = t.context.storage.json.folders[0].key
|
||||
let noteKey
|
||||
@@ -33,44 +36,64 @@ test.serial('Delete a folder', (t) => {
|
||||
const input1 = {
|
||||
type: 'SNIPPET_NOTE',
|
||||
description: faker.lorem.lines(),
|
||||
snippets: [{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
}],
|
||||
snippets: [
|
||||
{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
}
|
||||
],
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
}
|
||||
input1.title = input1.description.split('\n').shift()
|
||||
|
||||
return Promise.resolve()
|
||||
.then(function prepare () {
|
||||
return createNote(storageKey, input1)
|
||||
.then(function createAttachmentFolder (data) {
|
||||
fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER))
|
||||
fs.mkdirSync(path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, data.key))
|
||||
.then(function prepare() {
|
||||
return createNote(storageKey, input1).then(
|
||||
function createAttachmentFolder(data) {
|
||||
fs.mkdirSync(
|
||||
path.join(storagePath, attachmentManagement.DESTINATION_FOLDER)
|
||||
)
|
||||
fs.mkdirSync(
|
||||
path.join(
|
||||
storagePath,
|
||||
attachmentManagement.DESTINATION_FOLDER,
|
||||
data.key
|
||||
)
|
||||
)
|
||||
noteKey = data.key
|
||||
|
||||
return data
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
.then(function doTest () {
|
||||
.then(function doTest() {
|
||||
return deleteFolder(storageKey, folderKey)
|
||||
})
|
||||
.then(function assert (data) {
|
||||
t.true(_.find(data.storage.folders, {key: folderKey}) == null)
|
||||
const jsonData = CSON.readFileSync(path.join(data.storage.path, 'boostnote.json'))
|
||||
.then(function assert(data) {
|
||||
t.true(_.find(data.storage.folders, { key: folderKey }) == null)
|
||||
const jsonData = CSON.readFileSync(
|
||||
path.join(data.storage.path, 'boostnote.json')
|
||||
)
|
||||
|
||||
t.true(_.find(jsonData.folders, {key: folderKey}) == null)
|
||||
t.true(_.find(jsonData.folders, { key: folderKey }) == null)
|
||||
const notePaths = sander.readdirSync(data.storage.path, 'notes')
|
||||
t.is(notePaths.length, t.context.storage.notes.filter((note) => note.folder !== folderKey).length)
|
||||
t.is(
|
||||
notePaths.length,
|
||||
t.context.storage.notes.filter(note => note.folder !== folderKey).length
|
||||
)
|
||||
|
||||
const attachmentFolderPath = path.join(storagePath, attachmentManagement.DESTINATION_FOLDER, noteKey)
|
||||
const attachmentFolderPath = path.join(
|
||||
storagePath,
|
||||
attachmentManagement.DESTINATION_FOLDER,
|
||||
noteKey
|
||||
)
|
||||
t.false(fs.existsSync(attachmentFolderPath))
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(function after () {
|
||||
test.after.always(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
|
||||
@@ -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,24 +40,26 @@ test.serial('Export a folder', (t) => {
|
||||
const input2 = {
|
||||
type: 'SNIPPET_NOTE',
|
||||
description: 'Some normal text',
|
||||
snippets: [{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
}],
|
||||
snippets: [
|
||||
{
|
||||
name: faker.system.fileName(),
|
||||
mode: 'text',
|
||||
content: faker.lorem.lines()
|
||||
}
|
||||
],
|
||||
tags: faker.lorem.words().split(' '),
|
||||
folder: folderKey
|
||||
}
|
||||
input2.title = 'input2'
|
||||
|
||||
return createNote(storageKey, input1)
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
return createNote(storageKey, input2)
|
||||
})
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
return exportFolder(storageKey, folderKey, 'md', storagePath)
|
||||
})
|
||||
.then(function assert () {
|
||||
.then(function assert() {
|
||||
let filePath = path.join(storagePath, 'input1.md')
|
||||
t.true(fs.existsSync(filePath))
|
||||
filePath = path.join(storagePath, 'input2.md')
|
||||
@@ -62,7 +67,7 @@ test.serial('Export a folder', (t) => {
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(function after () {
|
||||
test.after.always(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
|
||||
@@ -6,7 +6,10 @@ global.window = document.defaultView
|
||||
global.navigator = window.navigator
|
||||
|
||||
const Storage = require('dom-storage')
|
||||
const localStorage = window.localStorage = global.localStorage = new Storage(null, { strict: true })
|
||||
const localStorage = (window.localStorage = global.localStorage = new Storage(
|
||||
null,
|
||||
{ strict: true }
|
||||
))
|
||||
const path = require('path')
|
||||
const TestDummy = require('../fixtures/TestDummy')
|
||||
const os = require('os')
|
||||
@@ -17,7 +20,9 @@ test.beforeEach(t => {
|
||||
t.context.storageDir = path.join(os.tmpdir(), 'test/export-storage')
|
||||
t.context.storage = TestDummy.dummyStorage(t.context.storageDir)
|
||||
t.context.exportDir = path.join(os.tmpdir(), 'test/export-storage-output')
|
||||
try { fs.mkdirSync(t.context.exportDir) } catch (e) {}
|
||||
try {
|
||||
fs.mkdirSync(t.context.exportDir)
|
||||
} catch (e) {}
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
|
||||
@@ -26,23 +31,25 @@ test.serial('Export a storage', t => {
|
||||
const folders = t.context.storage.json.folders
|
||||
const notes = t.context.storage.notes
|
||||
const exportDir = t.context.exportDir
|
||||
const folderKeyToName = folders.reduce(
|
||||
(acc, folder) => {
|
||||
acc[folder.key] = folder.name
|
||||
return acc
|
||||
}, {})
|
||||
return exportStorage(storageKey, 'md', exportDir)
|
||||
.then(() => {
|
||||
notes.forEach(note => {
|
||||
const noteDir = path.join(exportDir, folderKeyToName[note.folder], `${note.title}.md`)
|
||||
if (note.type === 'MARKDOWN_NOTE') {
|
||||
t.true(fs.existsSync(noteDir))
|
||||
t.is(fs.readFileSync(noteDir, 'utf8'), note.content)
|
||||
} else if (note.type === 'SNIPPET_NOTE') {
|
||||
t.false(fs.existsSync(noteDir))
|
||||
}
|
||||
})
|
||||
const folderKeyToName = folders.reduce((acc, folder) => {
|
||||
acc[folder.key] = folder.name
|
||||
return acc
|
||||
}, {})
|
||||
return exportStorage(storageKey, 'md', exportDir).then(() => {
|
||||
notes.forEach(note => {
|
||||
const noteDir = path.join(
|
||||
exportDir,
|
||||
folderKeyToName[note.folder],
|
||||
`${note.title}.md`
|
||||
)
|
||||
if (note.type === 'MARKDOWN_NOTE') {
|
||||
t.true(fs.existsSync(noteDir))
|
||||
t.is(fs.readFileSync(noteDir, 'utf8'), note.content)
|
||||
} else if (note.type === 'SNIPPET_NOTE') {
|
||||
t.false(fs.existsSync(noteDir))
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test.afterEach.always(t => {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 '{}'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
global.Raphael = {
|
||||
setWindow: jest.fn(),
|
||||
registerFont: jest.fn(),
|
||||
fn: function () {
|
||||
fn: function() {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +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
|
||||
const buildEditorContextMenu = require('browser/lib/contextMenuBuilder')
|
||||
.buildEditorContextMenu
|
||||
const buildMarkdownPreviewContextMenu = require('browser/lib/contextMenuBuilder')
|
||||
.buildMarkdownPreviewContextMenu
|
||||
|
||||
beforeEach(() => {
|
||||
menuBuilderParameter = null
|
||||
})
|
||||
|
||||
// Editor Context Menu
|
||||
it('should make sure that no context menu is build if the passed editor instance was null', function () {
|
||||
it('should make sure that no context menu is build if the passed editor instance was null', function() {
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
@@ -21,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(() => [])
|
||||
|
||||
@@ -128,7 +149,7 @@ it('should make sure that word suggestions creates a correct menu if there was a
|
||||
})
|
||||
|
||||
// Markdown Preview Context Menu
|
||||
it('should make sure that no context menu is built if the Markdown Preview instance was null', function () {
|
||||
it('should make sure that no context menu is built if the Markdown Preview instance was null', function() {
|
||||
const event = {
|
||||
pageX: 12,
|
||||
pageY: 12
|
||||
|
||||
@@ -6,14 +6,17 @@ 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) => {
|
||||
test.beforeEach(t => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
})
|
||||
@@ -26,7 +29,7 @@ test('findStorage() should return a correct storage path(string)', t => {
|
||||
t.is(findStorage(storageKey).path, storagePath)
|
||||
})
|
||||
|
||||
test.after(function after () {
|
||||
test.after(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
|
||||
@@ -20,7 +20,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}`)
|
||||
t.is(
|
||||
findNoteTitle(input, false),
|
||||
expected,
|
||||
`Test for find() input: ${input} expected: ${expected}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -34,21 +38,32 @@ 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}`)
|
||||
t.is(
|
||||
findNoteTitle(input, false),
|
||||
expected,
|
||||
`Test for find() input: ${input} expected: ${expected}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
test('findNoteTitle#find should respect front matter when enableFrontMatterTitle=true', t => {
|
||||
// [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}`)
|
||||
t.is(
|
||||
findNoteTitle(input, true),
|
||||
expected,
|
||||
`Test for find() input: ${input} expected: ${expected}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -61,6 +76,10 @@ 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}`)
|
||||
t.is(
|
||||
findNoteTitle(input, true, 'custom'),
|
||||
expected,
|
||||
`Test for find() input: ${input} expected: ${expected}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -40,8 +40,15 @@ test('getTodoStatus should return a correct hash object', t => {
|
||||
|
||||
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}`)
|
||||
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}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -9,16 +9,23 @@ 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\';'],
|
||||
['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\\$\'']
|
||||
['a$'', "a\\$'"]
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
t.is(htmlTextHelper.decodeEntities(input), expected, `Test for decodeEntities() input: ${input} expected: ${expected}`)
|
||||
t.is(
|
||||
htmlTextHelper.decodeEntities(input),
|
||||
expected,
|
||||
`Test for decodeEntities() input: ${input} expected: ${expected}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -26,29 +33,40 @@ 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$'']
|
||||
["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}`)
|
||||
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\' />'
|
||||
"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()')
|
||||
t.is(
|
||||
decodedText,
|
||||
testCase,
|
||||
'Integration test through encodedText() and decodedText()'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -42,6 +42,10 @@ test(t => {
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
t.is(markdown.strip(input), expected, `Test for strip() input: ${input} expected: ${expected}`)
|
||||
t.is(
|
||||
markdown.strip(input),
|
||||
expected,
|
||||
`Test for strip() input: ${input} expected: ${expected}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -261,7 +261,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}`)
|
||||
t.is(
|
||||
generatedToc,
|
||||
expectedToc,
|
||||
`generate test : ${title} , generated : ${EOL}${generatedToc}, expected : ${EOL}${expectedToc}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -279,7 +283,7 @@ test(t => {
|
||||
const testCases = [
|
||||
[
|
||||
`***************************** Empty note, cursor at the top`,
|
||||
{line: 0, ch: 0},
|
||||
{ line: 0, ch: 0 },
|
||||
``,
|
||||
`
|
||||
<!-- toc -->
|
||||
@@ -291,7 +295,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 +333,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 +377,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 +420,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 +465,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 +515,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 +565,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 +606,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 +667,10 @@ 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}`)
|
||||
t.is(
|
||||
expectedMd,
|
||||
editor.getValue(),
|
||||
`generateInEditor test : ${title} , generated : ${EOL}${editor.getValue()}, expected : ${EOL}${expectedMd}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -12,5 +12,8 @@ test('normalizeEditorFontFamily() should return default font family (string[])',
|
||||
|
||||
test('normalizeEditorFontFamily(["hoge", "huga"]) should return default font family connected with arg.', t => {
|
||||
const arg = 'font1, font2'
|
||||
t.is(normalizeEditorFontFamily(arg), `${arg}, ${defaultEditorFontFamily.join(', ')}`)
|
||||
t.is(
|
||||
normalizeEditorFontFamily(arg),
|
||||
`${arg}, ${defaultEditorFontFamily.join(', ')}`
|
||||
)
|
||||
})
|
||||
|
||||
@@ -4,8 +4,42 @@ 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 }
|
||||
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 = [
|
||||
@@ -13,21 +47,27 @@ test('RcParser should return a json object', t => {
|
||||
['.boostnoterc.all', allJson]
|
||||
]
|
||||
|
||||
const invalidTestCases = [
|
||||
['.boostnoterc.invalid', {}]
|
||||
]
|
||||
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}`)
|
||||
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}`)
|
||||
t.is(
|
||||
parse(filePath(input)).editor,
|
||||
expected.editor,
|
||||
`Test for getTodoStatus() input: ${input} expected: ${expected.editor}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
function filePath (filename) {
|
||||
function filePath(filename) {
|
||||
return path.join(`${__dirname}/boostnoterc`, filename)
|
||||
}
|
||||
|
||||
@@ -3,14 +3,21 @@ 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 => {
|
||||
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)
|
||||
@@ -34,12 +41,12 @@ 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()))
|
||||
|
||||
@@ -13,7 +13,7 @@ test('alphabet and digit', t => {
|
||||
|
||||
test('should delete unavailable symbols', t => {
|
||||
const availableSymbols = '_-'
|
||||
const testCase = availableSymbols + '][!\'#$%&()*+,./:;<=>?@\\^{|}~`'
|
||||
const testCase = availableSymbols + "][!'#$%&()*+,./:;<=>?@\\^{|}~`"
|
||||
const decodeSlug = decodeURI(slugify(testCase))
|
||||
|
||||
t.true(decodeSlug === availableSymbols)
|
||||
|
||||
@@ -87,7 +87,7 @@ Generated by [AVA](https://ava.li).
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`<p data-line="1"><ul class="markdownIt-TOC">␊
|
||||
`<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>␊
|
||||
@@ -98,7 +98,7 @@ Generated by [AVA](https://ava.li).
|
||||
</ul>␊
|
||||
</li>␊
|
||||
</ul>␊
|
||||
</p>␊
|
||||
</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>␊
|
||||
@@ -226,39 +226,4 @@ Generated by [AVA](https://ava.li).
|
||||
> Snapshot 2
|
||||
|
||||
`<p data-line="0">This is a "QUOTE".</p>␊
|
||||
|
||||
|
||||
## 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" />␊
|
||||
`
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user