mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Add tests for searchFromeNotes()
This commit is contained in:
3
tests/fixtures/TestDummy.js
vendored
3
tests/fixtures/TestDummy.js
vendored
@@ -175,5 +175,6 @@ module.exports = {
|
||||
dummyFolder,
|
||||
dummyBoostnoteJSONData,
|
||||
dummyStorage,
|
||||
dummyLegacyStorage
|
||||
dummyLegacyStorage,
|
||||
dummyNote
|
||||
}
|
||||
|
||||
36
tests/lib/search-test.js
Normal file
36
tests/lib/search-test.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import test from 'ava'
|
||||
import searchFromNotes from 'browser/lib/search'
|
||||
import { dummyNote } from '../fixtures/TestDummy'
|
||||
import _ from 'lodash'
|
||||
|
||||
const pickContents = (notes) => notes.map((note) => { return note.content } )
|
||||
|
||||
let noteList = { noteMap: [] }
|
||||
let note1, note2
|
||||
|
||||
test.before(t => {
|
||||
const data1 = { type: 'MARKDOWN_NOTE', content: 'content1', tags: ['tag1'], }
|
||||
const data2 = { type: 'MARKDOWN_NOTE', content: 'content1\ncontent2', tags: ['tag1', 'tag2'], }
|
||||
note1 = dummyNote(data1)
|
||||
note2 = dummyNote(data2)
|
||||
|
||||
noteList.noteMap = [note1, note2]
|
||||
})
|
||||
|
||||
test('it can find notes by tags or words', t => {
|
||||
// [input, expected content (Array)]
|
||||
const testCases= [
|
||||
['#tag1', [note1.content, note2.content]],
|
||||
['#tag1 #tag2', [note2.content]],
|
||||
['#tag1 #tag2 #tag3', []],
|
||||
['content1', [note1.content, note2.content]],
|
||||
['content1 content2', [note2.content]],
|
||||
['content1 content2 content3', []]
|
||||
]
|
||||
|
||||
testCases.forEach((testCase) => {
|
||||
const [input, expectedContents] = testCase
|
||||
const results = searchFromNotes(noteList, input)
|
||||
t.true(_.isEqual(pickContents(results).sort(), expectedContents.sort()))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user