@entropic-bond/crud-panel 3.3.3 → 3.4.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/lib/crud-controller.js +73 -150
- package/lib/crud-controller.js.map +1 -1
- package/lib/crud-controller.spec.js +44 -129
- package/lib/crud-controller.spec.js.map +1 -1
- package/lib/crud-panel.js +74 -155
- package/lib/crud-panel.js.map +1 -1
- package/lib/crud-panel.spec.js +174 -364
- package/lib/crud-panel.spec.js.map +1 -1
- package/lib/progress-controller.js +13 -15
- package/lib/progress-controller.js.map +1 -1
- package/lib/progress-controller.spec.js +32 -32
- package/lib/progress-controller.spec.js.map +1 -1
- package/package.json +14 -13
package/lib/crud-panel.spec.js
CHANGED
|
@@ -1,30 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
3
|
if (k2 === undefined) k2 = k;
|
|
30
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -57,44 +31,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
57
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
58
32
|
});
|
|
59
33
|
};
|
|
60
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
61
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
62
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
63
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
64
|
-
function step(op) {
|
|
65
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
66
|
-
while (_) try {
|
|
67
|
-
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;
|
|
68
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
69
|
-
switch (op[0]) {
|
|
70
|
-
case 0: case 1: t = op; break;
|
|
71
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
72
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
73
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
74
|
-
default:
|
|
75
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
76
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
77
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
78
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
79
|
-
if (t[2]) _.ops.pop();
|
|
80
|
-
_.trys.pop(); continue;
|
|
81
|
-
}
|
|
82
|
-
op = body.call(thisArg, _);
|
|
83
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
84
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
88
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
89
36
|
};
|
|
90
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
38
|
+
const react_1 = __importStar(require("react"));
|
|
39
|
+
const react_2 = require("@testing-library/react");
|
|
40
|
+
const user_event_1 = __importDefault(require("@testing-library/user-event"));
|
|
41
|
+
const entropic_bond_1 = require("entropic-bond");
|
|
42
|
+
const crud_panel_1 = require("./crud-panel");
|
|
43
|
+
const crud_controller_spec_1 = require("./crud-controller.spec");
|
|
44
|
+
const crudLabels = {
|
|
98
45
|
addNewDocumentLabel: 'Add new document',
|
|
99
46
|
addButtonLabel: 'Add',
|
|
100
47
|
updateButtonLabel: 'Update',
|
|
@@ -102,12 +49,12 @@ var crudLabels = {
|
|
|
102
49
|
singularDocumentInCollectionCaption: 'Existing document',
|
|
103
50
|
noDocumentsFoundLabel: 'No documents found',
|
|
104
51
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
52
|
+
const testViewPlaceholder = 'Test View Placeholder';
|
|
53
|
+
const editButtonLabel = 'Edit';
|
|
54
|
+
const deleteButtonLabel = 'Delete';
|
|
55
|
+
const cancelButtonCaption = 'Cancel';
|
|
56
|
+
const viewHeader = 'View header';
|
|
57
|
+
const mockData = {
|
|
111
58
|
Test: {
|
|
112
59
|
test1: {
|
|
113
60
|
__className: 'Test',
|
|
@@ -121,130 +68,71 @@ var mockData = {
|
|
|
121
68
|
}
|
|
122
69
|
}
|
|
123
70
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
TestView.prototype.componentDidMount = function () {
|
|
130
|
-
var _this = this;
|
|
131
|
-
var controller = this.props.controller;
|
|
132
|
-
controller.onChange(function (e) {
|
|
71
|
+
class TestView extends react_1.Component {
|
|
72
|
+
componentDidMount() {
|
|
73
|
+
const { controller } = this.props;
|
|
74
|
+
controller.onChange(e => {
|
|
133
75
|
if (e.documentProps)
|
|
134
|
-
|
|
76
|
+
this.setState(e.documentProps);
|
|
135
77
|
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
78
|
+
}
|
|
79
|
+
render() {
|
|
80
|
+
const { controller, onCancel, onSubmit, submitButtonCaption } = this.props;
|
|
81
|
+
const { document } = controller;
|
|
140
82
|
return (react_1.default.createElement("div", null,
|
|
141
83
|
react_1.default.createElement("h1", null, viewHeader),
|
|
142
|
-
react_1.default.createElement("input", { placeholder: testViewPlaceholder, value: document.testProp || '', onChange:
|
|
143
|
-
react_1.default.createElement("button", { onClick:
|
|
84
|
+
react_1.default.createElement("input", { placeholder: testViewPlaceholder, value: document.testProp || '', onChange: e => document.testProp = e.target.value }),
|
|
85
|
+
react_1.default.createElement("button", { onClick: () => onSubmit(document) }, submitButtonCaption),
|
|
144
86
|
react_1.default.createElement("button", { onClick: onCancel }, cancelButtonCaption)));
|
|
145
|
-
};
|
|
146
|
-
return TestView;
|
|
147
|
-
}(react_1.Component));
|
|
148
|
-
var TestCard = /** @class */ (function (_super) {
|
|
149
|
-
__extends(TestCard, _super);
|
|
150
|
-
function TestCard() {
|
|
151
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
152
87
|
}
|
|
153
|
-
|
|
154
|
-
|
|
88
|
+
}
|
|
89
|
+
class TestCard extends react_1.Component {
|
|
90
|
+
render() {
|
|
91
|
+
const { document, onDelete, onSelect } = this.props;
|
|
155
92
|
return (react_1.default.createElement("div", null,
|
|
156
93
|
react_1.default.createElement("p", null, document === null || document === void 0 ? void 0 : document.testProp),
|
|
157
|
-
react_1.default.createElement("button", { onClick:
|
|
158
|
-
react_1.default.createElement("button", { onClick:
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
// await datasource.wait()
|
|
180
|
-
return [4 /*yield*/, react_2.screen.findByRole('heading')];
|
|
181
|
-
case 1:
|
|
182
|
-
// await datasource.wait()
|
|
183
|
-
_a.sent();
|
|
184
|
-
return [2 /*return*/];
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}); });
|
|
188
|
-
it('should show add button', function () {
|
|
94
|
+
react_1.default.createElement("button", { onClick: () => onSelect(document) }, editButtonLabel),
|
|
95
|
+
react_1.default.createElement("button", { onClick: () => onDelete(document) }, deleteButtonLabel)));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
describe('Crud Panel', () => {
|
|
99
|
+
let controller;
|
|
100
|
+
let notifySpy;
|
|
101
|
+
let renderResult;
|
|
102
|
+
let datasource;
|
|
103
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
datasource = new entropic_bond_1.JsonDataSource(JSON.parse(JSON.stringify(mockData)));
|
|
105
|
+
entropic_bond_1.Store.useDataSource(datasource);
|
|
106
|
+
controller = new crud_controller_spec_1.TestController();
|
|
107
|
+
notifySpy = jest.fn();
|
|
108
|
+
controller.onChange(notifySpy);
|
|
109
|
+
renderResult = (0, react_2.render)(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: crudLabels },
|
|
110
|
+
react_1.default.createElement(TestView, null),
|
|
111
|
+
react_1.default.createElement(TestCard, null)));
|
|
112
|
+
// await datasource.wait()
|
|
113
|
+
yield react_2.screen.findByRole('heading');
|
|
114
|
+
}));
|
|
115
|
+
it('should show add button', () => {
|
|
189
116
|
expect(react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel })).toBeInTheDocument();
|
|
190
117
|
});
|
|
191
|
-
it('should show existing documents',
|
|
192
|
-
|
|
118
|
+
it('should show existing documents', () => {
|
|
119
|
+
const docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
|
|
193
120
|
expect((0, react_2.within)(docs).getByText('Test prop 1')).toBeInTheDocument();
|
|
194
121
|
expect((0, react_2.within)(docs).getByText('Test prop 2')).toBeInTheDocument();
|
|
195
122
|
expect(docs.children.length).toBe(2);
|
|
196
123
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return __generator(this, function (_a) {
|
|
200
|
-
switch (_a.label) {
|
|
201
|
-
case 0:
|
|
202
|
-
expect(react_2.screen.queryByText('Test prop 2')).toBeInTheDocument();
|
|
203
|
-
deleteButton = react_2.screen.getAllByRole('button', { name: deleteButtonLabel });
|
|
204
|
-
return [4 /*yield*/, user_event_1.default.click(deleteButton[1])];
|
|
205
|
-
case 1:
|
|
206
|
-
_a.sent();
|
|
207
|
-
return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(notifySpy).toHaveBeenCalled(); })];
|
|
208
|
-
case 2:
|
|
209
|
-
_a.sent();
|
|
210
|
-
return [4 /*yield*/, react_2.screen.findByRole('heading', { name: crudLabels.singularDocumentInCollectionCaption })];
|
|
211
|
-
case 3:
|
|
212
|
-
heading = _a.sent();
|
|
213
|
-
expect(heading).toBeInTheDocument();
|
|
214
|
-
return [2 /*return*/];
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}); });
|
|
218
|
-
it('should show plural when only one existing document but empty singular caption', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
219
|
-
var deleteButton, heading;
|
|
220
|
-
return __generator(this, function (_a) {
|
|
221
|
-
switch (_a.label) {
|
|
222
|
-
case 0:
|
|
223
|
-
crudLabels.singularDocumentInCollectionCaption = undefined;
|
|
224
|
-
expect(react_2.screen.queryByText('Test prop 2')).toBeInTheDocument();
|
|
225
|
-
deleteButton = react_2.screen.getAllByRole('button', { name: deleteButtonLabel });
|
|
226
|
-
user_event_1.default.click(deleteButton[1]);
|
|
227
|
-
return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(notifySpy).toHaveBeenCalled(); })];
|
|
228
|
-
case 1:
|
|
229
|
-
_a.sent();
|
|
230
|
-
heading = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption });
|
|
231
|
-
expect(heading).toBeInTheDocument();
|
|
232
|
-
return [2 /*return*/];
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
}); });
|
|
236
|
-
describe('Accepts children as functions', function () {
|
|
237
|
-
beforeEach(function () {
|
|
124
|
+
describe('Accepts children as functions', () => {
|
|
125
|
+
beforeEach(() => {
|
|
238
126
|
user_event_1.default.setup();
|
|
239
127
|
renderResult.rerender(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: crudLabels },
|
|
240
|
-
|
|
241
|
-
|
|
128
|
+
props => react_1.default.createElement(TestView, Object.assign({}, props)),
|
|
129
|
+
props => react_1.default.createElement(TestCard, Object.assign({}, props))));
|
|
242
130
|
});
|
|
243
|
-
it('should show add button',
|
|
131
|
+
it('should show add button', () => {
|
|
244
132
|
expect(react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel })).toBeInTheDocument();
|
|
245
133
|
});
|
|
246
|
-
it('should show existing documents',
|
|
247
|
-
|
|
134
|
+
it('should show existing documents', () => {
|
|
135
|
+
const docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
|
|
248
136
|
expect((0, react_2.within)(docs).getByText('Test prop 1')).toBeInTheDocument();
|
|
249
137
|
expect((0, react_2.within)(docs).getByText('Test prop 2')).toBeInTheDocument();
|
|
250
138
|
expect(docs.children.length).toBe(2);
|
|
@@ -252,206 +140,128 @@ describe('Crud Panel', function () {
|
|
|
252
140
|
expect(react_2.screen.getAllByRole('button', { name: deleteButtonLabel })[0]).toBeInTheDocument();
|
|
253
141
|
});
|
|
254
142
|
});
|
|
255
|
-
describe('Working with TestView',
|
|
256
|
-
it('should create an empty document view on add new document button click',
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
})
|
|
268
|
-
it('should
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
case 1:
|
|
277
|
-
_a.sent();
|
|
278
|
-
expect(react_2.screen.getByRole('heading', { name: viewHeader })).toBeInTheDocument();
|
|
279
|
-
expect(react_2.screen.getByDisplayValue(testDoc.testProp)).toBeInTheDocument();
|
|
280
|
-
return [2 /*return*/];
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}); });
|
|
284
|
-
it('should refresh document list on new document added', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
285
|
-
var input, docs, _a;
|
|
286
|
-
return __generator(this, function (_b) {
|
|
287
|
-
switch (_b.label) {
|
|
288
|
-
case 0: return [4 /*yield*/, user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel }))];
|
|
289
|
-
case 1:
|
|
290
|
-
_b.sent();
|
|
291
|
-
return [4 /*yield*/, react_2.screen.findByPlaceholderText(testViewPlaceholder)];
|
|
292
|
-
case 2:
|
|
293
|
-
input = _b.sent();
|
|
294
|
-
return [4 /*yield*/, user_event_1.default.type(input, 'New and fancy Application')];
|
|
295
|
-
case 3:
|
|
296
|
-
_b.sent();
|
|
297
|
-
return [4 /*yield*/, user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.addButtonLabel }))];
|
|
298
|
-
case 4:
|
|
299
|
-
_b.sent();
|
|
300
|
-
docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
|
|
301
|
-
_a = expect;
|
|
302
|
-
return [4 /*yield*/, (0, react_2.within)(docs).findByText('New and fancy Application')];
|
|
303
|
-
case 5:
|
|
304
|
-
_a.apply(void 0, [_b.sent()]).toBeInTheDocument();
|
|
305
|
-
return [2 /*return*/];
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}); });
|
|
143
|
+
describe('Working with TestView', () => {
|
|
144
|
+
it('should create an empty document view on add new document button click', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
145
|
+
yield user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel }));
|
|
146
|
+
expect(react_2.screen.getByRole('heading', { name: viewHeader })).toBeInTheDocument();
|
|
147
|
+
expect(react_2.screen.getByPlaceholderText(testViewPlaceholder)).toHaveDisplayValue('');
|
|
148
|
+
}));
|
|
149
|
+
it('should show detail view with document data on edit button click', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
150
|
+
const testDoc = mockData.Test.test1;
|
|
151
|
+
const editButton = react_2.screen.getAllByRole('button', { name: editButtonLabel });
|
|
152
|
+
yield user_event_1.default.click(editButton[0]);
|
|
153
|
+
expect(react_2.screen.getByRole('heading', { name: viewHeader })).toBeInTheDocument();
|
|
154
|
+
expect(react_2.screen.getByDisplayValue(testDoc.testProp)).toBeInTheDocument();
|
|
155
|
+
}));
|
|
156
|
+
it('should refresh document list on new document added', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
157
|
+
yield user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel }));
|
|
158
|
+
const input = yield react_2.screen.findByPlaceholderText(testViewPlaceholder);
|
|
159
|
+
yield user_event_1.default.type(input, 'New and fancy Application');
|
|
160
|
+
yield user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.addButtonLabel }));
|
|
161
|
+
const docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
|
|
162
|
+
expect(yield (0, react_2.within)(docs).findByText('New and fancy Application')).toBeInTheDocument();
|
|
163
|
+
}));
|
|
309
164
|
});
|
|
310
|
-
describe('Working with detail card buttons',
|
|
311
|
-
it('should refresh document list on document edited',
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
return [4 /*yield*/, user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.updateButtonLabel }))];
|
|
330
|
-
case 5:
|
|
331
|
-
_b.sent();
|
|
332
|
-
return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(notifySpy).toHaveBeenCalled(); })];
|
|
333
|
-
case 6:
|
|
334
|
-
_b.sent();
|
|
335
|
-
docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
|
|
336
|
-
_a = expect;
|
|
337
|
-
return [4 /*yield*/, (0, react_2.within)(docs).findByText('Test prop 1 Edited')];
|
|
338
|
-
case 7:
|
|
339
|
-
_a.apply(void 0, [_b.sent()]).toBeInTheDocument();
|
|
340
|
-
return [2 /*return*/];
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
}); });
|
|
344
|
-
it('should delete document and remove from the list', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
345
|
-
var deleteButton;
|
|
346
|
-
return __generator(this, function (_a) {
|
|
347
|
-
switch (_a.label) {
|
|
348
|
-
case 0:
|
|
349
|
-
expect(react_2.screen.queryByText('Test prop 2')).toBeInTheDocument();
|
|
350
|
-
deleteButton = react_2.screen.getAllByRole('button', { name: deleteButtonLabel });
|
|
351
|
-
return [4 /*yield*/, user_event_1.default.click(deleteButton[1])];
|
|
352
|
-
case 1:
|
|
353
|
-
_a.sent();
|
|
354
|
-
return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(notifySpy).toHaveBeenCalled(); })];
|
|
355
|
-
case 2:
|
|
356
|
-
_a.sent();
|
|
357
|
-
return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(react_2.screen.queryByText('Test prop 2')).not.toBeInTheDocument(); })];
|
|
358
|
-
case 3:
|
|
359
|
-
_a.sent();
|
|
360
|
-
return [2 /*return*/];
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
}); });
|
|
165
|
+
describe('Working with detail card buttons', () => {
|
|
166
|
+
it('should refresh document list on document edited', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
167
|
+
const editButton = react_2.screen.getAllByRole('button', { name: editButtonLabel });
|
|
168
|
+
yield user_event_1.default.click(editButton[0]);
|
|
169
|
+
const input = yield react_2.screen.findByPlaceholderText(testViewPlaceholder);
|
|
170
|
+
yield user_event_1.default.click(input);
|
|
171
|
+
yield user_event_1.default.paste(' Edited');
|
|
172
|
+
yield user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.updateButtonLabel }));
|
|
173
|
+
yield (0, react_2.waitFor)(() => expect(notifySpy).toHaveBeenCalled());
|
|
174
|
+
const docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
|
|
175
|
+
expect(yield (0, react_2.within)(docs).findByText('Test prop 1 Edited')).toBeInTheDocument();
|
|
176
|
+
}));
|
|
177
|
+
it('should delete document and remove from the list', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
+
expect(react_2.screen.queryByText('Test prop 2')).toBeInTheDocument();
|
|
179
|
+
const deleteButton = react_2.screen.getAllByRole('button', { name: deleteButtonLabel });
|
|
180
|
+
yield user_event_1.default.click(deleteButton[1]);
|
|
181
|
+
yield (0, react_2.waitFor)(() => expect(notifySpy).toHaveBeenCalled());
|
|
182
|
+
yield (0, react_2.waitFor)(() => expect(react_2.screen.queryByText('Test prop 2')).not.toBeInTheDocument());
|
|
183
|
+
}));
|
|
364
184
|
});
|
|
365
|
-
describe('Layout behaviour',
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
});
|
|
394
|
-
}); });
|
|
395
|
-
it('should show always collection items when layout set to itemsAlways', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
396
|
-
return __generator(this, function (_a) {
|
|
397
|
-
switch (_a.label) {
|
|
398
|
-
case 0:
|
|
399
|
-
renderWith('itemsAlways');
|
|
400
|
-
expect(itemsView()).toBeInTheDocument();
|
|
401
|
-
expect(formView()).not.toBeInTheDocument();
|
|
402
|
-
return [4 /*yield*/, user_event_1.default.click(addButton())];
|
|
403
|
-
case 1:
|
|
404
|
-
_a.sent();
|
|
405
|
-
expect(itemsView()).toBeInTheDocument();
|
|
406
|
-
expect(formView()).toBeInTheDocument();
|
|
407
|
-
return [2 /*return*/];
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
}); });
|
|
411
|
-
it('should show always form view and items view when layout set to formAndItems', function () {
|
|
185
|
+
describe('Layout behaviour', () => {
|
|
186
|
+
const itemsView = () => react_2.screen.queryByRole('heading', { name: crudLabels.documentsInCollectionCaption });
|
|
187
|
+
const formView = () => react_2.screen.queryByRole('heading', { name: viewHeader });
|
|
188
|
+
const addButton = () => react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel });
|
|
189
|
+
const renderWith = (layout) => __awaiter(void 0, void 0, void 0, function* () {
|
|
190
|
+
renderResult.rerender(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: crudLabels, layout: layout },
|
|
191
|
+
react_1.default.createElement(TestView, null),
|
|
192
|
+
(props) => (react_1.default.createElement("div", null,
|
|
193
|
+
react_1.default.createElement("p", null, props.document.testProp),
|
|
194
|
+
react_1.default.createElement("button", { onClick: () => props.onSelect(props.document) }, editButtonLabel),
|
|
195
|
+
react_1.default.createElement("button", { onClick: () => props.onDelete(props.document) }, deleteButtonLabel)))));
|
|
196
|
+
});
|
|
197
|
+
it('should show always collection items when default layout', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
198
|
+
expect(itemsView()).toBeInTheDocument();
|
|
199
|
+
expect(formView()).not.toBeInTheDocument();
|
|
200
|
+
yield user_event_1.default.click(addButton());
|
|
201
|
+
expect(itemsView()).toBeInTheDocument();
|
|
202
|
+
expect(formView()).toBeInTheDocument();
|
|
203
|
+
}));
|
|
204
|
+
it('should show always collection items when layout set to itemsAlways', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
205
|
+
renderWith('itemsAlways');
|
|
206
|
+
expect(itemsView()).toBeInTheDocument();
|
|
207
|
+
expect(formView()).not.toBeInTheDocument();
|
|
208
|
+
yield user_event_1.default.click(addButton());
|
|
209
|
+
expect(itemsView()).toBeInTheDocument();
|
|
210
|
+
expect(formView()).toBeInTheDocument();
|
|
211
|
+
}));
|
|
212
|
+
it('should show always form view and items view when layout set to formAndItems', () => {
|
|
412
213
|
renderWith('formAndItems');
|
|
413
214
|
expect(itemsView()).toBeInTheDocument();
|
|
414
215
|
expect(formView()).toBeInTheDocument();
|
|
415
216
|
});
|
|
416
|
-
it('should alternate from form view to items view but not both when layout set to formOrItems',
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
case 1:
|
|
425
|
-
_a.sent();
|
|
426
|
-
expect(itemsView()).not.toBeInTheDocument();
|
|
427
|
-
expect(formView()).toBeInTheDocument();
|
|
428
|
-
return [2 /*return*/];
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
}); });
|
|
217
|
+
it('should alternate from form view to items view but not both when layout set to formOrItems', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
218
|
+
renderWith('formOrItems');
|
|
219
|
+
expect(itemsView()).toBeInTheDocument();
|
|
220
|
+
expect(formView()).not.toBeInTheDocument();
|
|
221
|
+
yield user_event_1.default.click(addButton());
|
|
222
|
+
expect(itemsView()).not.toBeInTheDocument();
|
|
223
|
+
expect(formView()).toBeInTheDocument();
|
|
224
|
+
}));
|
|
432
225
|
});
|
|
433
|
-
describe('Labels',
|
|
434
|
-
it('should
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
226
|
+
describe('Labels', () => {
|
|
227
|
+
it('should show singular when only one existing document', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
228
|
+
expect(react_2.screen.queryByText('Test prop 2')).toBeInTheDocument();
|
|
229
|
+
const deleteButton = react_2.screen.getAllByRole('button', { name: deleteButtonLabel });
|
|
230
|
+
yield user_event_1.default.click(deleteButton[1]);
|
|
231
|
+
yield (0, react_2.waitFor)(() => expect(notifySpy).toHaveBeenCalled());
|
|
232
|
+
const heading = yield react_2.screen.findByRole('heading', { name: crudLabels.singularDocumentInCollectionCaption });
|
|
233
|
+
expect(heading).toBeInTheDocument();
|
|
234
|
+
}));
|
|
235
|
+
it('should show plural when only one existing document but empty singular caption', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
236
|
+
crudLabels.singularDocumentInCollectionCaption = undefined;
|
|
237
|
+
expect(react_2.screen.queryByText('Test prop 2')).toBeInTheDocument();
|
|
238
|
+
const deleteButton = react_2.screen.getAllByRole('button', { name: deleteButtonLabel });
|
|
239
|
+
user_event_1.default.click(deleteButton[1]);
|
|
240
|
+
yield (0, react_2.waitFor)(() => expect(notifySpy).toHaveBeenCalled());
|
|
241
|
+
const heading = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption });
|
|
242
|
+
expect(heading).toBeInTheDocument();
|
|
243
|
+
}));
|
|
244
|
+
it('should allow to pass labels as a function', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
|
+
const labels = (controller) => Object.entries(crudLabels)
|
|
246
|
+
.reduce((prev, [key, label]) => {
|
|
247
|
+
prev[key] = `${label} ${controller.document.className}`;
|
|
248
|
+
return prev;
|
|
249
|
+
}, {});
|
|
250
|
+
renderResult.rerender(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: labels },
|
|
251
|
+
react_1.default.createElement(TestView, null),
|
|
252
|
+
(props) => (react_1.default.createElement("div", null,
|
|
253
|
+
react_1.default.createElement("p", null, props.document.testProp),
|
|
254
|
+
react_1.default.createElement("button", { onClick: () => props.onSelect(props.document) }, editButtonLabel),
|
|
255
|
+
react_1.default.createElement("button", { onClick: () => props.onDelete(props.document) }, deleteButtonLabel)))));
|
|
256
|
+
const documentClassName = controller.createDocument().className;
|
|
257
|
+
expect(react_2.screen.getByText(`${crudLabels.addNewDocumentLabel} ${documentClassName}`)).toBeInTheDocument();
|
|
258
|
+
expect(react_2.screen.getByText(`${crudLabels.documentsInCollectionCaption} ${documentClassName}`)).toBeInTheDocument();
|
|
259
|
+
}));
|
|
260
|
+
it('should not throw on undefined labels', () => {
|
|
261
|
+
expect(() => renderResult.rerender(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: undefined },
|
|
262
|
+
react_1.default.createElement(TestView, null),
|
|
263
|
+
react_1.default.createElement(TestCard, null)))).not.toThrow();
|
|
264
|
+
});
|
|
455
265
|
});
|
|
456
266
|
});
|
|
457
267
|
//# sourceMappingURL=crud-panel.spec.js.map
|