Add shell plugin model tests
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||
|
||||
run_node_test <<'JS'
|
||||
const fs = require('fs')
|
||||
const emojis = requireFromRoot('shell/plugins/emojis/EmojiSearch.js')
|
||||
|
||||
const raw = fs.readFileSync(path.join(root, 'shell/plugins/emojis/emojis.json'), 'utf8')
|
||||
const data = emojis.parseEmojis(raw)
|
||||
|
||||
assert(data.length > 1000, 'emoji dataset parses')
|
||||
assertDeepEqual(emojis.parseEmojis('{'), [], 'invalid emoji JSON parses as empty list')
|
||||
assertDeepEqual(emojis.parseEmojis('{"e":"nope"}'), [], 'non-array emoji JSON parses as empty list')
|
||||
|
||||
const fixture = [
|
||||
{ e: 'a', k: 'grinning face smile happy' },
|
||||
{ e: 'b', k: 'face with tears of joy joy tears' },
|
||||
{ e: 'c', k: 'flag: united states us america' }
|
||||
]
|
||||
|
||||
assertDeepEqual(
|
||||
emojis.filterEmojis(fixture, ' JOY ').map(item => item.e),
|
||||
['b'],
|
||||
'emoji filtering trims and lowercases query'
|
||||
)
|
||||
|
||||
assertDeepEqual(
|
||||
emojis.filterEmojis(fixture, '', 2).map(item => item.e),
|
||||
['a', 'b'],
|
||||
'emoji filtering honors result limit'
|
||||
)
|
||||
|
||||
assertDeepEqual(
|
||||
emojis.filterEmojis(fixture, '', 0),
|
||||
[],
|
||||
'emoji filtering supports zero result limit'
|
||||
)
|
||||
|
||||
assertEqual(
|
||||
emojis.filterEmojis(data, 'face with tears')[0].e,
|
||||
'\u{1F602}',
|
||||
'emoji filtering finds face with tears of joy'
|
||||
)
|
||||
JS
|
||||
Reference in New Issue
Block a user