piral-search 0.15.0-alpha.4332 → 0.15.0-alpha.4345
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.
- package/package.json +7 -3
- package/src/actions.test.ts +43 -43
- package/src/create.test.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-search",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.4345",
|
|
4
4
|
"description": "Plugin for centralizing search in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"./lib/*": {
|
|
32
32
|
"require": "./lib/*"
|
|
33
33
|
},
|
|
34
|
+
"./_/*": {
|
|
35
|
+
"import": "./esm/*.js",
|
|
36
|
+
"require": "./lib/*.js"
|
|
37
|
+
},
|
|
34
38
|
"./package.json": "./package.json"
|
|
35
39
|
},
|
|
36
40
|
"sideEffects": false,
|
|
@@ -58,12 +62,12 @@
|
|
|
58
62
|
},
|
|
59
63
|
"devDependencies": {
|
|
60
64
|
"@types/react": "^18.0.0",
|
|
61
|
-
"piral-core": "0.15.0-alpha.
|
|
65
|
+
"piral-core": "0.15.0-alpha.4345",
|
|
62
66
|
"react": "^18.0.0"
|
|
63
67
|
},
|
|
64
68
|
"peerDependencies": {
|
|
65
69
|
"piral-core": "0.14.x || 0.15.x",
|
|
66
70
|
"react": ">=16.8.0"
|
|
67
71
|
},
|
|
68
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "56ecd6ad080b3d275752b19afcf8435e4bd09140"
|
|
69
73
|
}
|
package/src/actions.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { createListener } from 'piral-base';
|
|
3
3
|
import { createActions } from 'piral-core';
|
|
4
4
|
import { createActions as createSearchActions } from './actions';
|
|
@@ -15,7 +15,7 @@ const state = {
|
|
|
15
15
|
|
|
16
16
|
describe('Search Action Module', () => {
|
|
17
17
|
it('appendSearchResults cont appends new items with still loading', () => {
|
|
18
|
-
const state =
|
|
18
|
+
const state: any = create(() => ({
|
|
19
19
|
foo: 5,
|
|
20
20
|
search: {
|
|
21
21
|
input: 'yo',
|
|
@@ -24,11 +24,11 @@ describe('Search Action Module', () => {
|
|
|
24
24
|
items: ['c'],
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
|
-
});
|
|
27
|
+
}));
|
|
28
28
|
const ctx = createActions(state, createListener({}));
|
|
29
29
|
ctx.defineActions(createSearchActions());
|
|
30
30
|
ctx.appendSearchResults(['a', 'b'], false);
|
|
31
|
-
expect(
|
|
31
|
+
expect(state.getState()).toEqual({
|
|
32
32
|
foo: 5,
|
|
33
33
|
search: {
|
|
34
34
|
input: 'yo',
|
|
@@ -41,7 +41,7 @@ describe('Search Action Module', () => {
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it('appendSearchResults stop appends new items without still loading', () => {
|
|
44
|
-
const state =
|
|
44
|
+
const state: any = create(() => ({
|
|
45
45
|
foo: [1, 2],
|
|
46
46
|
search: {
|
|
47
47
|
input: 'yo',
|
|
@@ -50,11 +50,11 @@ describe('Search Action Module', () => {
|
|
|
50
50
|
items: ['c'],
|
|
51
51
|
},
|
|
52
52
|
},
|
|
53
|
-
});
|
|
53
|
+
}));
|
|
54
54
|
const ctx = createActions(state, createListener({}));
|
|
55
55
|
ctx.defineActions(createSearchActions());
|
|
56
56
|
ctx.appendSearchResults(['a'], true);
|
|
57
|
-
expect(
|
|
57
|
+
expect(state.getState()).toEqual({
|
|
58
58
|
foo: [1, 2],
|
|
59
59
|
search: {
|
|
60
60
|
input: 'yo',
|
|
@@ -67,7 +67,7 @@ describe('Search Action Module', () => {
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
it('prependSearchResults cont prepends new items with still loading', () => {
|
|
70
|
-
const state =
|
|
70
|
+
const state: any = create(() => ({
|
|
71
71
|
foo: 5,
|
|
72
72
|
search: {
|
|
73
73
|
input: 'yo',
|
|
@@ -76,11 +76,11 @@ describe('Search Action Module', () => {
|
|
|
76
76
|
items: ['c'],
|
|
77
77
|
},
|
|
78
78
|
},
|
|
79
|
-
});
|
|
79
|
+
}));
|
|
80
80
|
const ctx = createActions(state, createListener({}));
|
|
81
81
|
ctx.defineActions(createSearchActions());
|
|
82
82
|
ctx.prependSearchResults(['a', 'b'], false);
|
|
83
|
-
expect(
|
|
83
|
+
expect(state.getState()).toEqual({
|
|
84
84
|
foo: 5,
|
|
85
85
|
search: {
|
|
86
86
|
input: 'yo',
|
|
@@ -93,7 +93,7 @@ describe('Search Action Module', () => {
|
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
it('prependSearchResults stop prepends new items without still loading', () => {
|
|
96
|
-
const state =
|
|
96
|
+
const state: any = create(() => ({
|
|
97
97
|
foo: [1, 2],
|
|
98
98
|
search: {
|
|
99
99
|
input: 'yo',
|
|
@@ -102,11 +102,11 @@ describe('Search Action Module', () => {
|
|
|
102
102
|
items: ['c'],
|
|
103
103
|
},
|
|
104
104
|
},
|
|
105
|
-
});
|
|
105
|
+
}));
|
|
106
106
|
const ctx = createActions(state, createListener({}));
|
|
107
107
|
ctx.defineActions(createSearchActions());
|
|
108
108
|
ctx.prependSearchResults(['a'], true);
|
|
109
|
-
expect(
|
|
109
|
+
expect(state.getState()).toEqual({
|
|
110
110
|
foo: [1, 2],
|
|
111
111
|
search: {
|
|
112
112
|
input: 'yo',
|
|
@@ -119,7 +119,7 @@ describe('Search Action Module', () => {
|
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
it('resetSearchResults cont resets the search results while still loading', () => {
|
|
122
|
-
const state =
|
|
122
|
+
const state: any = create(() => ({
|
|
123
123
|
foo: [1, 2],
|
|
124
124
|
search: {
|
|
125
125
|
input: 'yo',
|
|
@@ -128,11 +128,11 @@ describe('Search Action Module', () => {
|
|
|
128
128
|
items: ['c'],
|
|
129
129
|
},
|
|
130
130
|
},
|
|
131
|
-
});
|
|
131
|
+
}));
|
|
132
132
|
const ctx = createActions(state, createListener({}));
|
|
133
133
|
ctx.defineActions(createSearchActions());
|
|
134
134
|
ctx.resetSearchResults('yo', true);
|
|
135
|
-
expect(
|
|
135
|
+
expect(state.getState()).toEqual({
|
|
136
136
|
foo: [1, 2],
|
|
137
137
|
search: {
|
|
138
138
|
input: 'yo',
|
|
@@ -145,7 +145,7 @@ describe('Search Action Module', () => {
|
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
it('resetSearchResults stop resets the search results without loading', () => {
|
|
148
|
-
const state =
|
|
148
|
+
const state: any = create(() => ({
|
|
149
149
|
foo: 5,
|
|
150
150
|
search: {
|
|
151
151
|
input: 'yo y',
|
|
@@ -154,11 +154,11 @@ describe('Search Action Module', () => {
|
|
|
154
154
|
items: ['c'],
|
|
155
155
|
},
|
|
156
156
|
},
|
|
157
|
-
});
|
|
157
|
+
}));
|
|
158
158
|
const ctx = createActions(state, createListener({}));
|
|
159
159
|
ctx.defineActions(createSearchActions());
|
|
160
160
|
ctx.resetSearchResults('yo y', false);
|
|
161
|
-
expect(
|
|
161
|
+
expect(state.getState()).toEqual({
|
|
162
162
|
foo: 5,
|
|
163
163
|
search: {
|
|
164
164
|
input: 'yo y',
|
|
@@ -171,7 +171,7 @@ describe('Search Action Module', () => {
|
|
|
171
171
|
});
|
|
172
172
|
|
|
173
173
|
it('setSearchInput sets the input field accordingly', () => {
|
|
174
|
-
const state =
|
|
174
|
+
const state: any = create(() => ({
|
|
175
175
|
foo: 5,
|
|
176
176
|
search: {
|
|
177
177
|
input: 'yo y',
|
|
@@ -180,11 +180,11 @@ describe('Search Action Module', () => {
|
|
|
180
180
|
items: ['c'],
|
|
181
181
|
},
|
|
182
182
|
},
|
|
183
|
-
});
|
|
183
|
+
}));
|
|
184
184
|
const ctx = createActions(state, createListener({}));
|
|
185
185
|
ctx.defineActions(createSearchActions());
|
|
186
186
|
ctx.setSearchInput('test input');
|
|
187
|
-
expect(
|
|
187
|
+
expect(state.getState()).toEqual({
|
|
188
188
|
foo: 5,
|
|
189
189
|
search: {
|
|
190
190
|
input: 'test input',
|
|
@@ -198,11 +198,11 @@ describe('Search Action Module', () => {
|
|
|
198
198
|
|
|
199
199
|
it('immediately resets with loading false if some value is given but no provider found', () => {
|
|
200
200
|
state.search.input = 'foo';
|
|
201
|
-
const globalState =
|
|
201
|
+
const globalState: any = create(() => state);
|
|
202
202
|
const ctx = createActions(globalState, createListener({}));
|
|
203
203
|
ctx.defineActions(createSearchActions());
|
|
204
204
|
ctx.triggerSearch();
|
|
205
|
-
expect(
|
|
205
|
+
expect(globalState.getState().search.results.loading).toBe(false);
|
|
206
206
|
});
|
|
207
207
|
|
|
208
208
|
it('immediately resets with loading true if some value is given and a provider is found', () => {
|
|
@@ -214,38 +214,38 @@ describe('Search Action Module', () => {
|
|
|
214
214
|
clear() {},
|
|
215
215
|
cancel() {},
|
|
216
216
|
};
|
|
217
|
-
const globalState =
|
|
217
|
+
const globalState: any = create(() => state);
|
|
218
218
|
const ctx = createActions(globalState, createListener({}));
|
|
219
219
|
ctx.defineActions(createSearchActions());
|
|
220
220
|
ctx.triggerSearch();
|
|
221
|
-
expect(
|
|
221
|
+
expect(globalState.getState().search.results.loading).toBe(true);
|
|
222
222
|
});
|
|
223
223
|
|
|
224
224
|
it('immediately resets with loading false if no value is given implicitly', () => {
|
|
225
225
|
state.search.input = '';
|
|
226
|
-
const globalState =
|
|
226
|
+
const globalState: any = create(() => state);
|
|
227
227
|
const ctx = createActions(globalState, createListener({}));
|
|
228
228
|
ctx.defineActions(createSearchActions());
|
|
229
229
|
ctx.triggerSearch();
|
|
230
|
-
expect(
|
|
230
|
+
expect(globalState.getState().search.results.loading).toBe(false);
|
|
231
231
|
});
|
|
232
232
|
|
|
233
233
|
it('immediately resets with loading false if no value is given explicitly', () => {
|
|
234
|
-
const gs =
|
|
234
|
+
const gs: any = create(() => state);
|
|
235
235
|
const ctx = createActions(gs, createListener({}));
|
|
236
236
|
ctx.defineActions(createSearchActions());
|
|
237
237
|
const dispose = ctx.triggerSearch('');
|
|
238
238
|
dispose();
|
|
239
|
-
expect(
|
|
239
|
+
expect(gs.getState().search.results.loading).toBe(false);
|
|
240
240
|
});
|
|
241
241
|
|
|
242
242
|
it('immediately resets with loading false if no value is given explicitly though immediate', () => {
|
|
243
|
-
const gs =
|
|
243
|
+
const gs: any = create(() => state);
|
|
244
244
|
const ctx = createActions(gs, createListener({}));
|
|
245
245
|
ctx.defineActions(createSearchActions());
|
|
246
246
|
const dispose = ctx.triggerSearch('', true);
|
|
247
247
|
dispose();
|
|
248
|
-
expect(
|
|
248
|
+
expect(gs.getState().search.results.loading).toBe(false);
|
|
249
249
|
});
|
|
250
250
|
|
|
251
251
|
it('resets with loading true if no value is given explicitly', () => {
|
|
@@ -257,11 +257,11 @@ describe('Search Action Module', () => {
|
|
|
257
257
|
clear() {},
|
|
258
258
|
cancel() {},
|
|
259
259
|
};
|
|
260
|
-
const gs =
|
|
260
|
+
const gs: any = create(() => state);
|
|
261
261
|
const ctx = createActions(gs, createListener({}));
|
|
262
262
|
ctx.defineActions(createSearchActions());
|
|
263
263
|
ctx.triggerSearch('foo');
|
|
264
|
-
expect(
|
|
264
|
+
expect(gs.getState().search.results.loading).toBe(true);
|
|
265
265
|
});
|
|
266
266
|
|
|
267
267
|
it('walks over all search providers', () => {
|
|
@@ -273,7 +273,7 @@ describe('Search Action Module', () => {
|
|
|
273
273
|
foo: { search, clear, cancel },
|
|
274
274
|
bar: { search, clear, cancel },
|
|
275
275
|
};
|
|
276
|
-
const gs =
|
|
276
|
+
const gs: any = create(() => state);
|
|
277
277
|
const ctx = createActions(gs, createListener({}));
|
|
278
278
|
ctx.defineActions(createSearchActions());
|
|
279
279
|
ctx.triggerSearch();
|
|
@@ -291,7 +291,7 @@ describe('Search Action Module', () => {
|
|
|
291
291
|
cancel() {},
|
|
292
292
|
},
|
|
293
293
|
};
|
|
294
|
-
const gs =
|
|
294
|
+
const gs: any = create(() => state);
|
|
295
295
|
const ctx = createActions(gs, createListener({}));
|
|
296
296
|
ctx.defineActions(createSearchActions());
|
|
297
297
|
ctx.triggerSearch();
|
|
@@ -310,7 +310,7 @@ describe('Search Action Module', () => {
|
|
|
310
310
|
cancel,
|
|
311
311
|
},
|
|
312
312
|
};
|
|
313
|
-
const gs =
|
|
313
|
+
const gs: any = create(() => state);
|
|
314
314
|
const ctx = createActions(gs, createListener({}));
|
|
315
315
|
ctx.defineActions(createSearchActions());
|
|
316
316
|
ctx.triggerSearch();
|
|
@@ -330,7 +330,7 @@ describe('Search Action Module', () => {
|
|
|
330
330
|
cancel,
|
|
331
331
|
},
|
|
332
332
|
};
|
|
333
|
-
const gs =
|
|
333
|
+
const gs: any = create(() => state);
|
|
334
334
|
const ctx = createActions(gs, createListener({}));
|
|
335
335
|
ctx.defineActions(createSearchActions());
|
|
336
336
|
const dispose = ctx.triggerSearch();
|
|
@@ -351,7 +351,7 @@ describe('Search Action Module', () => {
|
|
|
351
351
|
cancel() {},
|
|
352
352
|
},
|
|
353
353
|
};
|
|
354
|
-
const gs =
|
|
354
|
+
const gs: any = create(() => state);
|
|
355
355
|
const ctx = createActions(gs, createListener({}));
|
|
356
356
|
ctx.defineActions(createSearchActions());
|
|
357
357
|
ctx.triggerSearch();
|
|
@@ -360,17 +360,17 @@ describe('Search Action Module', () => {
|
|
|
360
360
|
});
|
|
361
361
|
|
|
362
362
|
it('registerSearchProvider and unregisterSearchProvider', () => {
|
|
363
|
-
const state =
|
|
363
|
+
const state: any = create(() => ({
|
|
364
364
|
foo: 5,
|
|
365
365
|
registry: {
|
|
366
366
|
foo: 5,
|
|
367
367
|
searchProviders: {},
|
|
368
368
|
},
|
|
369
|
-
});
|
|
369
|
+
}));
|
|
370
370
|
const ctx = createActions(state, createListener({}));
|
|
371
371
|
ctx.defineActions(createSearchActions());
|
|
372
372
|
ctx.registerSearchProvider('foo', 10 as any);
|
|
373
|
-
expect(
|
|
373
|
+
expect(state.getState()).toEqual({
|
|
374
374
|
foo: 5,
|
|
375
375
|
registry: {
|
|
376
376
|
foo: 5,
|
|
@@ -380,7 +380,7 @@ describe('Search Action Module', () => {
|
|
|
380
380
|
},
|
|
381
381
|
});
|
|
382
382
|
ctx.unregisterSearchProvider('foo');
|
|
383
|
-
expect(
|
|
383
|
+
expect(state.getState()).toEqual({
|
|
384
384
|
foo: 5,
|
|
385
385
|
registry: {
|
|
386
386
|
foo: 5,
|
package/src/create.test.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { createSearchApi } from './create';
|
|
3
3
|
|
|
4
4
|
function createMockContainer() {
|
|
5
|
-
const state =
|
|
5
|
+
const state = create(() => ({
|
|
6
6
|
registry: {
|
|
7
7
|
extensions: {},
|
|
8
8
|
},
|
|
9
|
-
});
|
|
9
|
+
}));
|
|
10
10
|
return {
|
|
11
11
|
context: {
|
|
12
12
|
on: jest.fn(),
|
|
@@ -15,7 +15,7 @@ function createMockContainer() {
|
|
|
15
15
|
defineActions() {},
|
|
16
16
|
state,
|
|
17
17
|
dispatch(update) {
|
|
18
|
-
|
|
18
|
+
state.setState(update(state.getState()));
|
|
19
19
|
},
|
|
20
20
|
} as any,
|
|
21
21
|
api: {} as any,
|