2016-11-28 12:59:41 -07:00
|
|
|
'use strict';
|
2017-02-17 21:55:19 -07:00
|
|
|
|
2016-11-28 12:59:41 -07:00
|
|
|
|
2021-02-04 00:06:15 -07:00
|
|
|
const assert = require('assert');
|
|
|
|
|
const search = require('../src/admin/search');
|
2016-11-28 12:59:41 -07:00
|
|
|
|
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) => {
|
2017-08-24 17:26:50 -06:00
|
|
|
assert.deepEqual(search.filterDirectories([
|
|
|
|
|
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
|
2017-09-23 12:51:20 -06:00
|
|
|
'dfahdfsgf/admin/hgkfds/fdhsdfh.js',
|
2017-08-24 17:26:50 -06:00
|
|
|
]), [
|
|
|
|
|
'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();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-11-28 12:59:41 -07:00
|
|
|
|
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(
|
2018-11-28 20:29:43 -07:00
|
|
|
search.sanitize('Pellentesque tristique senectus' +
|
|
|
|
|
'<script>alert("nope");</script> habitant morbi'),
|
|
|
|
|
'Pellentesque tristique senectus' +
|
|
|
|
|
' habitant morbi'
|
2017-10-01 16:19:10 -06:00
|
|
|
);
|
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(
|
2018-11-28 20:29:43 -07:00
|
|
|
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-10-01 16:19:10 -06:00
|
|
|
);
|
2017-02-18 02:38:03 -07:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-11-28 12:59:41 -07:00
|
|
|
|
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(
|
2018-11-28 20:29:43 -07:00
|
|
|
search.simplify('Pellentesque tristique {{senectus}}habitant morbi' +
|
|
|
|
|
'liquam tincidunt {mauris.eu}risus'),
|
|
|
|
|
'Pellentesque tristique habitant morbi' +
|
|
|
|
|
'liquam tincidunt risus'
|
2017-10-01 16:19:10 -06:00
|
|
|
);
|
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(
|
2018-11-28 20:29:43 -07:00
|
|
|
search.simplify('Pellentesque tristique habitant morbi' +
|
|
|
|
|
' \n\n liquam tincidunt mauris eu risus.'),
|
|
|
|
|
'Pellentesque tristique habitant morbi' +
|
|
|
|
|
'\nliquam tincidunt mauris eu risus.'
|
2017-10-01 16:19:10 -06:00
|
|
|
);
|
2017-02-18 02:38:03 -07:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-02-18 02:30:48 -07:00
|
|
|
});
|