Commit fb5996e6 authored by Nacim Goura's avatar Nacim Goura

add test for search

parent 62b80078
{ {
"env": { "env": {
"meteor": true, "meteor": true,
"node": true, "node": true,
"browser": true, "browser": true,
"mocha": true, "mocha": true,
"es6": true "es6": true
}, },
"parser": "babel-eslint", "parser": "babel-eslint",
"parserOptions": { "parserOptions": {
"allowImportExportEverywhere": true, "allowImportExportEverywhere": true,
"ecmaVersion": 6, "ecmaVersion": 6,
"ecmaFeatures": { "ecmaFeatures": {
"jsx": false, "jsx": false,
"experimentalObjectRestSpread": true "experimentalObjectRestSpread": true
} }
}, },
"plugins": [ "plugins": [
"meteor", "meteor",
"promise", "promise"
"lodash" ],
], "extends": [
"extends": [
"@meteorjs/eslint-config-meteor", "@meteorjs/eslint-config-meteor",
"plugin:meteor/recommended", "plugin:meteor/recommended",
"airbnb", "airbnb"
"plugin:lodash/recommended" ],
], "settings": {
"settings": { "import/resolver": "meteor"
"import/resolver": "meteor" },
}, "rules": {
"rules": {
"indent": ["error", 4, { "SwitchCase": 1 }], "indent": ["error", 4, { "SwitchCase": 1 }],
"import/extensions": ["off", "never"], "import/extensions": ["off", "never"],
"import/no-extraneous-dependencies": "off", "import/no-extraneous-dependencies": "off",
"no-underscore-dangle": "off", "no-underscore-dangle": "off",
"class-methods-use-this": "off" "class-methods-use-this": "off"
} }
} }
...@@ -60,7 +60,7 @@ export default class IndexGeneric { ...@@ -60,7 +60,7 @@ export default class IndexGeneric {
query: term, query: term,
fuzziness: 'AUTO', fuzziness: 'AUTO',
fields: [ fields: [
'title.stemmed', 'description',
'description.stemmed', 'description.stemmed',
'body', 'body',
'body.stemmed', 'body.stemmed',
...@@ -76,7 +76,7 @@ export default class IndexGeneric { ...@@ -76,7 +76,7 @@ export default class IndexGeneric {
fuzziness: 'AUTO', fuzziness: 'AUTO',
fields: [ fields: [
'title', 'title',
'description', 'title.stemmed',
'url', 'url',
'breadcrumb', 'breadcrumb',
'h1', 'h1',
......
...@@ -105,7 +105,7 @@ export default class IndexWebsite extends IndexGeneric { ...@@ -105,7 +105,7 @@ export default class IndexWebsite extends IndexGeneric {
index: { index: {
_index: Meteor.settings.private.elasticsearch.esIndex, _index: Meteor.settings.private.elasticsearch.esIndex,
_type: Meteor.settings.private.elasticsearch.esType, _type: Meteor.settings.private.elasticsearch.esType,
_id: url, _id: decodeURI(url),
}, },
}); });
......
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import _ from 'lodash';
import testSearchCollection from '../../collections/testSearchCollection';
Meteor.methods({
addTest(test) {
check(test, Object);
test.urlExpected = _.replace(test.urlExpected, 'https', 'http');
const results = Meteor.call('searchByTerm', test.term);
_.forEach(results.list, (result, index) => {
if (test.urlExpected === result.url) {
test.urlPosition = index + 1;
}
});
testSearchCollection.insert(test);
},
deleteTest(id) {
check(id, String);
testSearchCollection.remove({ _id: id });
},
});
import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo';
/**
* this local collection keep tracks of all tabs of this application
* @type {Mongo.Collection}
*/
const testSearchCollection = new Mongo.Collection('testSearch');
SimpleSchema.testSearchCollection = new SimpleSchema({
term: {
type: String,
},
urlExpected: {
type: String,
},
urlPosition: {
type: Number,
required: false,
},
createdAt: {
type: Date,
defaultValue: new Date(),
},
});
testSearchCollection.attachSchema(SimpleSchema.testSearchCollection);
export default testSearchCollection;
...@@ -2,4 +2,6 @@ ...@@ -2,4 +2,6 @@
import '../../api/indexation/methods'; import '../../api/indexation/methods';
import '../../api/account/methods'; import '../../api/account/methods';
import '../../api/testSearch/methods';
import '../../tabular/tabularUser'; import '../../tabular/tabularUser';
import '../../tabular/tabularTestSearch';
<template name="accountActionTable"> <template name="accountActionTable">
<button type="button" class="btn btn-xs btn-danger delete-account">Supprimer</button> <button type="button" class="btn btn-xs btn-danger delete-account">Supprimer</button>
</template> </template>
<template name="testSearchActionTable">
<button type="button" class="btn btn-xs btn-danger delete-test-search">Supprimer</button>
</template>
import dataTablesBootstrap from 'datatables.net-bs';
import 'datatables.net-bs/css/dataTables.bootstrap.css';
import './buttonTabular.html';
import './tabularUser';
import './tabularTestSearch';
dataTablesBootstrap(window, $);
import Tabular from 'meteor/aldeed:tabular';
import { Meteor } from 'meteor/meteor';
import testSearchCollection from '../collections/testSearchCollection';
new Tabular.Table({
name: 'testSearch',
collection: testSearchCollection,
columns: [
{
data: 'term', title: 'Terme',
},
{
data: 'urlExpected', title: 'url Attendu',
},
{
data: 'urlPosition', title: 'Position',
},
{
data: 'createdAt', title: 'Date',
},
{
tmpl: Meteor.isClient && Template.testSearchActionTable,
},
],
pageLength: 20,
language: {
sProcessing: 'Traitement en cours...',
sSearch: 'Rechercher&nbsp;:',
sLengthMenu: 'Afficher _MENU_ &eacute;l&eacute;ments',
sInfo: "Affichage de l'&eacute;l&eacute;ment _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
sInfoEmpty: "Affichage de l'&eacute;l&eacute;ment 0 &agrave; 0 sur 0 &eacute;l&eacute;ment",
sInfoFiltered: '(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)',
sInfoPostFix: '',
sLoadingRecords: 'Chargement en cours...',
sZeroRecords: 'Aucun &eacute;l&eacute;ment &agrave; afficher',
sEmptyTable: 'Aucune donn&eacute;e disponible dans le tableau',
oPaginate: {
sFirst: 'Premier',
sPrevious: 'Pr&eacute;c&eacute;dent',
sNext: 'Suivant',
sLast: 'Dernier',
},
oAria: {
sSortAscending: ': activer pour trier la colonne par ordre croissant',
sSortDescending: ': activer pour trier la colonne par ordre d&eacute;croissant',
},
},
});
<template name="testSearchTpl">
<!-- testSearchTpl -->
Tester le système de recherche :
<form class="form-inline" role="form" method="post">
<input class="form-control" name="termTestSearch" type="text" placeholder="terme">
<input class="form-control" name="urlTestSearch" type="url" placeholder="Url attendu">
<input class="btn btn-success" type="submit" value="Tester">
</form>
<div class="panel panel-default wrapper">
<div class="panel-heading text-center">
Résultat des tests
</div>
<div class="panel-body">
{{> tabular table=TabularTables.testSearch class="table table-striped table-bordered table-condensed text-center"}}
</div>
</div>
</template>
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import './testSearch.html';
import '../../../tabular/configClient';
Template.testSearchTpl.events({
'submit form': (event) => {
event.preventDefault();
const test = {
term: event.target.termTestSearch.value,
urlExpected: event.target.urlTestSearch.value,
};
Meteor.callPromise('addTest', test)
.then((results) => {
console.log(results);
}).catch((error) => {
console.log(error);
});
},
});
Template.testSearchActionTable.events({
'click .delete-test-search': function () {
Meteor.callPromise('deleteTest', this._id)
.then((results) => {
console.log(results);
}).catch((error) => {
console.log(error);
});
},
});
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import dataTablesBootstrap from 'datatables.net-bs';
import 'datatables.net-bs/css/dataTables.bootstrap.css';
import displayNotif from '../../../../components/notifs/notifs';
import '../../../../../tabular/buttonTabular.html'; import displayNotif from '../../../../components/notifs/notifs';
import '../../../../../tabular/tabularUser'; import '../../../../../tabular/configClient';
import './list.html'; import './list.html';
dataTablesBootstrap(window, $);
Template.accountActionTable.events({ Template.accountActionTable.events({
'click .delete-account': function () { 'click .delete-account': function () {
Meteor.callPromise('deleteAccount', this._id) Meteor.callPromise('deleteAccount', this._id)
......
...@@ -4,4 +4,6 @@ ...@@ -4,4 +4,6 @@
{{> searchTpl ""}} {{> searchTpl ""}}
{{> testSearchTpl ""}}
</template> </template>
import '../../components/search/search'; import '../../components/search/search';
import '../../components/testSearch/testSearch';
import './home.html'; import './home.html';
{ {
"name": "meteorSearch", "name": "meteorSearch",
"author": "Nacim", "author": "Nacim",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "meteor --settings settings.json", "start": "meteor --settings settings.json",
"test": "meteor test --driver-package practicalmeteor:mocha --port 3001", "test": "meteor test --driver-package practicalmeteor:mocha --port 3001",
"eslint": "eslint .; exit 0" "eslint": "eslint .; exit 0"
}, },
"dependencies": { "dependencies": {
"babel-runtime": "^6.23.0", "babel-runtime": "^6.23.0",
"bcrypt": "^1.0.2", "bcrypt": "^1.0.2",
"bootstrap-sass": "^3.3.7", "bootstrap-sass": "^3.3.7",
"crawler": "^1.0.5", "crawler": "^1.0.5",
"datatables.net-bs": "^1.10.15", "datatables.net-bs": "^1.10.15",
"elasticsearch": "^13.1.0", "elasticsearch": "^13.1.0",
"izitoast": "^1.1.1", "izitoast": "^1.1.1",
"jquery": "^1.11.2", "jquery": "^1.11.2",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"meteor-node-stubs": "~0.2.11", "meteor-node-stubs": "~0.2.11",
"sanitize-html": "^1.14.1", "sanitize-html": "^1.14.1",
"simpl-schema": "^0.3.0", "simpl-schema": "^0.3.0",
"sitemapper": "^2.1.13", "sitemapper": "^2.1.13",
"slug": "^0.9.1", "slug": "^0.9.1",
"sweetalert2": "^6.6.5" "sweetalert2": "^6.6.5"
}, },
"devDependencies": { "devDependencies": {
"@meteorjs/eslint-config-meteor": "^1.0.5", "@meteorjs/eslint-config-meteor": "^1.0.5",
"babel-eslint": "^7.2.3", "babel-eslint": "^7.2.3",
"eslint": "^4.0.0", "eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1", "eslint-config-airbnb": "^15.0.1",
"eslint-import-resolver-meteor": "^0.4.0", "eslint-import-resolver-meteor": "^0.4.0",
"eslint-plugin-import": "^2.3.0", "eslint-plugin-import": "^2.3.0",
"eslint-plugin-jsx-a11y": "^5.0.3", "eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-lodash": "^2.4.2", "eslint-plugin-meteor": "^4.0.1",
"eslint-plugin-meteor": "^4.0.1", "eslint-plugin-promise": "^3.5.0",
"eslint-plugin-promise": "^3.5.0", "eslint-plugin-react": "^7.0.1"
"eslint-plugin-react": "^7.0.1" }
}
} }
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment