@schukai/monster 4.111.0 → 4.113.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.
@@ -29,6 +29,7 @@ export * from "./components/layout/width-toggle.mjs";
29
29
  export * from "./components/layout/board.mjs";
30
30
  export * from "./components/layout/panel.mjs";
31
31
  export * from "./components/layout/details.mjs";
32
+ export * from "./components/layout/vertical-tabs.mjs";
32
33
  export * from "./components/layout/slider.mjs";
33
34
  export * from "./components/content/fetch-box.mjs";
34
35
  export * from "./components/content/viewer.mjs";
@@ -73,6 +74,7 @@ export * from "./components/form/action-button.mjs";
73
74
  export * from "./components/form/form.mjs";
74
75
  export * from "./components/form/repeat-field-set.mjs";
75
76
  export * from "./components/form/api-button.mjs";
77
+ export * from "./components/form/select-link.mjs";
76
78
  export * from "./components/form/digits.mjs";
77
79
  export * from "./components/form/tree-select.mjs";
78
80
  export * from "./components/form/popper-button.mjs";
@@ -184,6 +184,122 @@ describe('Select', function () {
184
184
 
185
185
  });
186
186
 
187
+ describe('Remote filter pagination', function () {
188
+ let requestCount = 0;
189
+
190
+ beforeEach((done) => {
191
+ let mocks = document.getElementById('mocks');
192
+ mocks.innerHTML = html1;
193
+
194
+ requestCount = 0;
195
+ global['fetch'] = function () {
196
+ requestCount += 1;
197
+ let headers = new Map;
198
+ headers.set('content-type', 'application/json');
199
+
200
+ if (requestCount === 1) {
201
+ return Promise.resolve({
202
+ ok: true,
203
+ status: 200,
204
+ headers: headers,
205
+ text: function () {
206
+ return Promise.resolve(JSON.stringify({
207
+ items: [
208
+ {id: 1, name: "Alpha"}
209
+ ],
210
+ pagination: {
211
+ total: 2,
212
+ page: 1,
213
+ perPage: 1
214
+ }
215
+ }));
216
+ }
217
+ });
218
+ }
219
+
220
+ return Promise.resolve({
221
+ ok: false,
222
+ status: 500,
223
+ headers: headers,
224
+ text: function () {
225
+ return Promise.resolve(JSON.stringify({}));
226
+ }
227
+ });
228
+ };
229
+
230
+ done();
231
+ });
232
+
233
+ afterEach(() => {
234
+ let mocks = document.getElementById('mocks');
235
+ mocks.innerHTML = "";
236
+ global['fetch'] = fetchReference;
237
+ });
238
+
239
+ it('should reset pagination and clear options on fetch error', function (done) {
240
+ this.timeout(4000);
241
+
242
+ let mocks = document.getElementById('mocks');
243
+ const select = document.createElement('monster-select');
244
+ select.setOption('url', 'https://example.com/items?filter={filter}&page={page}');
245
+ select.setOption('filter.mode', 'remote');
246
+ select.setOption('mapping.selector', 'items.*');
247
+ select.setOption('mapping.labelTemplate', '${name}');
248
+ select.setOption('mapping.valueTemplate', '${id}');
249
+ select.setOption('mapping.total', 'pagination.total');
250
+ select.setOption('mapping.currentPage', 'pagination.page');
251
+ select.setOption('mapping.objectsPerPage', 'pagination.perPage');
252
+ mocks.appendChild(select);
253
+
254
+ const pagination = () => select.shadowRoot.querySelector('[data-monster-role=pagination]');
255
+
256
+ const triggerFilter = (value) => {
257
+ const filterInput = select.shadowRoot.querySelector('[data-monster-role=filter]');
258
+ filterInput.value = value;
259
+ filterInput.dispatchEvent(new KeyboardEvent('keydown', {
260
+ code: 'KeyA',
261
+ bubbles: true
262
+ }));
263
+ };
264
+
265
+ select.addEventListener('monster-options-set', () => {
266
+ setTimeout(() => {
267
+ try {
268
+ const options = select.getOption('options');
269
+ expect(options.length).to.equal(1);
270
+ expect(pagination().getOption('currentPage')).to.equal(1);
271
+ expect(pagination().getOption('pages')).to.equal(2);
272
+ expect(pagination().getOption('objectsPerPage')).to.equal(1);
273
+
274
+ triggerFilter('b');
275
+
276
+ setTimeout(() => {
277
+ try {
278
+ const optionsAfterError = select.getOption('options');
279
+ expect(optionsAfterError.length).to.equal(0);
280
+ expect(pagination().getOption('currentPage')).to.equal(null);
281
+ expect(pagination().getOption('pages')).to.equal(null);
282
+ expect(pagination().getOption('objectsPerPage')).to.equal(null);
283
+ expect(select.getOption('total')).to.equal(null);
284
+ expect(select.getOption('messages.total')).to.equal("");
285
+ } catch (e) {
286
+ return done(e);
287
+ }
288
+
289
+ done();
290
+ }, 500);
291
+ } catch (e) {
292
+ done(e);
293
+ }
294
+ }, 50);
295
+ }, {once: true});
296
+
297
+ setTimeout(() => {
298
+ triggerFilter('a');
299
+ }, 0);
300
+ });
301
+ });
302
+
187
303
  describe('document.createElement()', function () {
188
304
 
189
305
  afterEach(() => {