@promoboxx/use-filter 1.0.5 → 1.2.0
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/CHANGELOG.md +21 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/memoryStore.js +8 -0
- package/dist/useFilter.d.ts +4 -3
- package/dist/useFilter.js +9 -2
- package/package.json +2 -6
- package/dist/lib/shallowEqual.test.d.ts +0 -1
- package/dist/lib/shallowEqual.test.js +0 -54
- package/dist/useFilter.test.d.ts +0 -1
- package/dist/useFilter.test.js +0 -581
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## 1.2.0 (2021-07-16)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* Add localStorageStore ([#4](https://github.com/promoboxx/use-filter/issues/4)) ([a6087e2](https://github.com/promoboxx/use-filter/commit/a6087e2f07a3640799b840e128b96838cd8ef150))
|
|
11
|
+
|
|
12
|
+
## 1.1.0 (2021-07-16)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* Add concept of data to useFilter ([#2](https://github.com/promoboxx/use-filter/issues/2)) ([563c5a9](https://github.com/promoboxx/use-filter/commit/563c5a959cdc22a0f8eba9dbb3dde7802df02b46))
|
|
18
|
+
|
|
19
|
+
### 1.0.6 (2021-07-16)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* dont deploy test files ([500151c](https://github.com/promoboxx/use-filter/commit/500151c04f75139c71baf29b2ad2dccefcd57db7))
|
|
25
|
+
|
|
5
26
|
### 1.0.5 (2021-07-16)
|
|
6
27
|
|
|
7
28
|
|
package/dist/store/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { FilterInfo } from '../useFilter';
|
|
|
2
2
|
export interface FilterStore {
|
|
3
3
|
getFilter(namespace: string): FilterInfo<any> | null | undefined;
|
|
4
4
|
saveFilter(namespace: string, filter: FilterInfo<any>): void;
|
|
5
|
+
getData(namespace: string): any | null | undefined;
|
|
6
|
+
saveData(namespace: string, data: any): void;
|
|
5
7
|
clear(): void;
|
|
6
8
|
}
|
|
7
9
|
export declare function setFilterStore(newStore: FilterStore): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var filters = {};
|
|
4
|
+
var data = {};
|
|
4
5
|
var memoryStore = {
|
|
5
6
|
getFilter: function (namespace) {
|
|
6
7
|
return filters[namespace];
|
|
@@ -8,8 +9,15 @@ var memoryStore = {
|
|
|
8
9
|
saveFilter: function (namespace, filter) {
|
|
9
10
|
filters[namespace] = filter;
|
|
10
11
|
},
|
|
12
|
+
getData: function (namespace) {
|
|
13
|
+
return data[namespace];
|
|
14
|
+
},
|
|
15
|
+
saveData: function (namespace, data) {
|
|
16
|
+
filters[namespace] = data;
|
|
17
|
+
},
|
|
11
18
|
clear: function () {
|
|
12
19
|
filters = {};
|
|
20
|
+
data = {};
|
|
13
21
|
},
|
|
14
22
|
};
|
|
15
23
|
exports.default = memoryStore;
|
package/dist/useFilter.d.ts
CHANGED
|
@@ -5,11 +5,12 @@ interface UseFilterOptions<TFilter, TResult> {
|
|
|
5
5
|
onChange: (filterInfo: FilterInfo<TFilter>) => MaybePromise<UseFilterOnChangeResult<TFilter, TResult>>;
|
|
6
6
|
debounceDuration?: number;
|
|
7
7
|
}
|
|
8
|
-
declare function useFilter<
|
|
8
|
+
declare function useFilter<TFilter, TResult>(namespace: string, options: UseFilterOptions<TFilter, TResult>): {
|
|
9
9
|
isLoading: boolean;
|
|
10
|
+
data: TResult | null | undefined;
|
|
10
11
|
doesFilterExist: boolean;
|
|
11
|
-
filterInfo: FilterInfo<
|
|
12
|
-
updateFilter(filter:
|
|
12
|
+
filterInfo: FilterInfo<TFilter>;
|
|
13
|
+
updateFilter(filter: Partial<TFilter>): void;
|
|
13
14
|
resetFilter(): void;
|
|
14
15
|
setOffset(offset: number | string): void;
|
|
15
16
|
setPage(page: number | string): void;
|
package/dist/useFilter.js
CHANGED
|
@@ -33,6 +33,9 @@ var shallowEqual_1 = __importDefault(require("./lib/shallowEqual"));
|
|
|
33
33
|
var store_1 = require("./store");
|
|
34
34
|
function useFilter(namespace, options) {
|
|
35
35
|
var _a = react_1.useState(function () { return store_1.getFilterStore().getFilter(namespace); }), filterInfo = _a[0], setFilterInfoState = _a[1];
|
|
36
|
+
var _b = react_1.useState(function () {
|
|
37
|
+
return store_1.getFilterStore().getData(namespace);
|
|
38
|
+
}), data = _b[0], setData = _b[1];
|
|
36
39
|
var setFilterInfo = react_1.useCallback(function (filterInfo, skipFetch) {
|
|
37
40
|
if (skipFetch === void 0) { skipFetch = false; }
|
|
38
41
|
setFilterInfoState(function (previousFilterInfo) {
|
|
@@ -55,7 +58,7 @@ function useFilter(namespace, options) {
|
|
|
55
58
|
debounceDuration: options.debounceDuration,
|
|
56
59
|
defaultFilterInfo: options.defaultFilterInfo,
|
|
57
60
|
});
|
|
58
|
-
var
|
|
61
|
+
var _c = react_1.useState(!filterInfo), isLoading = _c[0], setIsLoading = _c[1];
|
|
59
62
|
var doesFilterExist = react_1.useRef(!!filterInfo);
|
|
60
63
|
var lastRefreshAtRef = react_1.useRef(
|
|
61
64
|
// if shouldForceRunOnMount is set, always use -1
|
|
@@ -113,9 +116,12 @@ function useFilter(namespace, options) {
|
|
|
113
116
|
extra.totalResults = Number(totalResults);
|
|
114
117
|
extra.totalPages = Math.ceil(extra.totalResults / pageSizeNumber);
|
|
115
118
|
}
|
|
116
|
-
// TODO Don't do anther request here????
|
|
117
119
|
setFilterInfo(__assign(__assign(__assign({}, filterInfo), filterInfoFromResponse), extra), true);
|
|
118
120
|
}
|
|
121
|
+
if (response.data) {
|
|
122
|
+
setData(response.data);
|
|
123
|
+
store_1.getFilterStore().saveData(namespace, response.data);
|
|
124
|
+
}
|
|
119
125
|
}
|
|
120
126
|
if (isPromise(response)) {
|
|
121
127
|
response.then(handleResponse).finally(function () { return setIsLoading(false); });
|
|
@@ -135,6 +141,7 @@ function useFilter(namespace, options) {
|
|
|
135
141
|
}, [filterInfo, setFilterInfo, namespace]);
|
|
136
142
|
return {
|
|
137
143
|
isLoading: isLoading,
|
|
144
|
+
data: data,
|
|
138
145
|
doesFilterExist: doesFilterExist.current,
|
|
139
146
|
filterInfo: filterInfo || buildDefaultFilterInfo_1.default(options.defaultFilterInfo),
|
|
140
147
|
updateFilter: function (filter) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promoboxx/use-filter",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/useFilter.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,16 +30,12 @@
|
|
|
30
30
|
"dist/store/memoryStore.d.ts",
|
|
31
31
|
"dist/useFilter.js",
|
|
32
32
|
"dist/lib/buildDefaultFilterInfo.js",
|
|
33
|
-
"dist/lib/shallowEqual.test.js",
|
|
34
33
|
"dist/lib/shallowEqual.js",
|
|
35
34
|
"dist/lib/getOffsetFromPage.js",
|
|
36
35
|
"dist/lib/buildDefaultFilterInfo.d.ts",
|
|
37
|
-
"dist/lib/shallowEqual.test.d.ts",
|
|
38
36
|
"dist/lib/getOffsetFromPage.d.ts",
|
|
39
37
|
"dist/lib/getPageFromOffset.js",
|
|
40
38
|
"dist/lib/shallowEqual.d.ts",
|
|
41
|
-
"dist/lib/getPageFromOffset.d.ts"
|
|
42
|
-
"dist/useFilter.test.d.ts",
|
|
43
|
-
"dist/useFilter.test.js"
|
|
39
|
+
"dist/lib/getPageFromOffset.d.ts"
|
|
44
40
|
]
|
|
45
41
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var shallowEqual_1 = __importDefault(require("./shallowEqual"));
|
|
7
|
-
describe('shallowEqual', function () {
|
|
8
|
-
it('should return true if arguments fields are equal', function () {
|
|
9
|
-
expect(shallowEqual_1.default({ a: 1, b: 2, c: undefined }, { a: 1, b: 2, c: undefined })).toBe(true);
|
|
10
|
-
expect(shallowEqual_1.default({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(true);
|
|
11
|
-
var o = {};
|
|
12
|
-
expect(shallowEqual_1.default({ a: 1, b: 2, c: o }, { a: 1, b: 2, c: o })).toBe(true);
|
|
13
|
-
var d = function () {
|
|
14
|
-
return 1;
|
|
15
|
-
};
|
|
16
|
-
expect(shallowEqual_1.default({ a: 1, b: 2, c: o, d: d }, { a: 1, b: 2, c: o, d: d })).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
it('should return false if arguments fields are different function identities', function () {
|
|
19
|
-
expect(shallowEqual_1.default({
|
|
20
|
-
a: 1,
|
|
21
|
-
b: 2,
|
|
22
|
-
d: function () {
|
|
23
|
-
return 1;
|
|
24
|
-
},
|
|
25
|
-
}, {
|
|
26
|
-
a: 1,
|
|
27
|
-
b: 2,
|
|
28
|
-
d: function () {
|
|
29
|
-
return 1;
|
|
30
|
-
},
|
|
31
|
-
})).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
it('should return false if first argument has too many keys', function () {
|
|
34
|
-
expect(shallowEqual_1.default({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 })).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
it('should return false if second argument has too many keys', function () {
|
|
37
|
-
expect(shallowEqual_1.default({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 })).toBe(false);
|
|
38
|
-
});
|
|
39
|
-
it('should return false if arguments have different keys', function () {
|
|
40
|
-
expect(shallowEqual_1.default({ a: 1, b: 2, c: undefined }, { a: 1, bb: 2, c: undefined })).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
it('should compare two NaN values', function () {
|
|
43
|
-
expect(shallowEqual_1.default(NaN, NaN)).toBe(true);
|
|
44
|
-
});
|
|
45
|
-
it('should compare empty objects, with false', function () {
|
|
46
|
-
expect(shallowEqual_1.default({}, false)).toBe(false);
|
|
47
|
-
expect(shallowEqual_1.default(false, {})).toBe(false);
|
|
48
|
-
expect(shallowEqual_1.default([], false)).toBe(false);
|
|
49
|
-
expect(shallowEqual_1.default(false, [])).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
it('should compare two zero values', function () {
|
|
52
|
-
expect(shallowEqual_1.default(0, 0)).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
});
|
package/dist/useFilter.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/useFilter.test.js
DELETED
|
@@ -1,581 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
-
function step(op) {
|
|
35
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
-
while (_) try {
|
|
37
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
-
switch (op[0]) {
|
|
40
|
-
case 0: case 1: t = op; break;
|
|
41
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
-
default:
|
|
45
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
-
if (t[2]) _.ops.pop();
|
|
50
|
-
_.trys.pop(); continue;
|
|
51
|
-
}
|
|
52
|
-
op = body.call(thisArg, _);
|
|
53
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
58
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
59
|
-
};
|
|
60
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
-
var react_1 = require("@testing-library/react");
|
|
62
|
-
var react_2 = __importStar(require("react"));
|
|
63
|
-
var buildDefaultFilterInfo_1 = __importDefault(require("./lib/buildDefaultFilterInfo"));
|
|
64
|
-
var store_1 = require("./store");
|
|
65
|
-
var memoryStore_1 = __importDefault(require("./store/memoryStore"));
|
|
66
|
-
var useFilter_1 = __importDefault(require("./useFilter"));
|
|
67
|
-
describe('useFilter', function () {
|
|
68
|
-
var defaultFilterInfo = buildDefaultFilterInfo_1.default({
|
|
69
|
-
filter: {
|
|
70
|
-
foo: 'bar',
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
it('calls on mount', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
-
var onChangeMock;
|
|
75
|
-
return __generator(this, function (_a) {
|
|
76
|
-
switch (_a.label) {
|
|
77
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })];
|
|
78
|
-
case 1:
|
|
79
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
80
|
-
expect(onChangeMock).toHaveBeenCalledTimes(1);
|
|
81
|
-
expect(onChangeMock).toHaveBeenLastCalledWith(expect.objectContaining({ filter: { foo: 'bar' } }));
|
|
82
|
-
return [2 /*return*/];
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}); });
|
|
86
|
-
it('calls when data changes', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
87
|
-
var onChangeMock;
|
|
88
|
-
return __generator(this, function (_a) {
|
|
89
|
-
switch (_a.label) {
|
|
90
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })];
|
|
91
|
-
case 1:
|
|
92
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
93
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
94
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('updateFilterButton'));
|
|
95
|
-
})];
|
|
96
|
-
case 2:
|
|
97
|
-
_a.sent();
|
|
98
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
99
|
-
expect(onChangeMock).toHaveBeenLastCalledWith(expect.objectContaining({ filter: { foo: '42' } }));
|
|
100
|
-
return [2 /*return*/];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}); });
|
|
104
|
-
it('uses shallowEqual be default', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
105
|
-
var onChangeMock;
|
|
106
|
-
return __generator(this, function (_a) {
|
|
107
|
-
switch (_a.label) {
|
|
108
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })];
|
|
109
|
-
case 1:
|
|
110
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
111
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
112
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('updateFilterButton'));
|
|
113
|
-
})];
|
|
114
|
-
case 2:
|
|
115
|
-
_a.sent();
|
|
116
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
117
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('updateFilterButton'));
|
|
118
|
-
})
|
|
119
|
-
// 2 is still the correct number of times, as there is one from the initial
|
|
120
|
-
// mount and the other from updateFilter.
|
|
121
|
-
];
|
|
122
|
-
case 3:
|
|
123
|
-
_a.sent();
|
|
124
|
-
// 2 is still the correct number of times, as there is one from the initial
|
|
125
|
-
// mount and the other from updateFilter.
|
|
126
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
127
|
-
return [2 /*return*/];
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}); });
|
|
131
|
-
it('can reset and keeps defaults', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
|
-
var onChangeMock;
|
|
133
|
-
return __generator(this, function (_a) {
|
|
134
|
-
switch (_a.label) {
|
|
135
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })];
|
|
136
|
-
case 1:
|
|
137
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
138
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
139
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('resetFilterButton'));
|
|
140
|
-
})];
|
|
141
|
-
case 2:
|
|
142
|
-
_a.sent();
|
|
143
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
144
|
-
expect(onChangeMock).toHaveBeenLastCalledWith(expect.objectContaining({ filter: { foo: 'bar' } }));
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}); });
|
|
149
|
-
it('can setSort', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
150
|
-
var onChangeMock;
|
|
151
|
-
return __generator(this, function (_a) {
|
|
152
|
-
switch (_a.label) {
|
|
153
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })];
|
|
154
|
-
case 1:
|
|
155
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
156
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
157
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('setSortButton'));
|
|
158
|
-
})];
|
|
159
|
-
case 2:
|
|
160
|
-
_a.sent();
|
|
161
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
162
|
-
expect(onChangeMock).toHaveBeenLastCalledWith(expect.objectContaining({ filter: { foo: 'bar' }, sort: 'foo:bar' }));
|
|
163
|
-
return [2 /*return*/];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}); });
|
|
167
|
-
it('renders the current filter', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
-
return __generator(this, function (_a) {
|
|
169
|
-
switch (_a.label) {
|
|
170
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })];
|
|
171
|
-
case 1:
|
|
172
|
-
_a.sent();
|
|
173
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ filter: { foo: 'bar' } }));
|
|
174
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
175
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('updateFilterButton'));
|
|
176
|
-
})];
|
|
177
|
-
case 2:
|
|
178
|
-
_a.sent();
|
|
179
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ filter: { foo: '42' } }));
|
|
180
|
-
return [2 /*return*/];
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}); });
|
|
184
|
-
it('handles onChange.filterInfo', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
185
|
-
var onChangeMock;
|
|
186
|
-
return __generator(this, function (_a) {
|
|
187
|
-
switch (_a.label) {
|
|
188
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })];
|
|
189
|
-
case 1:
|
|
190
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
191
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ totalResults: 1 }));
|
|
192
|
-
// Say the server response with a new totalResults.
|
|
193
|
-
onChangeMock.mockImplementation(function () { return ({
|
|
194
|
-
filterInfo: {
|
|
195
|
-
totalResults: 100,
|
|
196
|
-
},
|
|
197
|
-
}); });
|
|
198
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
199
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('forceRefreshButton'));
|
|
200
|
-
})];
|
|
201
|
-
case 2:
|
|
202
|
-
_a.sent();
|
|
203
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ totalResults: 100 }));
|
|
204
|
-
return [2 /*return*/];
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
}); });
|
|
208
|
-
it('handles onChange.filterInfo.totalResults', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
209
|
-
var onChangeMock;
|
|
210
|
-
return __generator(this, function (_a) {
|
|
211
|
-
switch (_a.label) {
|
|
212
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })
|
|
213
|
-
// Say the server response with a new totalResults.
|
|
214
|
-
];
|
|
215
|
-
case 1:
|
|
216
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
217
|
-
// Say the server response with a new totalResults.
|
|
218
|
-
onChangeMock.mockImplementation(function () { return ({
|
|
219
|
-
filterInfo: {
|
|
220
|
-
totalResults: 99,
|
|
221
|
-
},
|
|
222
|
-
}); });
|
|
223
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
224
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('forceRefreshButton'));
|
|
225
|
-
})];
|
|
226
|
-
case 2:
|
|
227
|
-
_a.sent();
|
|
228
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ totalResults: 99 }));
|
|
229
|
-
return [2 /*return*/];
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
}); });
|
|
233
|
-
// it("handles onChange.data", async () => {
|
|
234
|
-
// onChangeMock.mockImplementation((filterInfo) => ({
|
|
235
|
-
// data: [{ name: filterInfo.filter.foo }],
|
|
236
|
-
// }));
|
|
237
|
-
// getByTestId(wrapper, "updateFilterButton").simulate("click");
|
|
238
|
-
// await actWrapperUpdate(wrapper);
|
|
239
|
-
// expect(JSON.parse(getByTestId(wrapper, "responseDataJson").text())).toEqual(
|
|
240
|
-
// [{ name: "42" }]
|
|
241
|
-
// );
|
|
242
|
-
// getByTestId(wrapper, "resetFilterButton").simulate("click");
|
|
243
|
-
// await actWrapperUpdate(wrapper);
|
|
244
|
-
// expect(JSON.parse(getByTestId(wrapper, "responseDataJson").text())).toEqual(
|
|
245
|
-
// [{ name: "bar" }]
|
|
246
|
-
// );
|
|
247
|
-
// });
|
|
248
|
-
it('handles async onChange.filterInfo', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
249
|
-
var onChangeMock;
|
|
250
|
-
return __generator(this, function (_a) {
|
|
251
|
-
switch (_a.label) {
|
|
252
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })];
|
|
253
|
-
case 1:
|
|
254
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
255
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ totalResults: 1 }));
|
|
256
|
-
// Say the server response with a new totalResults.
|
|
257
|
-
onChangeMock.mockImplementation(function () {
|
|
258
|
-
return Promise.resolve({
|
|
259
|
-
filterInfo: {
|
|
260
|
-
totalResults: 100,
|
|
261
|
-
},
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
265
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('forceRefreshButton'));
|
|
266
|
-
})];
|
|
267
|
-
case 2:
|
|
268
|
-
_a.sent();
|
|
269
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ totalResults: 100 }));
|
|
270
|
-
return [2 /*return*/];
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}); });
|
|
274
|
-
it('handles async onChange.filterInfo.totalResults', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
275
|
-
var onChangeMock;
|
|
276
|
-
return __generator(this, function (_a) {
|
|
277
|
-
switch (_a.label) {
|
|
278
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo })
|
|
279
|
-
// Say the server response with a new totalResults.
|
|
280
|
-
];
|
|
281
|
-
case 1:
|
|
282
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
283
|
-
// Say the server response with a new totalResults.
|
|
284
|
-
onChangeMock.mockImplementation(function () {
|
|
285
|
-
return Promise.resolve({
|
|
286
|
-
filterInfo: {
|
|
287
|
-
totalResults: 99,
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
292
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('forceRefreshButton'));
|
|
293
|
-
})];
|
|
294
|
-
case 2:
|
|
295
|
-
_a.sent();
|
|
296
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ totalPages: 5 }));
|
|
297
|
-
return [2 /*return*/];
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
}); });
|
|
301
|
-
// it("handles async onChange.data", async () => {
|
|
302
|
-
// onChangeMock.mockImplementation((filterInfo) =>
|
|
303
|
-
// Promise.resolve({
|
|
304
|
-
// data: [{ name: filterInfo.filter.foo }],
|
|
305
|
-
// })
|
|
306
|
-
// );
|
|
307
|
-
// getByTestId(wrapper, "updateFilterButton").simulate("click");
|
|
308
|
-
// await actWrapperUpdate(wrapper);
|
|
309
|
-
// expect(JSON.parse(getByTestId(wrapper, "responseDataJson").text())).toEqual(
|
|
310
|
-
// [{ name: "42" }]
|
|
311
|
-
// );
|
|
312
|
-
// getByTestId(wrapper, "resetFilterButton").simulate("click");
|
|
313
|
-
// await actWrapperUpdate(wrapper);
|
|
314
|
-
// expect(JSON.parse(getByTestId(wrapper, "responseDataJson").text())).toEqual(
|
|
315
|
-
// [{ name: "bar" }]
|
|
316
|
-
// );
|
|
317
|
-
// });
|
|
318
|
-
it('persists across mounts', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
319
|
-
var _a, onChangeMock, ExampleComponent, ToggleComponent;
|
|
320
|
-
return __generator(this, function (_b) {
|
|
321
|
-
switch (_b.label) {
|
|
322
|
-
case 0: return [4 /*yield*/, setup({
|
|
323
|
-
defaultFilterInfo: defaultFilterInfo,
|
|
324
|
-
})];
|
|
325
|
-
case 1:
|
|
326
|
-
_a = _b.sent(), onChangeMock = _a.onChangeMock, ExampleComponent = _a.ExampleComponent;
|
|
327
|
-
ToggleComponent = function () {
|
|
328
|
-
var _a = react_2.useState(true), shouldShow = _a[0], setShouldShow = _a[1];
|
|
329
|
-
return (react_2.default.createElement("div", null,
|
|
330
|
-
react_2.default.createElement("button", { "data-testid": "toggleShouldShow", onClick: function () { return setShouldShow(!shouldShow); } }),
|
|
331
|
-
shouldShow ? react_2.default.createElement(ExampleComponent, null) : null));
|
|
332
|
-
};
|
|
333
|
-
// Simulate the filter being visible.
|
|
334
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
335
|
-
// Cleanup the render done in `setup`.
|
|
336
|
-
react_1.cleanup();
|
|
337
|
-
react_1.render(react_2.default.createElement(ToggleComponent, null));
|
|
338
|
-
})];
|
|
339
|
-
case 2:
|
|
340
|
-
// Simulate the filter being visible.
|
|
341
|
-
_b.sent();
|
|
342
|
-
expect(react_1.screen.queryByTestId('updateFilterButton')).toBeTruthy();
|
|
343
|
-
// Simulate removing the filter.
|
|
344
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
345
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('toggleShouldShow'));
|
|
346
|
-
})];
|
|
347
|
-
case 3:
|
|
348
|
-
// Simulate removing the filter.
|
|
349
|
-
_b.sent();
|
|
350
|
-
expect(react_1.screen.queryByTestId('updateFilterButton')).toBeFalsy();
|
|
351
|
-
// Simulate the filter being visible, again.
|
|
352
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
353
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('toggleShouldShow'));
|
|
354
|
-
})];
|
|
355
|
-
case 4:
|
|
356
|
-
// Simulate the filter being visible, again.
|
|
357
|
-
_b.sent();
|
|
358
|
-
expect(react_1.screen.queryByTestId('updateFilterButton')).toBeTruthy();
|
|
359
|
-
// onChange should still only be called once.
|
|
360
|
-
expect(onChangeMock).toHaveBeenCalledTimes(1);
|
|
361
|
-
return [2 /*return*/];
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
}); });
|
|
365
|
-
});
|
|
366
|
-
describe('page based', function () {
|
|
367
|
-
var defaultFilterInfo = buildDefaultFilterInfo_1.default({
|
|
368
|
-
filter: {
|
|
369
|
-
foo: 'bar',
|
|
370
|
-
},
|
|
371
|
-
pageSize: 20,
|
|
372
|
-
page: 2,
|
|
373
|
-
});
|
|
374
|
-
var children = function (wut) { return (react_2.default.createElement("button", { "data-testid": "setPageButton", onClick: function () { return wut.setPage(3); } })); };
|
|
375
|
-
it('accepts initial page', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
376
|
-
return __generator(this, function (_a) {
|
|
377
|
-
switch (_a.label) {
|
|
378
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo, children: children })];
|
|
379
|
-
case 1:
|
|
380
|
-
_a.sent();
|
|
381
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ page: 2, offset: 20 }));
|
|
382
|
-
return [2 /*return*/];
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
}); });
|
|
386
|
-
it('can set page', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
387
|
-
var onChangeMock;
|
|
388
|
-
return __generator(this, function (_a) {
|
|
389
|
-
switch (_a.label) {
|
|
390
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo, children: children })];
|
|
391
|
-
case 1:
|
|
392
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
393
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
394
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('setPageButton'));
|
|
395
|
-
})];
|
|
396
|
-
case 2:
|
|
397
|
-
_a.sent();
|
|
398
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
399
|
-
expect(onChangeMock).toHaveBeenLastCalledWith(expect.objectContaining({ page: 3, offset: 40 }));
|
|
400
|
-
return [2 /*return*/];
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
}); });
|
|
404
|
-
it('can handle onChange.filterInfo.page', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
405
|
-
var onChangeMock;
|
|
406
|
-
return __generator(this, function (_a) {
|
|
407
|
-
switch (_a.label) {
|
|
408
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo, children: children })
|
|
409
|
-
// Intentionally respond with numbers that don't match what the button
|
|
410
|
-
// actually does.
|
|
411
|
-
// This is to test the actual response, the view updates immediately.
|
|
412
|
-
];
|
|
413
|
-
case 1:
|
|
414
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
415
|
-
// Intentionally respond with numbers that don't match what the button
|
|
416
|
-
// actually does.
|
|
417
|
-
// This is to test the actual response, the view updates immediately.
|
|
418
|
-
onChangeMock.mockImplementation(function () { return ({
|
|
419
|
-
filterInfo: {
|
|
420
|
-
page: 20,
|
|
421
|
-
},
|
|
422
|
-
}); });
|
|
423
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
424
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('setPageButton'));
|
|
425
|
-
})];
|
|
426
|
-
case 2:
|
|
427
|
-
_a.sent();
|
|
428
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ page: 20, offset: 380 }));
|
|
429
|
-
return [2 /*return*/];
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
}); });
|
|
433
|
-
});
|
|
434
|
-
describe('offset based', function () {
|
|
435
|
-
var defaultFilterInfo = buildDefaultFilterInfo_1.default({
|
|
436
|
-
filter: {
|
|
437
|
-
foo: 'bar',
|
|
438
|
-
},
|
|
439
|
-
pageSize: 20,
|
|
440
|
-
offset: 80,
|
|
441
|
-
});
|
|
442
|
-
var children = function (wut) { return (react_2.default.createElement("button", { "data-testid": "setOffsetButton", onClick: function () { return wut.setOffset(100); } })); };
|
|
443
|
-
it('accepts initial offset', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
444
|
-
return __generator(this, function (_a) {
|
|
445
|
-
switch (_a.label) {
|
|
446
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo, children: children })];
|
|
447
|
-
case 1:
|
|
448
|
-
_a.sent();
|
|
449
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ offset: 80, page: 5 }));
|
|
450
|
-
return [2 /*return*/];
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
}); });
|
|
454
|
-
it('can set offset', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
455
|
-
var onChangeMock;
|
|
456
|
-
return __generator(this, function (_a) {
|
|
457
|
-
switch (_a.label) {
|
|
458
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo, children: children })];
|
|
459
|
-
case 1:
|
|
460
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
461
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
462
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('setOffsetButton'));
|
|
463
|
-
})];
|
|
464
|
-
case 2:
|
|
465
|
-
_a.sent();
|
|
466
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
467
|
-
expect(onChangeMock).toHaveBeenLastCalledWith(expect.objectContaining({ page: 6, offset: 100 }));
|
|
468
|
-
return [2 /*return*/];
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
}); });
|
|
472
|
-
it('can handle onChange.filterInfo.offset', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
473
|
-
var onChangeMock;
|
|
474
|
-
return __generator(this, function (_a) {
|
|
475
|
-
switch (_a.label) {
|
|
476
|
-
case 0: return [4 /*yield*/, setup({ defaultFilterInfo: defaultFilterInfo, children: children })
|
|
477
|
-
// Intentionally respond with numbers that don't match what the button
|
|
478
|
-
// actually does.
|
|
479
|
-
// This is to test the actual response, the view updates immediately.
|
|
480
|
-
];
|
|
481
|
-
case 1:
|
|
482
|
-
onChangeMock = (_a.sent()).onChangeMock;
|
|
483
|
-
// Intentionally respond with numbers that don't match what the button
|
|
484
|
-
// actually does.
|
|
485
|
-
// This is to test the actual response, the view updates immediately.
|
|
486
|
-
onChangeMock.mockImplementation(function () { return ({
|
|
487
|
-
filterInfo: {
|
|
488
|
-
offset: 380,
|
|
489
|
-
},
|
|
490
|
-
}); });
|
|
491
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
492
|
-
react_1.fireEvent.click(react_1.screen.getByTestId('setOffsetButton'));
|
|
493
|
-
})];
|
|
494
|
-
case 2:
|
|
495
|
-
_a.sent();
|
|
496
|
-
expect(safeJsonParse(react_1.screen.getByTestId('filterJson').textContent)).toEqual(expect.objectContaining({ page: 20, offset: 380 }));
|
|
497
|
-
return [2 /*return*/];
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
}); });
|
|
501
|
-
});
|
|
502
|
-
function wait(n) {
|
|
503
|
-
if (n === void 0) { n = 0; }
|
|
504
|
-
return new Promise(function (resolve) { return setTimeout(resolve, n); });
|
|
505
|
-
}
|
|
506
|
-
function safeJsonParse(input) {
|
|
507
|
-
if (input === void 0) { input = ''; }
|
|
508
|
-
if (input) {
|
|
509
|
-
return JSON.parse(input);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function actAndWait(fn, n) {
|
|
513
|
-
if (n === void 0) { n = 0; }
|
|
514
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
515
|
-
var _this = this;
|
|
516
|
-
return __generator(this, function (_a) {
|
|
517
|
-
switch (_a.label) {
|
|
518
|
-
case 0:
|
|
519
|
-
react_1.act(fn);
|
|
520
|
-
return [4 /*yield*/, react_1.act(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
521
|
-
return __generator(this, function (_a) {
|
|
522
|
-
switch (_a.label) {
|
|
523
|
-
case 0: return [4 /*yield*/, wait(n)];
|
|
524
|
-
case 1:
|
|
525
|
-
_a.sent();
|
|
526
|
-
return [2 /*return*/];
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
}); })
|
|
530
|
-
// You'd think you could just write this:
|
|
531
|
-
// await act(async () => {
|
|
532
|
-
// fn();
|
|
533
|
-
// await wait(n);
|
|
534
|
-
// });
|
|
535
|
-
// But for some reason, doing it that way needs a longer wait duration than
|
|
536
|
-
// just a single tick. /shrug.
|
|
537
|
-
];
|
|
538
|
-
case 1:
|
|
539
|
-
_a.sent();
|
|
540
|
-
return [2 /*return*/];
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
function setup(options) {
|
|
546
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
547
|
-
var onChangeMock, ExampleComponent;
|
|
548
|
-
return __generator(this, function (_a) {
|
|
549
|
-
switch (_a.label) {
|
|
550
|
-
case 0:
|
|
551
|
-
memoryStore_1.default.clear();
|
|
552
|
-
store_1.setFilterStore(memoryStore_1.default);
|
|
553
|
-
onChangeMock = jest.fn();
|
|
554
|
-
ExampleComponent = function () {
|
|
555
|
-
var _a;
|
|
556
|
-
var wut = useFilter_1.default('namespace', {
|
|
557
|
-
defaultFilterInfo: options.defaultFilterInfo,
|
|
558
|
-
debounceDuration: 0,
|
|
559
|
-
onChange: onChangeMock,
|
|
560
|
-
});
|
|
561
|
-
return (react_2.default.createElement("div", null, (_a = options.children) === null || _a === void 0 ? void 0 :
|
|
562
|
-
_a.call(options, wut),
|
|
563
|
-
react_2.default.createElement("button", { "data-testid": "updateFilterButton", onClick: function () { return wut.updateFilter({ foo: '42' }); } }),
|
|
564
|
-
react_2.default.createElement("button", { "data-testid": "resetFilterButton", onClick: function () { return wut.resetFilter(); } }),
|
|
565
|
-
react_2.default.createElement("button", { "data-testid": "forceRefreshButton", onClick: function () { return wut.forceRefresh(); } }),
|
|
566
|
-
react_2.default.createElement("button", { "data-testid": "setSortButton", onClick: function () { return wut.setSort('foo:bar'); } }),
|
|
567
|
-
react_2.default.createElement("div", { "data-testid": "filterJson" }, JSON.stringify(wut.filterInfo))));
|
|
568
|
-
};
|
|
569
|
-
return [4 /*yield*/, actAndWait(function () {
|
|
570
|
-
react_1.render(react_2.default.createElement(ExampleComponent, null));
|
|
571
|
-
})];
|
|
572
|
-
case 1:
|
|
573
|
-
_a.sent();
|
|
574
|
-
return [2 /*return*/, {
|
|
575
|
-
onChangeMock: onChangeMock,
|
|
576
|
-
ExampleComponent: ExampleComponent,
|
|
577
|
-
}];
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
});
|
|
581
|
-
}
|