1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00
Files
Boostnote/tests/lib/search-test.js
bimlas 5f5a7880a6 Fix tag filtering in search entry
Some issues introduced in #954
(https://github.com/BoostIO/Boostnote/pull/954#issuecomment-336344915):

- search by `#tag1 #tag2` returns the results of only `#tag2`
- search by `#tag1 content` is as same as AND search by `#tag1 content` (and
  `#tag1` is regarded a word, not a tag)
- search by `content #tag1` returns the results of only `#tag1`

This commit fixing these:

- search by `#tag1 #tag2` returns the results of only `#tag2`

  ![screencast](https://i.imgur.com/SjhQIhl.gif)

- search by `#tag1 content` is as same as AND search by `#tag1 content` (and
  `#tag1` is regarded a word, not a tag)

  ![screencast](https://i.imgur.com/G0Tmd8c.gif)

- search by `content #tag1` returns the results of only `#tag1`

  ![screencast](https://i.imgur.com/5MrMbE6.gif)

NOTE: the examples works without `#` character too, because
`findByWord()` checks the tags too.
2018-03-20 09:01:11 +01:00

44 lines
1.4 KiB
JavaScript

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 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 data3 = { type: 'MARKDOWN_NOTE', content: '#content4', tags: ['tag1'] }
note1 = dummyNote(data1)
note2 = dummyNote(data2)
note3 = dummyNote(data3)
notes = [note1, note2, note3]
})
test('it can find notes by tags and words', t => {
// [input, expected content (Array)]
const testCases = [
['#tag1', [note1.content, note2.content, note3.content]],
['#tag1 #tag2', [note2.content]],
['#tag2 #tag1', [note2.content]],
['#tag1 #tag2 #tag3', []],
['content1', [note1.content, note2.content]],
['content1 content2', [note2.content]],
['content1 content2 content3', []],
['#content4', [note3.content]],
['#tag2 content1', [note2.content]],
['content1 #tag2', [note2.content]]
]
testCases.forEach((testCase) => {
const [input, expectedContents] = testCase
const results = searchFromNotes(notes, input)
t.true(_.isEqual(pickContents(results).sort(), expectedContents.sort()))
})
})