@digigov/text-search 1.1.3-rc.16 → 1.2.0-85c27c19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/cjs/hook/index.js +46 -46
  2. package/cjs/hook.js.map +7 -0
  3. package/cjs/index.js +39 -19
  4. package/cjs/index.js.map +7 -0
  5. package/cjs/search/index.js +24 -6
  6. package/cjs/search/index.js.map +7 -0
  7. package/cjs/search/lang/gr/encoder/index.js +35 -23
  8. package/cjs/search/lang/gr/encoder.js.map +7 -0
  9. package/cjs/search/lang/gr/normalization-map/index.js +126 -104
  10. package/cjs/search/lang/gr/normalization-map.js.map +7 -0
  11. package/cjs/search/search-index/index.js +86 -119
  12. package/cjs/search/search-index.js.map +7 -0
  13. package/cjs/search/utils/index.js +47 -63
  14. package/cjs/search/utils.js.map +7 -0
  15. package/cjs/types/index.js +16 -4
  16. package/cjs/types.js.map +7 -0
  17. package/hook/index.js +18 -41
  18. package/hook.js.map +7 -0
  19. package/index.js +7 -3
  20. package/index.js.map +7 -0
  21. package/package.json +3 -3
  22. package/search/index.js +5 -1
  23. package/search/index.js.map +7 -0
  24. package/search/lang/gr/encoder/index.js +13 -19
  25. package/search/lang/gr/encoder.js.map +7 -0
  26. package/search/lang/gr/normalization-map/index.js +104 -100
  27. package/search/lang/gr/normalization-map.js.map +7 -0
  28. package/search/search-index/index.js +59 -110
  29. package/search/search-index.js.map +7 -0
  30. package/search/utils/index.js +25 -58
  31. package/search/utils.js.map +7 -0
  32. package/types/index.js +1 -1
  33. package/types.js.map +7 -0
  34. package/cjs/hook.spec/index.js +0 -481
  35. package/cjs/search/__tests__/utils.spec/index.js +0 -83
  36. package/cjs/test-utils/data.json +0 -552
  37. package/hook.spec/index.js +0 -478
  38. package/hook.spec/package.json +0 -6
  39. package/search/__tests__/utils.spec/index.js +0 -81
  40. package/search/__tests__/utils.spec/package.json +0 -6
  41. package/test-utils/data.json +0 -552
@@ -1,478 +0,0 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
4
- import { act, renderHook } from '@testing-library/react-hooks';
5
- import useSearch from "./hook";
6
- import documents from "./test-utils/data.json";
7
- describe('loading', function () {
8
- it('should start when searching', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
9
- var _renderHook, result;
10
- return _regeneratorRuntime().wrap(function _callee$(_context) {
11
- while (1) switch (_context.prev = _context.next) {
12
- case 0:
13
- _renderHook = renderHook(function () {
14
- return useSearch(documents, 'Anastasia');
15
- }), result = _renderHook.result;
16
- expect(result.current.loading).toBe(false);
17
- act(function () {
18
- return result.current.search();
19
- });
20
- expect(result.current.loading).toBe(true);
21
- case 4:
22
- case "end":
23
- return _context.stop();
24
- }
25
- }, _callee);
26
- })));
27
- it('should stop after search is completed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
28
- var _renderHook2, result, waitForNextUpdate;
29
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
30
- while (1) switch (_context2.prev = _context2.next) {
31
- case 0:
32
- _renderHook2 = renderHook(function () {
33
- return useSearch(documents, 'Anastasia');
34
- }), result = _renderHook2.result, waitForNextUpdate = _renderHook2.waitForNextUpdate;
35
- expect(result.current.loading).toBe(false);
36
- act(function () {
37
- return result.current.search();
38
- });
39
- expect(result.current.loading).toBe(true);
40
- _context2.next = 6;
41
- return waitForNextUpdate();
42
- case 6:
43
- expect(result.current.loading).toBe(false);
44
- case 7:
45
- case "end":
46
- return _context2.stop();
47
- }
48
- }, _callee2);
49
- })));
50
- });
51
- describe('reset', function () {
52
- it('should change the returned result back to the initial data', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
53
- var _renderHook3, result, waitForNextUpdate;
54
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
55
- while (1) switch (_context3.prev = _context3.next) {
56
- case 0:
57
- _renderHook3 = renderHook(function () {
58
- return useSearch(documents, 'Anastasia');
59
- }), result = _renderHook3.result, waitForNextUpdate = _renderHook3.waitForNextUpdate;
60
- expect(result.current.loading).toBe(false);
61
- act(function () {
62
- return result.current.search();
63
- });
64
- expect(result.current.loading).toBe(true);
65
- expect(result.current.data).toEqual(documents);
66
- _context3.next = 7;
67
- return waitForNextUpdate();
68
- case 7:
69
- expect(result.current.loading).toBe(false);
70
- expect(result.current.data.length).toBe(1);
71
- act(function () {
72
- return result.current.reset();
73
- });
74
- expect(result.current.data).toEqual(documents);
75
- expect(result.current.loading).toBe(false);
76
- case 12:
77
- case "end":
78
- return _context3.stop();
79
- }
80
- }, _callee3);
81
- })));
82
- });
83
- describe('search', function () {
84
- it('should return the initial data when no query is passed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
85
- var _renderHook4, result;
86
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
87
- while (1) switch (_context4.prev = _context4.next) {
88
- case 0:
89
- _renderHook4 = renderHook(function () {
90
- return useSearch(documents);
91
- }), result = _renderHook4.result;
92
- expect(result.current.loading).toBe(false);
93
- act(function () {
94
- return result.current.search();
95
- });
96
- expect(result.current.loading).toBe(false);
97
- expect(result.current.data).toEqual(documents);
98
- case 5:
99
- case "end":
100
- return _context4.stop();
101
- }
102
- }, _callee4);
103
- })));
104
- it('should return an empty array when there are no relevant items', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
105
- var _renderHook5, result, waitForNextUpdate;
106
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
107
- while (1) switch (_context5.prev = _context5.next) {
108
- case 0:
109
- _renderHook5 = renderHook(function () {
110
- return useSearch(documents, 'fajsgsdgsdgsd');
111
- }), result = _renderHook5.result, waitForNextUpdate = _renderHook5.waitForNextUpdate;
112
- expect(result.current.loading).toBe(false);
113
- act(function () {
114
- return result.current.search();
115
- });
116
- expect(result.current.loading).toBe(true);
117
- expect(result.current.data).toEqual(documents);
118
- _context5.next = 7;
119
- return waitForNextUpdate();
120
- case 7:
121
- expect(result.current.loading).toBe(false);
122
- expect(result.current.data).toEqual([]);
123
- case 9:
124
- case "end":
125
- return _context5.stop();
126
- }
127
- }, _callee5);
128
- })));
129
- it('should return an empty array when relevant field is not indexed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
130
- var _renderHook6, result, waitForNextUpdate;
131
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
132
- while (1) switch (_context6.prev = _context6.next) {
133
- case 0:
134
- _renderHook6 = renderHook(function () {
135
- return useSearch(documents, 'Anastasia', {
136
- indexing: {
137
- fields: ['lastName'] // missing 'firstName'
138
- }
139
- });
140
- }), result = _renderHook6.result, waitForNextUpdate = _renderHook6.waitForNextUpdate;
141
- expect(result.current.loading).toBe(false);
142
- act(function () {
143
- return result.current.search();
144
- });
145
- expect(result.current.loading).toBe(true);
146
- expect(result.current.data).toEqual(documents);
147
- _context6.next = 7;
148
- return waitForNextUpdate();
149
- case 7:
150
- expect(result.current.loading).toBe(false);
151
- expect(result.current.data).toEqual([]);
152
- case 9:
153
- case "end":
154
- return _context6.stop();
155
- }
156
- }, _callee6);
157
- })));
158
- it('should return a single result when there is only one relevant item', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
159
- var _renderHook7, result, waitForNextUpdate, firstResult;
160
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
161
- while (1) switch (_context7.prev = _context7.next) {
162
- case 0:
163
- _renderHook7 = renderHook(function () {
164
- return useSearch(documents, 'Anastasia');
165
- }), result = _renderHook7.result, waitForNextUpdate = _renderHook7.waitForNextUpdate;
166
- expect(result.current.loading).toBe(false);
167
- act(function () {
168
- return result.current.search();
169
- });
170
- expect(result.current.loading).toBe(true);
171
- expect(result.current.data).toEqual(documents);
172
- _context7.next = 7;
173
- return waitForNextUpdate();
174
- case 7:
175
- expect(result.current.loading).toBe(false);
176
- expect(result.current.data.length).toBe(1);
177
- firstResult = result.current.data[0];
178
- expect(firstResult).toBeDefined();
179
- expect(Object.values(firstResult).values()).toContain('Anastasia');
180
- case 12:
181
- case "end":
182
- return _context7.stop();
183
- }
184
- }, _callee7);
185
- })));
186
- it('should return multiple results when there are multiple relevant items', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
187
- var _renderHook8, result, waitForNextUpdate;
188
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
189
- while (1) switch (_context8.prev = _context8.next) {
190
- case 0:
191
- _renderHook8 = renderHook(function () {
192
- return useSearch(documents, 'Kari');
193
- }), result = _renderHook8.result, waitForNextUpdate = _renderHook8.waitForNextUpdate;
194
- expect(result.current.loading).toBe(false);
195
- act(function () {
196
- return result.current.search();
197
- });
198
- expect(result.current.loading).toBe(true);
199
- expect(result.current.data).toEqual(documents);
200
- _context8.next = 7;
201
- return waitForNextUpdate();
202
- case 7:
203
- expect(result.current.loading).toBe(false);
204
- expect(result.current.data.length).toBeGreaterThanOrEqual(2);
205
- result.current.data.forEach(function (item) {
206
- expect(item).toBeDefined();
207
- expect(Object.values(item).values()).toContain('Kari');
208
- });
209
- case 10:
210
- case "end":
211
- return _context8.stop();
212
- }
213
- }, _callee8);
214
- })));
215
- it('should work with a partial query', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
216
- var _renderHook9, result, waitForNextUpdate, firstResult;
217
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
218
- while (1) switch (_context9.prev = _context9.next) {
219
- case 0:
220
- _renderHook9 = renderHook(function () {
221
- return useSearch(documents, 'anast');
222
- }), result = _renderHook9.result, waitForNextUpdate = _renderHook9.waitForNextUpdate;
223
- expect(result.current.loading).toBe(false);
224
- act(function () {
225
- return result.current.search();
226
- });
227
- expect(result.current.loading).toBe(true);
228
- expect(result.current.data).toEqual(documents);
229
- _context9.next = 7;
230
- return waitForNextUpdate();
231
- case 7:
232
- expect(result.current.loading).toBe(false);
233
- expect(result.current.data.length).toBe(1);
234
- firstResult = result.current.data[0];
235
- expect(firstResult).toBeDefined();
236
- expect(Object.values(firstResult).values()).toContain('Anastasia');
237
- case 12:
238
- case "end":
239
- return _context9.stop();
240
- }
241
- }, _callee9);
242
- })));
243
- it('should work with nested field if not explicitly stated', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
244
- var _renderHook10, result, waitForNextUpdate, firstResult;
245
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
246
- while (1) switch (_context10.prev = _context10.next) {
247
- case 0:
248
- _renderHook10 = renderHook(function () {
249
- return useSearch(documents, 'Titanic');
250
- }), result = _renderHook10.result, waitForNextUpdate = _renderHook10.waitForNextUpdate;
251
- expect(result.current.loading).toBe(false);
252
- act(function () {
253
- return result.current.search();
254
- });
255
- expect(result.current.loading).toBe(true);
256
- expect(result.current.data).toEqual(documents);
257
- _context10.next = 7;
258
- return waitForNextUpdate();
259
- case 7:
260
- expect(result.current.loading).toBe(false);
261
- expect(result.current.data.length).toBe(1);
262
- firstResult = result.current.data[0];
263
- expect(firstResult).toBeDefined();
264
- expect(Object.values(firstResult.address).values()).toContain('Titanic');
265
- case 12:
266
- case "end":
267
- return _context10.stop();
268
- }
269
- }, _callee10);
270
- })));
271
- it('should work with nested field if explicitly stated', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
272
- var _renderHook11, result, waitForNextUpdate, firstResult;
273
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
274
- while (1) switch (_context11.prev = _context11.next) {
275
- case 0:
276
- _renderHook11 = renderHook(function () {
277
- return useSearch(documents, 'Titanic', {
278
- indexing: {
279
- fields: ['address.city']
280
- }
281
- });
282
- }), result = _renderHook11.result, waitForNextUpdate = _renderHook11.waitForNextUpdate;
283
- expect(result.current.loading).toBe(false);
284
- act(function () {
285
- return result.current.search();
286
- });
287
- expect(result.current.loading).toBe(true);
288
- expect(result.current.data).toEqual(documents);
289
- _context11.next = 7;
290
- return waitForNextUpdate();
291
- case 7:
292
- expect(result.current.loading).toBe(false);
293
- expect(result.current.data.length).toBe(1);
294
- firstResult = result.current.data[0];
295
- expect(firstResult).toBeDefined();
296
- expect(Object.values(firstResult.address).values()).toContain('Titanic');
297
- case 12:
298
- case "end":
299
- return _context11.stop();
300
- }
301
- }, _callee11);
302
- })));
303
- it('should work with nested ID', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
304
- var _renderHook12, result, waitForNextUpdate, firstResult;
305
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
306
- while (1) switch (_context12.prev = _context12.next) {
307
- case 0:
308
- _renderHook12 = renderHook(function () {
309
- return useSearch(documents, 'Titanic', {
310
- indexing: {
311
- idKey: 'address.street'
312
- }
313
- });
314
- }), result = _renderHook12.result, waitForNextUpdate = _renderHook12.waitForNextUpdate;
315
- expect(result.current.loading).toBe(false);
316
- act(function () {
317
- return result.current.search();
318
- });
319
- expect(result.current.loading).toBe(true);
320
- expect(result.current.data).toEqual(documents);
321
- _context12.next = 7;
322
- return waitForNextUpdate();
323
- case 7:
324
- expect(result.current.loading).toBe(false);
325
- expect(result.current.data.length).toBe(1);
326
- firstResult = result.current.data[0];
327
- expect(firstResult).toBeDefined();
328
- expect(Object.values(firstResult.address).values()).toContain('Titanic');
329
- case 12:
330
- case "end":
331
- return _context12.stop();
332
- }
333
- }, _callee12);
334
- })));
335
- it('should work with indexed Greek characters and Latin query', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
336
- var _renderHook13, result, waitForNextUpdate, firstResult;
337
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
338
- while (1) switch (_context13.prev = _context13.next) {
339
- case 0:
340
- _renderHook13 = renderHook(function () {
341
- return useSearch(documents, 'Markos');
342
- }), result = _renderHook13.result, waitForNextUpdate = _renderHook13.waitForNextUpdate;
343
- expect(result.current.loading).toBe(false);
344
- act(function () {
345
- return result.current.search();
346
- });
347
- expect(result.current.loading).toBe(true);
348
- expect(result.current.data).toEqual(documents);
349
- _context13.next = 7;
350
- return waitForNextUpdate();
351
- case 7:
352
- expect(result.current.loading).toBe(false);
353
- expect(result.current.data.length).toBe(1);
354
- firstResult = result.current.data[0];
355
- expect(firstResult).toBeDefined();
356
- expect(Object.values(firstResult).values()).toContain('Μάρκος');
357
- case 12:
358
- case "end":
359
- return _context13.stop();
360
- }
361
- }, _callee13);
362
- })));
363
- it('should work with indexed Greek characters and Greek query', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
364
- var _renderHook14, result, waitForNextUpdate, firstResult;
365
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
366
- while (1) switch (_context14.prev = _context14.next) {
367
- case 0:
368
- _renderHook14 = renderHook(function () {
369
- return useSearch(documents, 'Μάρκος');
370
- }), result = _renderHook14.result, waitForNextUpdate = _renderHook14.waitForNextUpdate;
371
- expect(result.current.loading).toBe(false);
372
- act(function () {
373
- return result.current.search();
374
- });
375
- expect(result.current.loading).toBe(true);
376
- expect(result.current.data).toEqual(documents);
377
- _context14.next = 7;
378
- return waitForNextUpdate();
379
- case 7:
380
- expect(result.current.loading).toBe(false);
381
- expect(result.current.data.length).toBe(1);
382
- firstResult = result.current.data[0];
383
- expect(firstResult).toBeDefined();
384
- expect(Object.values(firstResult).values()).toContain('Μάρκος');
385
- case 12:
386
- case "end":
387
- return _context14.stop();
388
- }
389
- }, _callee14);
390
- })));
391
- it('should react to changes in the documents list', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
392
- var emptyDocuments, _renderHook15, result, rerender, waitForNextUpdate, firstResult;
393
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
394
- while (1) switch (_context15.prev = _context15.next) {
395
- case 0:
396
- emptyDocuments = [];
397
- _renderHook15 = renderHook(function (_ref16) {
398
- var documents = _ref16.documents;
399
- return useSearch(documents, 'Anastasia');
400
- }, {
401
- initialProps: {
402
- documents: emptyDocuments
403
- }
404
- }), result = _renderHook15.result, rerender = _renderHook15.rerender, waitForNextUpdate = _renderHook15.waitForNextUpdate;
405
- expect(result.current.loading).toBe(false);
406
- act(function () {
407
- return result.current.search();
408
- });
409
- expect(result.current.loading).toBe(true);
410
- _context15.next = 7;
411
- return waitForNextUpdate();
412
- case 7:
413
- expect(result.current.loading).toBe(false);
414
- expect(result.current.data).toEqual([]);
415
- rerender({
416
- documents: documents
417
- });
418
- expect(result.current.loading).toBe(false);
419
- expect(result.current.data).toEqual([]);
420
- act(function () {
421
- return result.current.search();
422
- });
423
- expect(result.current.loading).toBe(true);
424
- expect(result.current.data).toEqual([]);
425
- _context15.next = 17;
426
- return waitForNextUpdate();
427
- case 17:
428
- expect(result.current.loading).toBe(false);
429
- expect(result.current.data.length).toBe(1);
430
- firstResult = result.current.data[0];
431
- expect(firstResult).toBeDefined();
432
- expect(Object.values(firstResult).values()).toContain('Anastasia');
433
- case 22:
434
- case "end":
435
- return _context15.stop();
436
- }
437
- }, _callee15);
438
- })));
439
- it('should react to changes in the search query', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
440
- var _renderHook16, result, rerender, waitForNextUpdate, firstResult;
441
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
442
- while (1) switch (_context16.prev = _context16.next) {
443
- case 0:
444
- _renderHook16 = renderHook(function (_ref18) {
445
- var query = _ref18.query;
446
- return useSearch(documents, query);
447
- }, {
448
- initialProps: {
449
- query: ''
450
- }
451
- }), result = _renderHook16.result, rerender = _renderHook16.rerender, waitForNextUpdate = _renderHook16.waitForNextUpdate;
452
- expect(result.current.loading).toBe(false);
453
- expect(result.current.data).toEqual(documents);
454
- rerender({
455
- query: 'Anastasia'
456
- });
457
- expect(result.current.loading).toBe(false);
458
- expect(result.current.data).toEqual(documents);
459
- act(function () {
460
- return result.current.search();
461
- });
462
- expect(result.current.loading).toBe(true);
463
- expect(result.current.data).toEqual(documents);
464
- _context16.next = 11;
465
- return waitForNextUpdate();
466
- case 11:
467
- expect(result.current.loading).toBe(false);
468
- expect(result.current.data.length).toBe(1);
469
- firstResult = result.current.data[0];
470
- expect(firstResult).toBeDefined();
471
- expect(Object.values(firstResult).values()).toContain('Anastasia');
472
- case 16:
473
- case "end":
474
- return _context16.stop();
475
- }
476
- }, _callee16);
477
- })));
478
- });
@@ -1,6 +0,0 @@
1
- {
2
- "sideEffects": false,
3
- "module": "./index.js",
4
- "types": "./index.d.ts",
5
- "main": "../cjs/hook.spec/index.js"
6
- }
@@ -1,81 +0,0 @@
1
- import { findItemsByIds, getAllItemKeys, getResultIds } from "../utils";
2
- describe('utils', function () {
3
- describe('getResultIds', function () {
4
- it('should return the ids of the results without duplicates', function () {
5
- var result = [{
6
- field: 'title',
7
- result: [1, 2]
8
- }, {
9
- field: 'description',
10
- result: [2, 3]
11
- }, {
12
- field: 'tag',
13
- result: [1, 2, 3, 4]
14
- }];
15
- expect(getResultIds(result)).toEqual([1, 2, 3, 4]);
16
- });
17
- it('should return an empty array if there are no results', function () {
18
- var result = [];
19
- expect(getResultIds(result)).toEqual([]);
20
- });
21
- });
22
- describe('findItemsByIds', function () {
23
- it('should return the items that match the given ids', function () {
24
- var items = [{
25
- id: 1,
26
- name: 'Anastasia'
27
- }, {
28
- id: 2,
29
- name: 'Bob'
30
- }, {
31
- id: 3,
32
- name: 'Cindy'
33
- }];
34
- var ids = [1, 3];
35
- expect(findItemsByIds(items, ids, 'id')).toEqual([{
36
- id: 1,
37
- name: 'Anastasia'
38
- }, {
39
- id: 3,
40
- name: 'Cindy'
41
- }]);
42
- });
43
- it('should return an empty array if there are no items', function () {
44
- var items = [];
45
- var ids = [1, 3];
46
- expect(findItemsByIds(items, ids, 'id')).toEqual([]);
47
- });
48
- it('should return an empty array if there are no ids', function () {
49
- var items = [{
50
- id: 1,
51
- name: 'Anastasia'
52
- }, {
53
- id: 2,
54
- name: 'Bob'
55
- }, {
56
- id: 3,
57
- name: 'Cindy'
58
- }];
59
- var ids = [];
60
- expect(findItemsByIds(items, ids, 'id')).toEqual([]);
61
- });
62
- });
63
- describe('getAllItemKeys', function () {
64
- it('should return all the keys for the given item', function () {
65
- var item = {
66
- id: 1,
67
- name: 'Anastasia',
68
- address: {
69
- street: '123 Main St',
70
- city: 'New York',
71
- state: 'NY'
72
- }
73
- };
74
- expect(getAllItemKeys(item)).toEqual(['id', 'name', 'address.street', 'address.city', 'address.state']);
75
- });
76
- it('should return an empty array if item is an empty object', function () {
77
- var item = {};
78
- expect(getAllItemKeys(item)).toEqual([]);
79
- });
80
- });
81
- });
@@ -1,6 +0,0 @@
1
- {
2
- "sideEffects": false,
3
- "module": "./index.js",
4
- "types": "./index.d.ts",
5
- "main": "../../../cjs/search/__tests__/utils.spec/index.js"
6
- }