Files
NodeBB/test/search-admin.js

88 lines
2.3 KiB
JavaScript
Raw Normal View History

'use strict';
2021-02-04 00:06:15 -07:00
const assert = require('assert');
const search = require('../src/admin/search');
2021-02-04 00:01:39 -07:00
describe('admin search', () => {
describe('filterDirectories', () => {
it('should resolve all paths to relative paths', (done) => {
2017-02-18 02:38:03 -07:00
assert.deepEqual(search.filterDirectories([
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
]), [
'admin/gdhgfsdg/sggag',
]);
done();
});
2021-02-04 00:01:39 -07:00
it('should exclude .js files', (done) => {
assert.deepEqual(search.filterDirectories([
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
2017-09-23 12:51:20 -06:00
'dfahdfsgf/admin/hgkfds/fdhsdfh.js',
]), [
'admin/gdhgfsdg/sggag',
]);
done();
});
2021-02-04 00:01:39 -07:00
it('should exclude partials', (done) => {
2017-02-18 02:38:03 -07:00
assert.deepEqual(search.filterDirectories([
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
'dfahdfsgf/admin/partials/hgkfds/fdhsdfh.tpl',
]), [
'admin/gdhgfsdg/sggag',
]);
done();
});
2021-02-04 00:01:39 -07:00
it('should exclude files in the admin directory', (done) => {
2017-02-18 02:38:03 -07:00
assert.deepEqual(search.filterDirectories([
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
'dfdasg/admin/hjkdfsk.tpl',
]), [
'admin/gdhgfsdg/sggag',
]);
done();
});
});
2021-02-04 00:01:39 -07:00
describe('sanitize', () => {
it('should strip out scripts', (done) => {
2017-02-18 02:38:03 -07:00
assert.equal(
search.sanitize('Pellentesque tristique senectus' +
'<script>alert("nope");</script> habitant morbi'),
'Pellentesque tristique senectus' +
' habitant morbi'
);
2017-02-18 02:38:03 -07:00
done();
});
2021-02-04 00:01:39 -07:00
it('should remove all tags', (done) => {
2017-02-18 02:38:03 -07:00
assert.equal(
search.sanitize('<p>Pellentesque <b>habitant morbi</b> tristique senectus' +
'Aenean <i>vitae</i> est.Mauris <a href="placerat">eleifend</a> leo.</p>'),
'Pellentesque habitant morbi tristique senectus' +
'Aenean vitae est.Mauris eleifend leo.'
);
2017-02-18 02:38:03 -07:00
done();
});
});
2021-02-04 00:01:39 -07:00
describe('simplify', () => {
it('should remove all mustaches', (done) => {
2017-02-18 02:38:03 -07:00
assert.equal(
search.simplify('Pellentesque tristique {{senectus}}habitant morbi' +
'liquam tincidunt {mauris.eu}risus'),
'Pellentesque tristique habitant morbi' +
'liquam tincidunt risus'
);
2017-02-18 02:38:03 -07:00
done();
});
2021-02-04 00:01:39 -07:00
it('should collapse all whitespace', (done) => {
2017-02-18 02:38:03 -07:00
assert.equal(
search.simplify('Pellentesque tristique habitant morbi' +
' \n\n liquam tincidunt mauris eu risus.'),
'Pellentesque tristique habitant morbi' +
'\nliquam tincidunt mauris eu risus.'
);
2017-02-18 02:38:03 -07:00
done();
});
});
2017-02-18 02:30:48 -07:00
});