@arrai-innovations/reactive-helpers 18.0.0 → 18.0.2
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 +20 -6
- package/types/config/listCrud.d.ts +153 -0
- package/types/config/listCrud.d.ts.map +1 -0
- package/types/config/objectCrud.d.ts +171 -0
- package/types/config/objectCrud.d.ts.map +1 -0
- package/types/index.d.ts +37 -0
- package/types/index.d.ts.map +1 -0
- package/types/tests/unit/config/listCrud.spec.d.ts +2 -0
- package/types/tests/unit/config/listCrud.spec.d.ts.map +1 -0
- package/types/tests/unit/config/objectCrud.spec.d.ts +2 -0
- package/types/tests/unit/config/objectCrud.spec.d.ts.map +1 -0
- package/types/tests/unit/crudPromise.d.ts +25 -0
- package/types/tests/unit/crudPromise.d.ts.map +1 -0
- package/types/tests/unit/expectHelpers.d.ts +2 -0
- package/types/tests/unit/expectHelpers.d.ts.map +1 -0
- package/types/tests/unit/mockOnUnmounted.d.ts +2 -0
- package/types/tests/unit/mockOnUnmounted.d.ts.map +1 -0
- package/types/tests/unit/poll.d.ts +2 -0
- package/types/tests/unit/poll.d.ts.map +1 -0
- package/types/tests/unit/use/cancellableIntent.spec.d.ts +2 -0
- package/types/tests/unit/use/cancellableIntent.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listCalculated.spec.d.ts +2 -0
- package/types/tests/unit/use/listCalculated.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listFilter.spec.d.ts +2 -0
- package/types/tests/unit/use/listFilter.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listInstance.spec.d.ts +2 -0
- package/types/tests/unit/use/listInstance.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listRelated.spec.d.ts +2 -0
- package/types/tests/unit/use/listRelated.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listSearch.spec.d.ts +2 -0
- package/types/tests/unit/use/listSearch.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listSort.spec.d.ts +2 -0
- package/types/tests/unit/use/listSort.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listSubscription.spec.d.ts +2 -0
- package/types/tests/unit/use/listSubscription.spec.d.ts.map +1 -0
- package/types/tests/unit/use/loadingError.spec.d.ts +2 -0
- package/types/tests/unit/use/loadingError.spec.d.ts.map +1 -0
- package/types/tests/unit/use/objectInstance.spec.d.ts +2 -0
- package/types/tests/unit/use/objectInstance.spec.d.ts.map +1 -0
- package/types/tests/unit/use/objectSubscription.spec.d.ts +2 -0
- package/types/tests/unit/use/objectSubscription.spec.d.ts.map +1 -0
- package/types/tests/unit/use/proxyLoadingError.spec.d.ts +2 -0
- package/types/tests/unit/use/proxyLoadingError.spec.d.ts.map +1 -0
- package/types/tests/unit/use/search.spec.d.ts +2 -0
- package/types/tests/unit/use/search.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/assignReactiveObject.spec.d.ts +2 -0
- package/types/tests/unit/utils/assignReactiveObject.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/classes.spec.d.ts +2 -0
- package/types/tests/unit/utils/classes.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/deleteKey.spec.d.ts +2 -0
- package/types/tests/unit/utils/deleteKey.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/flattenPaths.spec.d.ts +2 -0
- package/types/tests/unit/utils/flattenPaths.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/keyDiff.spec.d.ts +2 -0
- package/types/tests/unit/utils/keyDiff.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/set.spec.d.ts +2 -0
- package/types/tests/unit/utils/set.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/watches.spec.d.ts +2 -0
- package/types/tests/unit/utils/watches.spec.d.ts.map +1 -0
- package/types/use/cancellableIntent.d.ts +129 -0
- package/types/use/cancellableIntent.d.ts.map +1 -0
- package/types/use/combineClasses.d.ts +43 -0
- package/types/use/combineClasses.d.ts.map +1 -0
- package/types/use/list.d.ts +176 -0
- package/types/use/list.d.ts.map +1 -0
- package/types/use/listCalculated.d.ts +192 -0
- package/types/use/listCalculated.d.ts.map +1 -0
- package/types/use/listFilter.d.ts +203 -0
- package/types/use/listFilter.d.ts.map +1 -0
- package/types/use/listInstance.d.ts +357 -0
- package/types/use/listInstance.d.ts.map +1 -0
- package/types/use/listKeys.d.ts +15 -0
- package/types/use/listKeys.d.ts.map +1 -0
- package/types/use/listRelated.d.ts +239 -0
- package/types/use/listRelated.d.ts.map +1 -0
- package/types/use/listSearch.d.ts +298 -0
- package/types/use/listSearch.d.ts.map +1 -0
- package/types/use/listSort.d.ts +235 -0
- package/types/use/listSort.d.ts.map +1 -0
- package/types/use/listSubscription.d.ts +218 -0
- package/types/use/listSubscription.d.ts.map +1 -0
- package/types/use/loadingError.d.ts +81 -0
- package/types/use/loadingError.d.ts.map +1 -0
- package/types/use/object.d.ts +67 -0
- package/types/use/object.d.ts.map +1 -0
- package/types/use/objectCalculated.d.ts +215 -0
- package/types/use/objectCalculated.d.ts.map +1 -0
- package/types/use/objectInstance.d.ts +289 -0
- package/types/use/objectInstance.d.ts.map +1 -0
- package/types/use/objectRelated.d.ts +264 -0
- package/types/use/objectRelated.d.ts.map +1 -0
- package/types/use/objectSubscription.d.ts +249 -0
- package/types/use/objectSubscription.d.ts.map +1 -0
- package/types/use/paginatedListInstance.d.ts +51 -0
- package/types/use/paginatedListInstance.d.ts.map +1 -0
- package/types/use/proxyLoadingError.d.ts +36 -0
- package/types/use/proxyLoadingError.d.ts.map +1 -0
- package/types/use/search.d.ts +144 -0
- package/types/use/search.d.ts.map +1 -0
- package/types/use/watchesRunning.d.ts +63 -0
- package/types/use/watchesRunning.d.ts.map +1 -0
- package/types/utils/assignReactiveObject.d.ts +115 -0
- package/types/utils/assignReactiveObject.d.ts.map +1 -0
- package/types/utils/classes.d.ts +22 -0
- package/types/utils/classes.d.ts.map +1 -0
- package/types/utils/compact.d.ts +4 -0
- package/types/utils/compact.d.ts.map +1 -0
- package/types/utils/deleteKey.d.ts +16 -0
- package/types/utils/deleteKey.d.ts.map +1 -0
- package/types/utils/flattenPaths.d.ts +23 -0
- package/types/utils/flattenPaths.d.ts.map +1 -0
- package/types/utils/getFakePk.d.ts +13 -0
- package/types/utils/getFakePk.d.ts.map +1 -0
- package/types/utils/keepAliveTry.d.ts +15 -0
- package/types/utils/keepAliveTry.d.ts.map +1 -0
- package/types/utils/keyDiff.d.ts +63 -0
- package/types/utils/keyDiff.d.ts.map +1 -0
- package/types/utils/loadingCombine.d.ts +9 -0
- package/types/utils/loadingCombine.d.ts.map +1 -0
- package/types/utils/proxyRunning.d.ts +9 -0
- package/types/utils/proxyRunning.d.ts.map +1 -0
- package/types/utils/relatedCalculatedHelpers.d.ts +5 -0
- package/types/utils/relatedCalculatedHelpers.d.ts.map +1 -0
- package/types/utils/set.d.ts +7 -0
- package/types/utils/set.d.ts.map +1 -0
- package/types/utils/transformWalk.d.ts +2 -0
- package/types/utils/transformWalk.d.ts.map +1 -0
- package/types/utils/watches.d.ts +155 -0
- package/types/utils/watches.d.ts.map +1 -0
- package/use/loadingError.js +1 -1
- package/.circleci/config.yml +0 -88
- package/.commitlintrc.json +0 -25
- package/.editorconfig +0 -5
- package/.husky/commit-msg +0 -3
- package/.husky/pre-commit +0 -3
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/encodings.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -7
- package/.idea/modules.xml +0 -8
- package/.idea/prettier.xml +0 -8
- package/.idea/reactive-helpers.iml +0 -15
- package/.prettierignore +0 -5
- package/.prettierrc.cjs +0 -5
- package/.vscode/extensions.json +0 -3
- package/docs/README.md +0 -45
- package/docs/config/listCrud.md +0 -422
- package/docs/config/objectCrud.md +0 -427
- package/docs/use/cancellableIntent.md +0 -165
- package/docs/use/combineClasses.md +0 -62
- package/docs/use/list.md +0 -361
- package/docs/use/listCalculated.md +0 -794
- package/docs/use/listFilter.md +0 -897
- package/docs/use/listInstance.md +0 -559
- package/docs/use/listKeys.md +0 -91
- package/docs/use/listRelated.md +0 -706
- package/docs/use/listSearch.md +0 -903
- package/docs/use/listSort.md +0 -1171
- package/docs/use/listSubscription.md +0 -393
- package/docs/use/loadingError.md +0 -115
- package/docs/use/object.md +0 -668
- package/docs/use/objectCalculated.md +0 -741
- package/docs/use/objectInstance.md +0 -685
- package/docs/use/objectRelated.md +0 -723
- package/docs/use/objectSubscription.md +0 -538
- package/docs/use/paginatedListInstance.md +0 -155
- package/docs/use/proxyLoadingError.md +0 -51
- package/docs/use/search.md +0 -321
- package/docs/use/watchesRunning.md +0 -84
- package/docs/utils/assignReactiveObject.md +0 -413
- package/docs/utils/classes.md +0 -139
- package/docs/utils/compact.md +0 -67
- package/docs/utils/deleteKey.md +0 -61
- package/docs/utils/flattenPaths.md +0 -53
- package/docs/utils/getFakePk.md +0 -39
- package/docs/utils/keepAliveTry.md +0 -59
- package/docs/utils/keyDiff.md +0 -117
- package/docs/utils/loadingCombine.md +0 -30
- package/docs/utils/proxyRunning.md +0 -39
- package/docs/utils/relatedCalculatedHelpers.md +0 -93
- package/docs/utils/set.md +0 -223
- package/docs/utils/transformWalk.md +0 -68
- package/docs/utils/watches.md +0 -489
- package/eslint.config.js +0 -125
- package/lint-staged.config.js +0 -10
- package/makeTypeDoc.sh +0 -25
- package/make_type_doc.js +0 -59
- package/tests/unit/config/listCrud.spec.js +0 -114
- package/tests/unit/config/objectCrud.spec.js +0 -160
- package/tests/unit/crudPromise.js +0 -40
- package/tests/unit/expectHelpers.js +0 -6
- package/tests/unit/mockOnUnmounted.js +0 -9
- package/tests/unit/poll.js +0 -50
- package/tests/unit/use/cancellableIntent.spec.js +0 -152
- package/tests/unit/use/listCalculated.spec.js +0 -135
- package/tests/unit/use/listFilter.spec.js +0 -484
- package/tests/unit/use/listInstance.spec.js +0 -1166
- package/tests/unit/use/listRelated.spec.js +0 -260
- package/tests/unit/use/listSearch.spec.js +0 -586
- package/tests/unit/use/listSort.spec.js +0 -418
- package/tests/unit/use/listSubscription.spec.js +0 -845
- package/tests/unit/use/loadingError.spec.js +0 -43
- package/tests/unit/use/objectInstance.spec.js +0 -1525
- package/tests/unit/use/objectSubscription.spec.js +0 -849
- package/tests/unit/use/proxyLoadingError.spec.js +0 -64
- package/tests/unit/use/search.spec.js +0 -248
- package/tests/unit/utils/assignReactiveObject.spec.js +0 -593
- package/tests/unit/utils/classes.spec.js +0 -427
- package/tests/unit/utils/deleteKey.spec.js +0 -265
- package/tests/unit/utils/flattenPaths.spec.js +0 -126
- package/tests/unit/utils/keyDiff.spec.js +0 -110
- package/tests/unit/utils/set.spec.js +0 -81
- package/tests/unit/utils/watches.spec.js +0 -276
- package/tsconfig.json +0 -19
- package/typedoc-local-plugins/customize-output.js +0 -13
- package/typedoc.json +0 -11
- package/vitest.config.js +0 -11
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { useProxyLoadingError } from "../../../use/proxyLoadingError.js";
|
|
2
|
-
import { ref } from "vue";
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
|
|
5
|
-
describe("useProxyLoadingError", () => {
|
|
6
|
-
let loadingError1, loadingError2;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
loadingError1 = {
|
|
10
|
-
loading: ref(false),
|
|
11
|
-
error: ref(null),
|
|
12
|
-
errored: ref(false),
|
|
13
|
-
clearError: vi.fn(),
|
|
14
|
-
};
|
|
15
|
-
loadingError2 = {
|
|
16
|
-
loading: ref(false),
|
|
17
|
-
error: ref(null),
|
|
18
|
-
errored: ref(false),
|
|
19
|
-
clearError: vi.fn(),
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should initialize with default states when no errors", () => {
|
|
24
|
-
const proxyLoadingError = useProxyLoadingError([loadingError1, loadingError2]);
|
|
25
|
-
expect(proxyLoadingError.loading.value).toBe(false);
|
|
26
|
-
expect(proxyLoadingError.error.value).toBe(null);
|
|
27
|
-
expect(proxyLoadingError.errored.value).toBe(false);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should reflect loading state when one source is loading", () => {
|
|
31
|
-
loadingError1.loading.value = true;
|
|
32
|
-
const proxyLoadingError = useProxyLoadingError([loadingError1, loadingError2]);
|
|
33
|
-
expect(proxyLoadingError.loading.value).toBe(true);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("should reflect error state when one source has an error", () => {
|
|
37
|
-
const error = new Error("Test Error");
|
|
38
|
-
loadingError2.error.value = error;
|
|
39
|
-
loadingError2.errored.value = true;
|
|
40
|
-
const proxyLoadingError = useProxyLoadingError([loadingError1, loadingError2]);
|
|
41
|
-
expect(proxyLoadingError.error.value).toBe(error);
|
|
42
|
-
expect(proxyLoadingError.errored.value).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should clear all errors when clearError is called", () => {
|
|
46
|
-
const proxyLoadingError = useProxyLoadingError([loadingError1, loadingError2]);
|
|
47
|
-
proxyLoadingError.clearError();
|
|
48
|
-
expect(loadingError1.clearError).toHaveBeenCalled();
|
|
49
|
-
expect(loadingError2.clearError).toHaveBeenCalled();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should reflect correct aggregate state when combining multiple sources", () => {
|
|
53
|
-
loadingError1.loading.value = true;
|
|
54
|
-
loadingError2.errored.value = true;
|
|
55
|
-
const error = new Error("Another Error");
|
|
56
|
-
loadingError2.error.value = error;
|
|
57
|
-
|
|
58
|
-
const proxyLoadingError = useProxyLoadingError([loadingError1, loadingError2]);
|
|
59
|
-
|
|
60
|
-
expect(proxyLoadingError.loading.value).toBe(true); // One source is loading
|
|
61
|
-
expect(proxyLoadingError.errored.value).toBe(true); // One source has an error
|
|
62
|
-
expect(proxyLoadingError.error.value).toBe(error); // Error is aggregated
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { doAwaitNot } from "../../../utils/watches.js";
|
|
2
|
-
import { reactive } from "vue";
|
|
3
|
-
|
|
4
|
-
describe("use/search", () => {
|
|
5
|
-
let useSearch;
|
|
6
|
-
beforeEach(async () => {
|
|
7
|
-
const searchModule = await import("../../../use/search.js");
|
|
8
|
-
useSearch = searchModule.useSearch;
|
|
9
|
-
});
|
|
10
|
-
it("should allow adding items to the index", async () => {
|
|
11
|
-
const search = useSearch({
|
|
12
|
-
props: reactive({
|
|
13
|
-
customDocumentOptions: {
|
|
14
|
-
tokenize: "forward",
|
|
15
|
-
document: {
|
|
16
|
-
index: ["field1", "field2"],
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
pkKey: "notId",
|
|
20
|
-
}),
|
|
21
|
-
throttle: 50,
|
|
22
|
-
});
|
|
23
|
-
search.addIndex({
|
|
24
|
-
notId: 1,
|
|
25
|
-
field1: "test index value field1 one",
|
|
26
|
-
field2: "test index value field2 one",
|
|
27
|
-
});
|
|
28
|
-
search.addIndex({
|
|
29
|
-
notId: 2,
|
|
30
|
-
field1: "test index value field1 two",
|
|
31
|
-
field2: "test index value field2 two",
|
|
32
|
-
});
|
|
33
|
-
search.addIndex({
|
|
34
|
-
notId: 3,
|
|
35
|
-
field1: "test index value field1 three",
|
|
36
|
-
field2: "test index value field2 three",
|
|
37
|
-
});
|
|
38
|
-
await doAwaitNot({
|
|
39
|
-
obj: search.state,
|
|
40
|
-
prop: "running",
|
|
41
|
-
});
|
|
42
|
-
expect(Object.keys(search.state.results)).toEqual([]);
|
|
43
|
-
search.state.search = "test";
|
|
44
|
-
await doAwaitNot({
|
|
45
|
-
obj: search.state,
|
|
46
|
-
prop: "running",
|
|
47
|
-
});
|
|
48
|
-
expect(Object.keys(search.state.results)).toEqual(["1", "2", "3"]);
|
|
49
|
-
});
|
|
50
|
-
it("should allow removing items from the index", async () => {
|
|
51
|
-
const search = useSearch({
|
|
52
|
-
props: reactive({
|
|
53
|
-
customDocumentOptions: {
|
|
54
|
-
tokenize: "forward",
|
|
55
|
-
document: {
|
|
56
|
-
index: ["field1", "field2"],
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
pkKey: "notPk",
|
|
60
|
-
}),
|
|
61
|
-
throttle: 50,
|
|
62
|
-
});
|
|
63
|
-
search.addIndex({
|
|
64
|
-
notPk: 1,
|
|
65
|
-
field1: "test index value field1 one",
|
|
66
|
-
field2: "test index value field2 one",
|
|
67
|
-
});
|
|
68
|
-
search.addIndex({
|
|
69
|
-
notPk: 2,
|
|
70
|
-
field1: "test index value field1 two",
|
|
71
|
-
field2: "test index value field2 two",
|
|
72
|
-
});
|
|
73
|
-
search.addIndex({
|
|
74
|
-
notPk: 3,
|
|
75
|
-
field1: "test index value field1 three",
|
|
76
|
-
field2: "test index value field2 three",
|
|
77
|
-
});
|
|
78
|
-
search.state.search = "test";
|
|
79
|
-
await doAwaitNot({
|
|
80
|
-
obj: search.state,
|
|
81
|
-
prop: "running",
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
expect(Object.keys(search.state.results)).toEqual(["1", "2", "3"]);
|
|
85
|
-
search.removeIndex(2);
|
|
86
|
-
await doAwaitNot({
|
|
87
|
-
obj: search.state,
|
|
88
|
-
prop: "running",
|
|
89
|
-
});
|
|
90
|
-
expect(Object.keys(search.state.results)).toEqual(["1", "3"]);
|
|
91
|
-
});
|
|
92
|
-
it("should allow updating items in the index", async () => {
|
|
93
|
-
const search = useSearch({
|
|
94
|
-
props: reactive({
|
|
95
|
-
customDocumentOptions: {
|
|
96
|
-
tokenize: "forward",
|
|
97
|
-
document: {
|
|
98
|
-
index: ["field1", "field2"],
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
pkKey: "id",
|
|
102
|
-
}),
|
|
103
|
-
throttle: 50,
|
|
104
|
-
});
|
|
105
|
-
search.addIndex({
|
|
106
|
-
id: 1,
|
|
107
|
-
field1: "test index value field1 one",
|
|
108
|
-
field2: "test index value field2 one",
|
|
109
|
-
});
|
|
110
|
-
search.addIndex({
|
|
111
|
-
id: 2,
|
|
112
|
-
field1: "test index value field1 two",
|
|
113
|
-
field2: "test index value field2 two",
|
|
114
|
-
});
|
|
115
|
-
search.addIndex({
|
|
116
|
-
id: 3,
|
|
117
|
-
field1: "test index value field1 three",
|
|
118
|
-
field2: "test index value field2 three",
|
|
119
|
-
});
|
|
120
|
-
search.state.search = "test";
|
|
121
|
-
await doAwaitNot({
|
|
122
|
-
obj: search.state,
|
|
123
|
-
prop: "running",
|
|
124
|
-
});
|
|
125
|
-
expect(Object.keys(search.state.results)).toEqual(["1", "2", "3"]);
|
|
126
|
-
search.updateIndex({
|
|
127
|
-
id: 2,
|
|
128
|
-
field1: "twest index value field1 two updated",
|
|
129
|
-
field2: "twest index value field2 two updated",
|
|
130
|
-
});
|
|
131
|
-
await doAwaitNot({
|
|
132
|
-
obj: search.state,
|
|
133
|
-
prop: "running",
|
|
134
|
-
});
|
|
135
|
-
expect(Object.keys(search.state.results)).toEqual(["1", "3"]);
|
|
136
|
-
search.state.search = "two";
|
|
137
|
-
await doAwaitNot({
|
|
138
|
-
obj: search.state,
|
|
139
|
-
prop: "running",
|
|
140
|
-
});
|
|
141
|
-
expect(Object.keys(search.state.results)).toEqual(["2"]);
|
|
142
|
-
});
|
|
143
|
-
it("should allow clearing all items from the index", async () => {
|
|
144
|
-
const search = useSearch({
|
|
145
|
-
props: reactive({
|
|
146
|
-
customDocumentOptions: {
|
|
147
|
-
tokenize: "forward",
|
|
148
|
-
document: {
|
|
149
|
-
index: ["field1", "field2"],
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
pkKey: "id",
|
|
153
|
-
}),
|
|
154
|
-
throttle: 50,
|
|
155
|
-
});
|
|
156
|
-
search.addIndex({
|
|
157
|
-
id: 1,
|
|
158
|
-
field1: "test index value field1 one",
|
|
159
|
-
field2: "test index value field2 one",
|
|
160
|
-
});
|
|
161
|
-
search.addIndex({
|
|
162
|
-
id: 2,
|
|
163
|
-
field1: "test index value field1 two",
|
|
164
|
-
field2: "test index value field2 two",
|
|
165
|
-
});
|
|
166
|
-
search.addIndex({
|
|
167
|
-
id: 3,
|
|
168
|
-
field1: "test index value field1 three",
|
|
169
|
-
field2: "test index value field2 three",
|
|
170
|
-
});
|
|
171
|
-
search.state.search = "test";
|
|
172
|
-
await doAwaitNot({
|
|
173
|
-
obj: search.state,
|
|
174
|
-
prop: "running",
|
|
175
|
-
});
|
|
176
|
-
expect(Object.keys(search.state.results)).toEqual(["1", "2", "3"]);
|
|
177
|
-
search.clearIndex();
|
|
178
|
-
expect(Object.keys(search.state.results)).toEqual([]);
|
|
179
|
-
});
|
|
180
|
-
it("should allow changing the index fields", async () => {
|
|
181
|
-
const searchProps = reactive({
|
|
182
|
-
customDocumentOptions: {
|
|
183
|
-
tokenize: "forward",
|
|
184
|
-
document: {
|
|
185
|
-
index: ["field1", "field2"],
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
pkKey: "id",
|
|
189
|
-
});
|
|
190
|
-
const search = useSearch({
|
|
191
|
-
props: searchProps,
|
|
192
|
-
throttle: 50,
|
|
193
|
-
});
|
|
194
|
-
search.addIndex({
|
|
195
|
-
id: 1,
|
|
196
|
-
field1: "test index value field1 one",
|
|
197
|
-
field2: "test index value field2 one",
|
|
198
|
-
});
|
|
199
|
-
search.addIndex({
|
|
200
|
-
id: 2,
|
|
201
|
-
field1: "test index value field1 two",
|
|
202
|
-
field2: "test index value field2 two",
|
|
203
|
-
});
|
|
204
|
-
search.addIndex({
|
|
205
|
-
id: 3,
|
|
206
|
-
field1: "test index value field1 three",
|
|
207
|
-
field2: "test index value field2 three",
|
|
208
|
-
});
|
|
209
|
-
search.state.search = "field2";
|
|
210
|
-
await doAwaitNot({
|
|
211
|
-
obj: search.state,
|
|
212
|
-
prop: "running",
|
|
213
|
-
});
|
|
214
|
-
expect(Object.keys(search.state.results)).toEqual(["1", "2", "3"]);
|
|
215
|
-
// implied clearIndex
|
|
216
|
-
searchProps.customDocumentOptions.document.index = ["field1"];
|
|
217
|
-
// indexes cannot be added until search.events newIndex is fired
|
|
218
|
-
let eventResolve = null;
|
|
219
|
-
const eventPromise = new Promise((resolve) => {
|
|
220
|
-
eventResolve = resolve;
|
|
221
|
-
});
|
|
222
|
-
search.events.addEventListener("newIndex", eventResolve);
|
|
223
|
-
await eventPromise;
|
|
224
|
-
search.addIndex({
|
|
225
|
-
id: 1,
|
|
226
|
-
field1: "test index value field1 one",
|
|
227
|
-
});
|
|
228
|
-
search.addIndex({
|
|
229
|
-
id: 2,
|
|
230
|
-
field1: "test index value field1 two",
|
|
231
|
-
});
|
|
232
|
-
search.addIndex({
|
|
233
|
-
id: 3,
|
|
234
|
-
field1: "test index value field1 three",
|
|
235
|
-
});
|
|
236
|
-
await doAwaitNot({
|
|
237
|
-
obj: search.state,
|
|
238
|
-
prop: "running",
|
|
239
|
-
});
|
|
240
|
-
expect(Object.keys(search.state.results)).toEqual([]);
|
|
241
|
-
search.state.search = "field1";
|
|
242
|
-
await doAwaitNot({
|
|
243
|
-
obj: search.state,
|
|
244
|
-
prop: "running",
|
|
245
|
-
});
|
|
246
|
-
expect(Object.keys(search.state.results)).toEqual(["1", "2", "3"]);
|
|
247
|
-
});
|
|
248
|
-
});
|