@dile/crud 2.9.5 → 2.10.1
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/components/steps-form/index.js +3 -0
- package/components/steps-form/src/DileStepForm.js +202 -0
- package/components/steps-form/src/DileStepNextPrev.js +134 -0
- package/components/steps-form/src/DileStepsForm.js +347 -0
- package/components/steps-form/step-form.js +5 -0
- package/components/steps-form/step-next-prev.js +5 -0
- package/components/steps-form/steps-form.js +5 -0
- package/lib/i18n/en.js +6 -1
- package/lib/i18n/es.js +6 -1
- package/package.json +3 -3
- package/components/action/src/DileCrudSingleActions.spec.js +0 -126
- package/components/action/src/__screenshots__/DileCrudSingleActions.spec.js/DileCrudSingleActions-with-triggerAction-closing-dialog-with-ESC-and-reopening-without-data-shows-reset-form-1.png +0 -0
- package/components/action/src/__screenshots__/DileCrudSingleActions.spec.js/DileCrudSingleActions-with-triggerAction-initialData-is-cleared-after-being-applied-1.png +0 -0
- package/components/action/src/__screenshots__/DileCrudSingleActions.spec.js/DileCrudSingleActions-with-triggerAction-initialData-is-only-applied-once-and-cleared-after-opening-1.png +0 -0
- package/components/action/src/__screenshots__/DileCrudSingleActions.spec.js/DileCrudSingleActions-with-triggerAction-triggerAction-behavior-matches-original-when-no-initialData-1.png +0 -0
- package/components/action/src/__screenshots__/DileCrudSingleActions.spec.js/DileCrudSingleActions-with-triggerAction-triggerAction-opens-confirm-dialog-1.png +0 -0
- package/components/action/src/__screenshots__/DileCrudSingleActions.spec.js/DileCrudSingleActions-with-triggerAction-triggerAction-with-initialData-sets-form-values-1.png +0 -0
- package/components/action/src/__screenshots__/DileCrudSingleActions.spec.js/DileCrudSingleActions-with-triggerAction-triggerAction-with-initialData-sets-form-values-before-opening-dialog-1.png +0 -0
- package/components/action/src/__screenshots__/DileCrudSingleActions.spec.js/DileCrudSingleActions-with-triggerAction-triggerAction-without-initialData-resets-form-1.png +0 -0
- package/components/action/src/__screenshots__/DileCrudSingleActions.spec.js/DileCrudSingleActions-with-triggerAction-triggerAction-without-initialData-resets-form-to-empty-1.png +0 -0
- package/components/ajax/ajax.spec.js +0 -35
- package/components/ajax-select-crud/ajax-select-crud-overlay.spec.js +0 -186
- package/components/crud/__screenshots__/crud.spec.js/dile-crud-list-grid-view-switch-defaults-to-the-item-template-and-toggles-to-the-grid-on-click-when-both-views-are-configured-1.png +0 -0
- package/components/crud/__screenshots__/crud.spec.js/dile-crud-list-grid-view-switch-does-not-render-the-switch-button-when-customization-disableListWiewSwitch-is-true-1.png +0 -0
- package/components/crud/crud.spec.js +0 -453
- package/components/file-uploader/file-uploader.spec.js +0 -32
- package/components/list/__screenshots__/crud-data-grid.spec.js/dile-crud-data-grid-always-forces-sort-mode-to-external-regardless-of-config-1.png +0 -0
- package/components/list/__screenshots__/crud-data-grid.spec.js/dile-crud-data-grid-forwards-stickyFirstColumn--striped--responsiveMode-and-emptyMessage-with-sensible-defaults-1.png +0 -0
- package/components/list/__screenshots__/crud-data-grid.spec.js/dile-crud-data-grid-leaves-computeRowId-unset-when-config-computeItemId-is-not-a-function-1.png +0 -0
- package/components/list/__screenshots__/crud-list.spec.js/dile-crud-list-scope-changes-and-page-reset-keeps-the-current-page-on-refresh---and-goes-back-to-page-1-on-refresh---resetPage--true----1.png +0 -0
- package/components/list/__screenshots__/crud-list.spec.js/dile-crud-list-scope-changes-and-page-reset-reloads-from-the-first-page-with-the-new-scope-when-belongsTo-and-relationId-change-1.png +0 -0
- package/components/list/__screenshots__/crud-list.spec.js/dile-crud-list-scope-changes-and-page-reset-reloads-when-only-relationId-changes-1.png +0 -0
- package/components/list/crud-data-grid.spec.js +0 -207
- package/components/list/crud-item-actions.spec.js +0 -122
- package/components/list/crud-list.spec.js +0 -455
- package/components/many-relation/many-relation.spec.js +0 -154
- package/components/select-ajax-simple/select-ajax-simple.spec.js +0 -133
- package/components/single/src/DileCrudSingle.spec.js +0 -151
- package/components/single/src/__screenshots__/DileCrudSingle.spec.js/DileCrudSingle-triggerAction-and-triggerDirectAction-triggerAction-delegates-to-singleActionsElement-triggerAction-1.png +0 -0
- package/components/single/src/__screenshots__/DileCrudSingle.spec.js/DileCrudSingle-triggerAction-and-triggerDirectAction-triggerAction-without-initialData-works-1.png +0 -0
- package/components/single/src/__screenshots__/DileCrudSingle.spec.js/DileCrudSingle-triggerAction-and-triggerDirectAction-triggerDirectAction-delegates-to-singleActionsElement-triggerAction-1.png +0 -0
- package/components/single/src/__screenshots__/DileCrudSingle.spec.js/DileCrudSingle-triggerAction-and-triggerDirectAction-triggerDirectAction-without-initialData-still-works--backward-compatibility--1.png +0 -0
- package/components/ui/__screenshots__/crud-sort-form.spec.js/dile-crud-sort-form-clicking-the-label-of-an-inactive-option-switches-to-it-using-its-own-configured-direction--without-flipping-it-1.png +0 -0
- package/components/ui/__screenshots__/crud-sort-form.spec.js/dile-crud-sort-form-clicking-the-label-of-the-already-active-option-toggles-its-direction-instead-of-doing-nothing-1.png +0 -0
- package/components/ui/__screenshots__/crud-sort-form.spec.js/dile-crud-sort-form-syncSort-suppresses-exactly-one-radio-group-echo--preserving-the-synced-direction-instead-of-falling-back-to-the-option-static-default-1.png +0 -0
- package/components/ui/crud-sort-form.spec.js +0 -132
- package/lib/CrudConfigBuilder.spec.js +0 -32
- package/lib/deepMerge.spec.js +0 -45
- package/lib/listViewMode.spec.js +0 -73
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
-
import { html } from 'lit';
|
|
3
|
-
import { CrudConfigBuilder } from '../../lib/CrudConfigBuilder.js';
|
|
4
|
-
import './crud.js';
|
|
5
|
-
|
|
6
|
-
describe('dile-crud initial filters', () => {
|
|
7
|
-
afterEach(() => {
|
|
8
|
-
document.body.innerHTML = '';
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('syncs active filters from config into the list and form on first render', async () => {
|
|
12
|
-
const config = new CrudConfigBuilder('https://example.test/api/countries', {
|
|
13
|
-
customization: {
|
|
14
|
-
disableInsert: true,
|
|
15
|
-
disableHelp: true,
|
|
16
|
-
disableKeywordSearch: true,
|
|
17
|
-
disableSort: true,
|
|
18
|
-
disableFilter: false,
|
|
19
|
-
disablePagination: true,
|
|
20
|
-
hideCheckboxSelection: true,
|
|
21
|
-
},
|
|
22
|
-
availableFilters: [
|
|
23
|
-
{
|
|
24
|
-
name: 'continent',
|
|
25
|
-
label: 'Continent',
|
|
26
|
-
active: true,
|
|
27
|
-
value: 'Europe',
|
|
28
|
-
type: 'select',
|
|
29
|
-
options: [
|
|
30
|
-
{ value: 'Europe', label: 'Europe' },
|
|
31
|
-
{ value: 'Asia', label: 'Asia' },
|
|
32
|
-
],
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
}).getConfig();
|
|
36
|
-
|
|
37
|
-
const el = document.createElement('dile-crud');
|
|
38
|
-
el.config = config;
|
|
39
|
-
document.body.appendChild(el);
|
|
40
|
-
await el.updateComplete;
|
|
41
|
-
await Promise.resolve();
|
|
42
|
-
|
|
43
|
-
expect(el.config.availableFilters[0].active).toBe(true);
|
|
44
|
-
expect(el.config.availableFilters[0].value).toBe('Europe');
|
|
45
|
-
expect(el.listElement.filters).toHaveLength(1);
|
|
46
|
-
expect(el.listElement.filters[0].name).toBe('continent');
|
|
47
|
-
expect(el.listElement.filters[0].value).toBe('Europe');
|
|
48
|
-
|
|
49
|
-
const form = el.shadowRoot.querySelector('dile-crud-filters');
|
|
50
|
-
expect(form.filters[0].active).toBe(true);
|
|
51
|
-
expect(form.filters[0].value).toBe('Europe');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('removes an active initial filter when the chip close icon is clicked', async () => {
|
|
55
|
-
const config = new CrudConfigBuilder('https://example.test/api/countries', {
|
|
56
|
-
customization: {
|
|
57
|
-
disableInsert: true,
|
|
58
|
-
disableHelp: true,
|
|
59
|
-
disableKeywordSearch: true,
|
|
60
|
-
disableSort: true,
|
|
61
|
-
disableFilter: false,
|
|
62
|
-
disablePagination: true,
|
|
63
|
-
hideCheckboxSelection: true,
|
|
64
|
-
},
|
|
65
|
-
availableFilters: [
|
|
66
|
-
{
|
|
67
|
-
name: 'continent',
|
|
68
|
-
label: 'Continent',
|
|
69
|
-
active: true,
|
|
70
|
-
value: 'Europe',
|
|
71
|
-
type: 'select',
|
|
72
|
-
options: [
|
|
73
|
-
{ value: 'Europe', label: 'Europe' },
|
|
74
|
-
{ value: 'Asia', label: 'Asia' },
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
}).getConfig();
|
|
79
|
-
|
|
80
|
-
const el = document.createElement('dile-crud');
|
|
81
|
-
el.config = config;
|
|
82
|
-
document.body.appendChild(el);
|
|
83
|
-
await el.updateComplete;
|
|
84
|
-
await Promise.resolve();
|
|
85
|
-
|
|
86
|
-
const filterEl = el.shadowRoot.querySelector('dile-crud-filters');
|
|
87
|
-
filterEl.removeFilter('continent');
|
|
88
|
-
|
|
89
|
-
expect(filterEl.filters[0].active).toBe(false);
|
|
90
|
-
expect(filterEl.filters[0].value).toBe('');
|
|
91
|
-
expect(el.listElement.filters[0].active).toBe(false);
|
|
92
|
-
expect(el.listElement.filters[0].value).toBe('');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('keeps an inactive select filter inactive when config uses the false sentinel', async () => {
|
|
96
|
-
const config = new CrudConfigBuilder('https://example.test/api/countries', {
|
|
97
|
-
customization: {
|
|
98
|
-
disableInsert: true,
|
|
99
|
-
disableHelp: true,
|
|
100
|
-
disableKeywordSearch: true,
|
|
101
|
-
disableSort: true,
|
|
102
|
-
disableFilter: false,
|
|
103
|
-
disablePagination: true,
|
|
104
|
-
hideCheckboxSelection: true,
|
|
105
|
-
},
|
|
106
|
-
availableFilters: [
|
|
107
|
-
{
|
|
108
|
-
name: 'continent',
|
|
109
|
-
label: 'Continent',
|
|
110
|
-
active: false,
|
|
111
|
-
value: false,
|
|
112
|
-
type: 'select',
|
|
113
|
-
options: [
|
|
114
|
-
{ value: 'Europe', label: 'Europe' },
|
|
115
|
-
{ value: 'Asia', label: 'Asia' },
|
|
116
|
-
],
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
}).getConfig();
|
|
120
|
-
|
|
121
|
-
const el = document.createElement('dile-crud');
|
|
122
|
-
el.config = config;
|
|
123
|
-
document.body.appendChild(el);
|
|
124
|
-
await el.updateComplete;
|
|
125
|
-
await Promise.resolve();
|
|
126
|
-
|
|
127
|
-
expect(el.listElement.filters).toHaveLength(0);
|
|
128
|
-
|
|
129
|
-
const filtersForm = el.shadowRoot
|
|
130
|
-
.querySelector('dile-crud-filters')
|
|
131
|
-
.shadowRoot.querySelector('dile-crud-filters-form');
|
|
132
|
-
const select = filtersForm.shadowRoot.querySelector('dile-select');
|
|
133
|
-
expect(select.value).toBe('');
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe('dile-crud sort synchronization', () => {
|
|
138
|
-
afterEach(() => {
|
|
139
|
-
document.body.innerHTML = '';
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('syncs dile-crud-sort-form when the list sort changes (e.g. from a DataGrid column header)', async () => {
|
|
143
|
-
const config = new CrudConfigBuilder('https://example.test/api/customers', {
|
|
144
|
-
customization: {
|
|
145
|
-
disableInsert: true,
|
|
146
|
-
disableHelp: true,
|
|
147
|
-
disableKeywordSearch: true,
|
|
148
|
-
disableSort: false,
|
|
149
|
-
disableFilter: true,
|
|
150
|
-
disablePagination: true,
|
|
151
|
-
hideCheckboxSelection: true,
|
|
152
|
-
},
|
|
153
|
-
sort: {
|
|
154
|
-
options: [
|
|
155
|
-
{ name: 'name', label: 'Name', direction: 'asc' },
|
|
156
|
-
],
|
|
157
|
-
initialSortField: null,
|
|
158
|
-
},
|
|
159
|
-
}).getConfig();
|
|
160
|
-
|
|
161
|
-
const el = document.createElement('dile-crud');
|
|
162
|
-
el.config = config;
|
|
163
|
-
document.body.appendChild(el);
|
|
164
|
-
await el.updateComplete;
|
|
165
|
-
await Promise.resolve();
|
|
166
|
-
|
|
167
|
-
expect(el.sortFormElement).toBeTruthy();
|
|
168
|
-
|
|
169
|
-
el.listElement.setSort({ sortField: 'name', sortDirection: 'desc' });
|
|
170
|
-
await el.updateComplete;
|
|
171
|
-
|
|
172
|
-
expect(el.sortFormElement.sortField).toBe('name');
|
|
173
|
-
expect(el.sortFormElement.sortDirection).toBe('desc');
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('ignores a grid sort field that is not listed in config.sort.options instead of crashing the sort-form', async () => {
|
|
177
|
-
// Reproduces a DataGrid column marked `sortable: true` for a field (e.g. "continent")
|
|
178
|
-
// that has no corresponding entry in config.sort.options.
|
|
179
|
-
const config = new CrudConfigBuilder('https://example.test/api/countries', {
|
|
180
|
-
customization: {
|
|
181
|
-
disableInsert: true,
|
|
182
|
-
disableHelp: true,
|
|
183
|
-
disableKeywordSearch: true,
|
|
184
|
-
disableSort: false,
|
|
185
|
-
disableFilter: true,
|
|
186
|
-
disablePagination: true,
|
|
187
|
-
hideCheckboxSelection: true,
|
|
188
|
-
},
|
|
189
|
-
grid: {
|
|
190
|
-
columns: [
|
|
191
|
-
{ field: 'name', header: 'Name', sortable: true },
|
|
192
|
-
{ field: 'continent', header: 'Continent', sortable: true },
|
|
193
|
-
],
|
|
194
|
-
},
|
|
195
|
-
sort: {
|
|
196
|
-
options: [
|
|
197
|
-
{ name: 'name', label: 'Name', direction: 'asc' },
|
|
198
|
-
],
|
|
199
|
-
initialSortField: 'name',
|
|
200
|
-
},
|
|
201
|
-
}).getConfig();
|
|
202
|
-
|
|
203
|
-
const el = document.createElement('dile-crud');
|
|
204
|
-
el.config = config;
|
|
205
|
-
document.body.appendChild(el);
|
|
206
|
-
await el.updateComplete;
|
|
207
|
-
await Promise.resolve();
|
|
208
|
-
|
|
209
|
-
const initialSortField = el.sortFormElement.sortField;
|
|
210
|
-
|
|
211
|
-
expect(() => {
|
|
212
|
-
el.listElement.dispatchEvent(new CustomEvent('crud-list-sort-changed', {
|
|
213
|
-
bubbles: true,
|
|
214
|
-
composed: true,
|
|
215
|
-
detail: { sortField: 'continent', sortDirection: 'asc' },
|
|
216
|
-
}));
|
|
217
|
-
}).not.toThrow();
|
|
218
|
-
await el.updateComplete;
|
|
219
|
-
|
|
220
|
-
// The sort-form's selection is left untouched rather than pointed at an unknown option.
|
|
221
|
-
expect(el.sortFormElement.sortField).toBe(initialSortField);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('does not let the sort-form echo override a grid-driven sort with the field static configured default direction', async () => {
|
|
225
|
-
// "year" is configured with a static default direction of "desc". A DataGrid column
|
|
226
|
-
// header click always starts at "asc" on first click — reproduces the exact scenario
|
|
227
|
-
// where the sort silently snapped back to "desc" and repeated clicks appeared to
|
|
228
|
-
// "lose" the requested order.
|
|
229
|
-
const config = new CrudConfigBuilder('https://example.test/api/board-games', {
|
|
230
|
-
customization: {
|
|
231
|
-
disableInsert: true,
|
|
232
|
-
disableHelp: true,
|
|
233
|
-
disableKeywordSearch: true,
|
|
234
|
-
disableSort: false,
|
|
235
|
-
disableFilter: true,
|
|
236
|
-
disablePagination: true,
|
|
237
|
-
hideCheckboxSelection: true,
|
|
238
|
-
},
|
|
239
|
-
grid: {
|
|
240
|
-
columns: [
|
|
241
|
-
{ field: 'year', header: 'Year', sortable: true },
|
|
242
|
-
],
|
|
243
|
-
},
|
|
244
|
-
sort: {
|
|
245
|
-
options: [
|
|
246
|
-
{ name: 'year', label: 'Year', direction: 'desc' },
|
|
247
|
-
],
|
|
248
|
-
initialSortField: 'year',
|
|
249
|
-
},
|
|
250
|
-
}).getConfig();
|
|
251
|
-
|
|
252
|
-
const el = document.createElement('dile-crud');
|
|
253
|
-
el.config = config;
|
|
254
|
-
document.body.appendChild(el);
|
|
255
|
-
await el.updateComplete;
|
|
256
|
-
await Promise.resolve();
|
|
257
|
-
|
|
258
|
-
let lastSetSort = null;
|
|
259
|
-
el.listElement.setSort = (sortObj) => {
|
|
260
|
-
lastSetSort = sortObj;
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
// Simulate what DileCrudList.setSort() dispatches after a grid header click requesting "asc".
|
|
264
|
-
el.listElement.dispatchEvent(new CustomEvent('crud-list-sort-changed', {
|
|
265
|
-
bubbles: true,
|
|
266
|
-
composed: true,
|
|
267
|
-
detail: { sortField: 'year', sortDirection: 'asc' },
|
|
268
|
-
}));
|
|
269
|
-
await el.updateComplete;
|
|
270
|
-
await new Promise((resolve) => setTimeout(resolve, 0)); // flush any echo microtasks
|
|
271
|
-
|
|
272
|
-
expect(el.sortFormElement.sortField).toBe('year');
|
|
273
|
-
expect(el.sortFormElement.sortDirection).toBe('asc');
|
|
274
|
-
// The echo must not have triggered a second, corrupting setSort() call.
|
|
275
|
-
expect(lastSetSort).toBeNull();
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
describe('dile-crud list/grid view switch', () => {
|
|
280
|
-
afterEach(() => {
|
|
281
|
-
document.body.innerHTML = '';
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
const baseCustomization = {
|
|
285
|
-
disableInsert: true,
|
|
286
|
-
disableHelp: true,
|
|
287
|
-
disableKeywordSearch: true,
|
|
288
|
-
disableSort: true,
|
|
289
|
-
disableFilter: true,
|
|
290
|
-
disablePagination: true,
|
|
291
|
-
hideCheckboxSelection: true,
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
function buildConfig(overrides = {}) {
|
|
295
|
-
return new CrudConfigBuilder('https://example.test/api/countries', {
|
|
296
|
-
customization: { ...baseCustomization, ...(overrides.customization || {}) },
|
|
297
|
-
grid: { columns: [{ field: 'name', header: 'Name' }] },
|
|
298
|
-
templates: { item: (item) => html`<span>${item.name}</span>` },
|
|
299
|
-
...overrides,
|
|
300
|
-
}).getConfig();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
it('shows the item template by default and renders no switch button when only one view is configured', async () => {
|
|
304
|
-
const config = new CrudConfigBuilder('https://example.test/api/countries', {
|
|
305
|
-
customization: baseCustomization,
|
|
306
|
-
templates: { item: (item) => html`<span>${item.name}</span>` },
|
|
307
|
-
}).getConfig();
|
|
308
|
-
|
|
309
|
-
const el = document.createElement('dile-crud');
|
|
310
|
-
el.config = config;
|
|
311
|
-
document.body.appendChild(el);
|
|
312
|
-
await el.updateComplete;
|
|
313
|
-
|
|
314
|
-
const switchButtons = [...el.shadowRoot.querySelectorAll('dile-button-icon')]
|
|
315
|
-
.filter((btn) => /view/i.test(btn.textContent));
|
|
316
|
-
expect(switchButtons.length).toBe(0);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
it('defaults to the item view and toggles to the grid on click when both views are configured', async () => {
|
|
320
|
-
// Rendering per view mode (item vs. grid DOM) is covered in crud-list.spec.js;
|
|
321
|
-
// here we only verify dile-crud's own state, wiring and button behavior, since
|
|
322
|
-
// driving dile-crud-list's real data load would race its own network refresh.
|
|
323
|
-
const config = buildConfig();
|
|
324
|
-
|
|
325
|
-
const el = document.createElement('dile-crud');
|
|
326
|
-
el.config = config;
|
|
327
|
-
document.body.appendChild(el);
|
|
328
|
-
await el.updateComplete;
|
|
329
|
-
|
|
330
|
-
expect(el._viewMode).toBe('item');
|
|
331
|
-
expect(el.listElement.viewMode).toBe('item');
|
|
332
|
-
|
|
333
|
-
const switchButton = [...el.shadowRoot.querySelectorAll('dile-button-icon')]
|
|
334
|
-
.find((btn) => /view/i.test(btn.textContent));
|
|
335
|
-
expect(switchButton).toBeTruthy();
|
|
336
|
-
expect(switchButton.textContent.trim()).toBe('Grid view');
|
|
337
|
-
|
|
338
|
-
switchButton.click();
|
|
339
|
-
await el.updateComplete;
|
|
340
|
-
|
|
341
|
-
expect(el._viewMode).toBe('grid');
|
|
342
|
-
expect(el.listElement.viewMode).toBe('grid');
|
|
343
|
-
|
|
344
|
-
const switchButtonAfter = [...el.shadowRoot.querySelectorAll('dile-button-icon')]
|
|
345
|
-
.find((btn) => /view/i.test(btn.textContent));
|
|
346
|
-
expect(switchButtonAfter.textContent.trim()).toBe('List view');
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it('does not render the switch button when customization.disableListWiewSwitch is true', async () => {
|
|
350
|
-
const config = buildConfig({ customization: { disableListWiewSwitch: true } });
|
|
351
|
-
|
|
352
|
-
const el = document.createElement('dile-crud');
|
|
353
|
-
el.config = config;
|
|
354
|
-
document.body.appendChild(el);
|
|
355
|
-
await el.updateComplete;
|
|
356
|
-
|
|
357
|
-
const switchButtons = [...el.shadowRoot.querySelectorAll('dile-button-icon')]
|
|
358
|
-
.filter((btn) => /view/i.test(btn.textContent));
|
|
359
|
-
expect(switchButtons.length).toBe(0);
|
|
360
|
-
expect(el.listElement.viewMode).toBe('item');
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
describe('dile-crud scope and refresh', () => {
|
|
365
|
-
afterEach(() => {
|
|
366
|
-
document.body.innerHTML = '';
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
370
|
-
|
|
371
|
-
async function createCrud() {
|
|
372
|
-
const config = new CrudConfigBuilder('https://example.test/api/invoices', {
|
|
373
|
-
customization: {
|
|
374
|
-
disableInsert: true,
|
|
375
|
-
disableHelp: true,
|
|
376
|
-
disableKeywordSearch: true,
|
|
377
|
-
disableSort: true,
|
|
378
|
-
disableFilter: true,
|
|
379
|
-
disablePagination: true,
|
|
380
|
-
hideCheckboxSelection: true,
|
|
381
|
-
},
|
|
382
|
-
templates: { item: (item) => html`<span>${item.name}</span>` },
|
|
383
|
-
}).getConfig();
|
|
384
|
-
|
|
385
|
-
const el = document.createElement('dile-crud');
|
|
386
|
-
el.config = config;
|
|
387
|
-
el.belongsTo = 'customer';
|
|
388
|
-
el.relationId = '10';
|
|
389
|
-
document.body.appendChild(el);
|
|
390
|
-
await el.updateComplete;
|
|
391
|
-
const list = el.listElement;
|
|
392
|
-
await list.updateComplete;
|
|
393
|
-
await list.elservice.updateComplete;
|
|
394
|
-
|
|
395
|
-
// Intercept the outgoing requests instead of hitting the network,
|
|
396
|
-
// and let the initial load (fired on start) settle first.
|
|
397
|
-
const requests = [];
|
|
398
|
-
const ajax = list.elservice.ajaxget;
|
|
399
|
-
ajax.generateRequest = () => requests.push({ url: ajax.url, data: ajax.data });
|
|
400
|
-
list.elservice.delayTime = 10;
|
|
401
|
-
await wait(250);
|
|
402
|
-
requests.length = 0;
|
|
403
|
-
return { el, list, requests, ajax };
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
it('setScope() updates belongsTo and relationId and reloads the list once from page 1', async () => {
|
|
407
|
-
const { el, list, requests, ajax } = await createCrud();
|
|
408
|
-
ajax.url = 'https://example.test/api/invoices?page=2';
|
|
409
|
-
|
|
410
|
-
el.setScope('supplier', '20');
|
|
411
|
-
expect(el.belongsTo).toBe('supplier');
|
|
412
|
-
expect(el.relationId).toBe('20');
|
|
413
|
-
await el.updateComplete;
|
|
414
|
-
await list.updateComplete;
|
|
415
|
-
await wait(50);
|
|
416
|
-
|
|
417
|
-
expect(list.belongsTo).toBe('supplier');
|
|
418
|
-
expect(list.relationId).toBe('20');
|
|
419
|
-
expect(requests).toHaveLength(1);
|
|
420
|
-
expect(requests[0].url).toBe('https://example.test/api/invoices');
|
|
421
|
-
expect(requests[0].data.belongsTo).toBe('supplier');
|
|
422
|
-
expect(requests[0].data.relationId).toBe('20');
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
it('setScope() without arguments clears the scope', async () => {
|
|
426
|
-
const { el, list, requests } = await createCrud();
|
|
427
|
-
|
|
428
|
-
el.setScope();
|
|
429
|
-
await el.updateComplete;
|
|
430
|
-
await list.updateComplete;
|
|
431
|
-
await wait(50);
|
|
432
|
-
|
|
433
|
-
expect(el.belongsTo).toBe('');
|
|
434
|
-
expect(el.relationId).toBe('');
|
|
435
|
-
expect(requests).toHaveLength(1);
|
|
436
|
-
expect(requests[0].data.belongsTo).toBeUndefined();
|
|
437
|
-
expect(requests[0].data.relationId).toBeUndefined();
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
it('refresh() keeps the current page and refresh({ resetPage: true }) goes back to page 1', async () => {
|
|
441
|
-
const { el, requests, ajax } = await createCrud();
|
|
442
|
-
const pagedUrl = 'https://example.test/api/invoices?page=2';
|
|
443
|
-
|
|
444
|
-
ajax.url = pagedUrl;
|
|
445
|
-
el.refresh();
|
|
446
|
-
await wait(50);
|
|
447
|
-
expect(requests.at(-1).url).toBe(pagedUrl);
|
|
448
|
-
|
|
449
|
-
el.refresh({ resetPage: true });
|
|
450
|
-
await wait(50);
|
|
451
|
-
expect(requests.at(-1).url).toBe('https://example.test/api/invoices');
|
|
452
|
-
});
|
|
453
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
-
import './file-uploader.js';
|
|
3
|
-
|
|
4
|
-
describe('dile-file-uploader', () => {
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
document.body.innerHTML = '';
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
async function renderUploader(html) {
|
|
10
|
-
document.body.innerHTML = html;
|
|
11
|
-
const el = document.body.querySelector('dile-file-uploader');
|
|
12
|
-
await el.updateComplete;
|
|
13
|
-
const form = el.shadowRoot.querySelector('dile-file-uploader-form');
|
|
14
|
-
await form.updateComplete;
|
|
15
|
-
const dropFile = form.shadowRoot.querySelector('dile-drop-file');
|
|
16
|
-
await dropFile.updateComplete;
|
|
17
|
-
return { el, form, dropFile };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
it('uses a single file field named "file" by default', async () => {
|
|
21
|
-
const { dropFile } = await renderUploader('<dile-file-uploader endpoint="/upload"></dile-file-uploader>');
|
|
22
|
-
expect(dropFile.getAttribute('name')).toBe('file');
|
|
23
|
-
expect(dropFile.multiple).toBe(false);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('uses a multiple field named "files" when multiple is set', async () => {
|
|
27
|
-
const { form, dropFile } = await renderUploader('<dile-file-uploader endpoint="/upload" multiple></dile-file-uploader>');
|
|
28
|
-
expect(dropFile.getAttribute('name')).toBe('files');
|
|
29
|
-
expect(dropFile.multiple).toBe(true);
|
|
30
|
-
expect(form.getData()).toEqual({ files: [] });
|
|
31
|
-
});
|
|
32
|
-
});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|