mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
migrate more tests to jest
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
const test = require('ava')
|
||||
const copyFile = require('browser/main/lib/dataApi/copyFile')
|
||||
|
||||
const path = require('path')
|
||||
@@ -13,23 +12,25 @@ const srcPath = path.join(srcFolder, testFile)
|
||||
const dstFolder = path.join(__dirname, '😇')
|
||||
const dstPath = path.join(dstFolder, testFile)
|
||||
|
||||
test.before(t => {
|
||||
beforeAll(() => {
|
||||
if (!fs.existsSync(srcFolder)) fs.mkdirSync(srcFolder)
|
||||
|
||||
fs.writeFileSync(srcPath, 'test')
|
||||
})
|
||||
|
||||
test('`copyFile` should handle encoded URI on src path', t => {
|
||||
it('`copyFile` should handle encoded URI on src path', done => {
|
||||
return copyFile(encodeURI(srcPath), dstPath)
|
||||
.then(() => {
|
||||
t.true(true)
|
||||
expect(true).toBe(true)
|
||||
done()
|
||||
})
|
||||
.catch(() => {
|
||||
t.true(false)
|
||||
expect(false).toBe(true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
test.after(t => {
|
||||
afterAll(() => {
|
||||
fs.unlinkSync(srcPath)
|
||||
fs.unlinkSync(dstPath)
|
||||
execSync(removeDirCommand + '"' + srcFolder + '"')
|
||||
@@ -1,4 +1,3 @@
|
||||
const test = require('ava')
|
||||
const createFolder = require('browser/main/lib/dataApi/createFolder')
|
||||
|
||||
global.document = require('jsdom').jsdom('<body></body>')
|
||||
@@ -19,32 +18,34 @@ const CSON = require('@rokt33r/season')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/create-folder')
|
||||
|
||||
test.beforeEach(t => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
let storageContext
|
||||
|
||||
beforeAll(() => {
|
||||
storageContext = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([storageContext.cache]))
|
||||
})
|
||||
|
||||
test.serial('Create a folder', t => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
it('Create a folder', done => {
|
||||
const storageKey = storageContext.cache.key
|
||||
const input = {
|
||||
name: 'created',
|
||||
color: '#ff5555'
|
||||
}
|
||||
return Promise.resolve()
|
||||
.then(function doTest() {
|
||||
.then(() => {
|
||||
return createFolder(storageKey, input)
|
||||
})
|
||||
.then(function assert(data) {
|
||||
t.true(_.find(data.storage.folders, input) != null)
|
||||
.then(data => {
|
||||
expect(_.find(data.storage.folders, input)).not.toBeNull()
|
||||
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)
|
||||
expect(_.find(jsonData.folders, input)).not.toBeNull()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
test.after(function after() {
|
||||
afterAll(() => {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
@@ -1,4 +1,3 @@
|
||||
const test = require('ava')
|
||||
const createNote = require('browser/main/lib/dataApi/createNote')
|
||||
|
||||
global.document = require('jsdom').jsdom('<body></body>')
|
||||
@@ -19,14 +18,16 @@ const faker = require('faker')
|
||||
|
||||
const storagePath = path.join(os.tmpdir(), 'test/create-note')
|
||||
|
||||
test.beforeEach(t => {
|
||||
t.context.storage = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([t.context.storage.cache]))
|
||||
let storageContext
|
||||
|
||||
beforeEach(() => {
|
||||
storageContext = TestDummy.dummyStorage(storagePath)
|
||||
localStorage.setItem('storages', JSON.stringify([storageContext.cache]))
|
||||
})
|
||||
|
||||
test.serial('Create a note', t => {
|
||||
const storageKey = t.context.storage.cache.key
|
||||
const folderKey = t.context.storage.json.folders[0].key
|
||||
it('Create a note', done => {
|
||||
const storageKey = storageContext.cache.key
|
||||
const folderKey = storageContext.json.folders[0].key
|
||||
|
||||
const randLinesHighlightedArray = new Array(10)
|
||||
.fill()
|
||||
@@ -58,58 +59,58 @@ test.serial('Create a note', t => {
|
||||
input2.title = input2.content.split('\n').shift()
|
||||
|
||||
return Promise.resolve()
|
||||
.then(function doTest() {
|
||||
.then(() => {
|
||||
return Promise.all([
|
||||
createNote(storageKey, input1),
|
||||
createNote(storageKey, input2)
|
||||
])
|
||||
})
|
||||
.then(function assert(data) {
|
||||
.then(data => {
|
||||
const data1 = data[0]
|
||||
const data2 = data[1]
|
||||
|
||||
t.is(storageKey, data1.storage)
|
||||
expect(storageKey).toEqual(data1.storage)
|
||||
const jsonData1 = CSON.readFileSync(
|
||||
path.join(storagePath, 'notes', data1.key + '.cson')
|
||||
)
|
||||
|
||||
t.is(input1.title, data1.title)
|
||||
t.is(input1.title, jsonData1.title)
|
||||
t.is(input1.description, data1.description)
|
||||
t.is(input1.description, jsonData1.description)
|
||||
t.is(input1.tags.length, data1.tags.length)
|
||||
t.is(input1.tags.length, jsonData1.tags.length)
|
||||
t.is(input1.snippets.length, data1.snippets.length)
|
||||
t.is(input1.snippets.length, jsonData1.snippets.length)
|
||||
t.is(input1.snippets[0].content, data1.snippets[0].content)
|
||||
t.is(input1.snippets[0].content, jsonData1.snippets[0].content)
|
||||
t.is(input1.snippets[0].name, data1.snippets[0].name)
|
||||
t.is(input1.snippets[0].name, jsonData1.snippets[0].name)
|
||||
t.deepEqual(
|
||||
input1.snippets[0].linesHighlighted,
|
||||
expect(input1.title).toEqual(data1.title)
|
||||
expect(input1.title).toEqual(jsonData1.title)
|
||||
expect(input1.description).toEqual(data1.description)
|
||||
expect(input1.description).toEqual(jsonData1.description)
|
||||
expect(input1.tags.length).toEqual(data1.tags.length)
|
||||
expect(input1.tags.length).toEqual(jsonData1.tags.length)
|
||||
expect(input1.snippets.length).toEqual(data1.snippets.length)
|
||||
expect(input1.snippets.length).toEqual(jsonData1.snippets.length)
|
||||
expect(input1.snippets[0].content).toEqual(data1.snippets[0].content)
|
||||
expect(input1.snippets[0].content).toEqual(jsonData1.snippets[0].content)
|
||||
expect(input1.snippets[0].name).toEqual(data1.snippets[0].name)
|
||||
expect(input1.snippets[0].name).toEqual(jsonData1.snippets[0].name)
|
||||
expect(input1.snippets[0].linesHighlighted).toEqual(
|
||||
data1.snippets[0].linesHighlighted
|
||||
)
|
||||
t.deepEqual(
|
||||
input1.snippets[0].linesHighlighted,
|
||||
expect(input1.snippets[0].linesHighlighted).toEqual(
|
||||
jsonData1.snippets[0].linesHighlighted
|
||||
)
|
||||
|
||||
t.is(storageKey, data2.storage)
|
||||
expect(storageKey).toEqual(data2.storage)
|
||||
const jsonData2 = CSON.readFileSync(
|
||||
path.join(storagePath, 'notes', data2.key + '.cson')
|
||||
)
|
||||
t.is(input2.title, data2.title)
|
||||
t.is(input2.title, jsonData2.title)
|
||||
t.is(input2.content, data2.content)
|
||||
t.is(input2.content, jsonData2.content)
|
||||
t.is(input2.tags.length, data2.tags.length)
|
||||
t.is(input2.tags.length, jsonData2.tags.length)
|
||||
t.deepEqual(input2.linesHighlighted, data2.linesHighlighted)
|
||||
t.deepEqual(input2.linesHighlighted, jsonData2.linesHighlighted)
|
||||
expect(input2.title).toEqual(data2.title)
|
||||
expect(input2.title).toEqual(jsonData2.title)
|
||||
expect(input2.content).toEqual(data2.content)
|
||||
expect(input2.content).toEqual(jsonData2.content)
|
||||
expect(input2.tags.length).toEqual(data2.tags.length)
|
||||
expect(input2.tags.length).toEqual(jsonData2.tags.length)
|
||||
expect(input2.linesHighlighted).toEqual(data2.linesHighlighted)
|
||||
expect(input2.linesHighlighted).toEqual(jsonData2.linesHighlighted)
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
test.after(function after() {
|
||||
afterAll(function after() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(storagePath)
|
||||
})
|
||||
Reference in New Issue
Block a user