@entropic-bond/crud-panel 3.4.0 → 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.
@@ -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
- var react_1 = __importStar(require("react"));
92
- var react_2 = require("@testing-library/react");
93
- var user_event_1 = __importDefault(require("@testing-library/user-event"));
94
- var entropic_bond_1 = require("entropic-bond");
95
- var crud_panel_1 = require("./crud-panel");
96
- var crud_controller_spec_1 = require("./crud-controller.spec");
97
- var crudLabels = {
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
- var testViewPlaceholder = 'Test View Placeholder';
106
- var editButtonLabel = 'Edit';
107
- var deleteButtonLabel = 'Delete';
108
- var cancelButtonCaption = 'Cancel';
109
- var viewHeader = 'View header';
110
- var mockData = {
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,91 +68,71 @@ var mockData = {
121
68
  }
122
69
  }
123
70
  };
124
- var TestView = /** @class */ (function (_super) {
125
- __extends(TestView, _super);
126
- function TestView() {
127
- return _super !== null && _super.apply(this, arguments) || this;
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
- _this.setState(e.documentProps);
76
+ this.setState(e.documentProps);
135
77
  });
136
- };
137
- TestView.prototype.render = function () {
138
- var _a = this.props, controller = _a.controller, onCancel = _a.onCancel, onSubmit = _a.onSubmit, submitButtonCaption = _a.submitButtonCaption;
139
- var document = controller.document;
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: function (e) { return document.testProp = e.target.value; } }),
143
- react_1.default.createElement("button", { onClick: function () { return onSubmit(document); } }, submitButtonCaption),
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
- TestCard.prototype.render = function () {
154
- var _a = this.props, document = _a.document, onDelete = _a.onDelete, onSelect = _a.onSelect;
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: function () { return onSelect(document); } }, editButtonLabel),
158
- react_1.default.createElement("button", { onClick: function () { return onDelete(document); } }, deleteButtonLabel)));
159
- };
160
- return TestCard;
161
- }(react_1.Component));
162
- describe('Crud Panel', function () {
163
- var controller;
164
- var notifySpy;
165
- var renderResult;
166
- var datasource;
167
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
168
- return __generator(this, function (_a) {
169
- switch (_a.label) {
170
- case 0:
171
- datasource = new entropic_bond_1.JsonDataSource(JSON.parse(JSON.stringify(mockData)));
172
- entropic_bond_1.Store.useDataSource(datasource);
173
- controller = new crud_controller_spec_1.TestController();
174
- notifySpy = jest.fn();
175
- controller.onChange(notifySpy);
176
- renderResult = (0, react_2.render)(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: crudLabels },
177
- react_1.default.createElement(TestView, null),
178
- react_1.default.createElement(TestCard, null)));
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', function () {
192
- var docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
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
- describe('Accepts children as functions', function () {
198
- beforeEach(function () {
124
+ describe('Accepts children as functions', () => {
125
+ beforeEach(() => {
199
126
  user_event_1.default.setup();
200
127
  renderResult.rerender(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: crudLabels },
201
- function (props) { return react_1.default.createElement(TestView, __assign({}, props)); },
202
- function (props) { return react_1.default.createElement(TestCard, __assign({}, props)); }));
128
+ props => react_1.default.createElement(TestView, Object.assign({}, props)),
129
+ props => react_1.default.createElement(TestCard, Object.assign({}, props))));
203
130
  });
204
- it('should show add button', function () {
131
+ it('should show add button', () => {
205
132
  expect(react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel })).toBeInTheDocument();
206
133
  });
207
- it('should show existing documents', function () {
208
- var docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
134
+ it('should show existing documents', () => {
135
+ const docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
209
136
  expect((0, react_2.within)(docs).getByText('Test prop 1')).toBeInTheDocument();
210
137
  expect((0, react_2.within)(docs).getByText('Test prop 2')).toBeInTheDocument();
211
138
  expect(docs.children.length).toBe(2);
@@ -213,249 +140,127 @@ describe('Crud Panel', function () {
213
140
  expect(react_2.screen.getAllByRole('button', { name: deleteButtonLabel })[0]).toBeInTheDocument();
214
141
  });
215
142
  });
216
- describe('Working with TestView', function () {
217
- it('should create an empty document view on add new document button click', function () { return __awaiter(void 0, void 0, void 0, function () {
218
- return __generator(this, function (_a) {
219
- switch (_a.label) {
220
- case 0: return [4 /*yield*/, user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel }))];
221
- case 1:
222
- _a.sent();
223
- expect(react_2.screen.getByRole('heading', { name: viewHeader })).toBeInTheDocument();
224
- expect(react_2.screen.getByPlaceholderText(testViewPlaceholder)).toHaveDisplayValue('');
225
- return [2 /*return*/];
226
- }
227
- });
228
- }); });
229
- it('should show detail view with document data on edit button click', function () { return __awaiter(void 0, void 0, void 0, function () {
230
- var testDoc, editButton;
231
- return __generator(this, function (_a) {
232
- switch (_a.label) {
233
- case 0:
234
- testDoc = mockData.Test.test1;
235
- editButton = react_2.screen.getAllByRole('button', { name: editButtonLabel });
236
- return [4 /*yield*/, user_event_1.default.click(editButton[0])];
237
- case 1:
238
- _a.sent();
239
- expect(react_2.screen.getByRole('heading', { name: viewHeader })).toBeInTheDocument();
240
- expect(react_2.screen.getByDisplayValue(testDoc.testProp)).toBeInTheDocument();
241
- return [2 /*return*/];
242
- }
243
- });
244
- }); });
245
- it('should refresh document list on new document added', function () { return __awaiter(void 0, void 0, void 0, function () {
246
- var input, docs, _a;
247
- return __generator(this, function (_b) {
248
- switch (_b.label) {
249
- case 0: return [4 /*yield*/, user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel }))];
250
- case 1:
251
- _b.sent();
252
- return [4 /*yield*/, react_2.screen.findByPlaceholderText(testViewPlaceholder)];
253
- case 2:
254
- input = _b.sent();
255
- return [4 /*yield*/, user_event_1.default.type(input, 'New and fancy Application')];
256
- case 3:
257
- _b.sent();
258
- return [4 /*yield*/, user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.addButtonLabel }))];
259
- case 4:
260
- _b.sent();
261
- docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
262
- _a = expect;
263
- return [4 /*yield*/, (0, react_2.within)(docs).findByText('New and fancy Application')];
264
- case 5:
265
- _a.apply(void 0, [_b.sent()]).toBeInTheDocument();
266
- return [2 /*return*/];
267
- }
268
- });
269
- }); });
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
+ }));
270
164
  });
271
- describe('Working with detail card buttons', function () {
272
- it('should refresh document list on document edited', function () { return __awaiter(void 0, void 0, void 0, function () {
273
- var editButton, input, docs, _a;
274
- return __generator(this, function (_b) {
275
- switch (_b.label) {
276
- case 0:
277
- editButton = react_2.screen.getAllByRole('button', { name: editButtonLabel });
278
- return [4 /*yield*/, user_event_1.default.click(editButton[0])];
279
- case 1:
280
- _b.sent();
281
- return [4 /*yield*/, react_2.screen.findByPlaceholderText(testViewPlaceholder)];
282
- case 2:
283
- input = _b.sent();
284
- return [4 /*yield*/, user_event_1.default.click(input)];
285
- case 3:
286
- _b.sent();
287
- return [4 /*yield*/, user_event_1.default.paste(' Edited')];
288
- case 4:
289
- _b.sent();
290
- return [4 /*yield*/, user_event_1.default.click(react_2.screen.getByRole('button', { name: crudLabels.updateButtonLabel }))];
291
- case 5:
292
- _b.sent();
293
- return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(notifySpy).toHaveBeenCalled(); })];
294
- case 6:
295
- _b.sent();
296
- docs = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption }).nextElementSibling;
297
- _a = expect;
298
- return [4 /*yield*/, (0, react_2.within)(docs).findByText('Test prop 1 Edited')];
299
- case 7:
300
- _a.apply(void 0, [_b.sent()]).toBeInTheDocument();
301
- return [2 /*return*/];
302
- }
303
- });
304
- }); });
305
- it('should delete document and remove from the list', function () { return __awaiter(void 0, void 0, void 0, function () {
306
- var deleteButton;
307
- return __generator(this, function (_a) {
308
- switch (_a.label) {
309
- case 0:
310
- expect(react_2.screen.queryByText('Test prop 2')).toBeInTheDocument();
311
- deleteButton = react_2.screen.getAllByRole('button', { name: deleteButtonLabel });
312
- return [4 /*yield*/, user_event_1.default.click(deleteButton[1])];
313
- case 1:
314
- _a.sent();
315
- return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(notifySpy).toHaveBeenCalled(); })];
316
- case 2:
317
- _a.sent();
318
- return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(react_2.screen.queryByText('Test prop 2')).not.toBeInTheDocument(); })];
319
- case 3:
320
- _a.sent();
321
- return [2 /*return*/];
322
- }
323
- });
324
- }); });
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
+ }));
325
184
  });
326
- describe('Layout behaviour', function () {
327
- var itemsView = function () { return react_2.screen.queryByRole('heading', { name: crudLabels.documentsInCollectionCaption }); };
328
- var formView = function () { return react_2.screen.queryByRole('heading', { name: viewHeader }); };
329
- var addButton = function () { return react_2.screen.getByRole('button', { name: crudLabels.addNewDocumentLabel }); };
330
- var renderWith = function (layout) { return __awaiter(void 0, void 0, void 0, function () {
331
- return __generator(this, function (_a) {
332
- renderResult.rerender(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: crudLabels, layout: layout },
333
- react_1.default.createElement(TestView, null),
334
- function (props) { return (react_1.default.createElement("div", null,
335
- react_1.default.createElement("p", null, props.document.testProp),
336
- react_1.default.createElement("button", { onClick: function () { return props.onSelect(props.document); } }, editButtonLabel),
337
- react_1.default.createElement("button", { onClick: function () { return props.onDelete(props.document); } }, deleteButtonLabel))); }));
338
- return [2 /*return*/];
339
- });
340
- }); };
341
- it('should show always collection items when default layout', function () { return __awaiter(void 0, void 0, void 0, function () {
342
- return __generator(this, function (_a) {
343
- switch (_a.label) {
344
- case 0:
345
- expect(itemsView()).toBeInTheDocument();
346
- expect(formView()).not.toBeInTheDocument();
347
- return [4 /*yield*/, user_event_1.default.click(addButton())];
348
- case 1:
349
- _a.sent();
350
- expect(itemsView()).toBeInTheDocument();
351
- expect(formView()).toBeInTheDocument();
352
- return [2 /*return*/];
353
- }
354
- });
355
- }); });
356
- it('should show always collection items when layout set to itemsAlways', function () { return __awaiter(void 0, void 0, void 0, function () {
357
- return __generator(this, function (_a) {
358
- switch (_a.label) {
359
- case 0:
360
- renderWith('itemsAlways');
361
- expect(itemsView()).toBeInTheDocument();
362
- expect(formView()).not.toBeInTheDocument();
363
- return [4 /*yield*/, user_event_1.default.click(addButton())];
364
- case 1:
365
- _a.sent();
366
- expect(itemsView()).toBeInTheDocument();
367
- expect(formView()).toBeInTheDocument();
368
- return [2 /*return*/];
369
- }
370
- });
371
- }); });
372
- 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', () => {
373
213
  renderWith('formAndItems');
374
214
  expect(itemsView()).toBeInTheDocument();
375
215
  expect(formView()).toBeInTheDocument();
376
216
  });
377
- it('should alternate from form view to items view but not both when layout set to formOrItems', function () { return __awaiter(void 0, void 0, void 0, function () {
378
- return __generator(this, function (_a) {
379
- switch (_a.label) {
380
- case 0:
381
- renderWith('formOrItems');
382
- expect(itemsView()).toBeInTheDocument();
383
- expect(formView()).not.toBeInTheDocument();
384
- return [4 /*yield*/, user_event_1.default.click(addButton())];
385
- case 1:
386
- _a.sent();
387
- expect(itemsView()).not.toBeInTheDocument();
388
- expect(formView()).toBeInTheDocument();
389
- return [2 /*return*/];
390
- }
391
- });
392
- }); });
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
+ }));
393
225
  });
394
- describe('Labels', function () {
395
- it('should show singular when only one existing document', function () { return __awaiter(void 0, void 0, void 0, function () {
396
- var deleteButton, heading;
397
- return __generator(this, function (_a) {
398
- switch (_a.label) {
399
- case 0:
400
- expect(react_2.screen.queryByText('Test prop 2')).toBeInTheDocument();
401
- deleteButton = react_2.screen.getAllByRole('button', { name: deleteButtonLabel });
402
- return [4 /*yield*/, user_event_1.default.click(deleteButton[1])];
403
- case 1:
404
- _a.sent();
405
- return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(notifySpy).toHaveBeenCalled(); })];
406
- case 2:
407
- _a.sent();
408
- return [4 /*yield*/, react_2.screen.findByRole('heading', { name: crudLabels.singularDocumentInCollectionCaption })];
409
- case 3:
410
- heading = _a.sent();
411
- expect(heading).toBeInTheDocument();
412
- return [2 /*return*/];
413
- }
414
- });
415
- }); });
416
- it('should show plural when only one existing document but empty singular caption', function () { return __awaiter(void 0, void 0, void 0, function () {
417
- var deleteButton, heading;
418
- return __generator(this, function (_a) {
419
- switch (_a.label) {
420
- case 0:
421
- crudLabels.singularDocumentInCollectionCaption = undefined;
422
- expect(react_2.screen.queryByText('Test prop 2')).toBeInTheDocument();
423
- deleteButton = react_2.screen.getAllByRole('button', { name: deleteButtonLabel });
424
- user_event_1.default.click(deleteButton[1]);
425
- return [4 /*yield*/, (0, react_2.waitFor)(function () { return expect(notifySpy).toHaveBeenCalled(); })];
426
- case 1:
427
- _a.sent();
428
- heading = react_2.screen.getByRole('heading', { name: crudLabels.documentsInCollectionCaption });
429
- expect(heading).toBeInTheDocument();
430
- return [2 /*return*/];
431
- }
432
- });
433
- }); });
434
- it('should allow to pass labels as a function', function () { return __awaiter(void 0, void 0, void 0, function () {
435
- var labels, documentClassName;
436
- return __generator(this, function (_a) {
437
- labels = function (controller) { return Object.entries(crudLabels)
438
- .reduce(function (prev, _a) {
439
- var key = _a[0], label = _a[1];
440
- prev[key] = "".concat(label, " ").concat(controller.document.className);
441
- return prev;
442
- }, {}); };
443
- renderResult.rerender(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: labels },
444
- react_1.default.createElement(TestView, null),
445
- function (props) { return (react_1.default.createElement("div", null,
446
- react_1.default.createElement("p", null, props.document.testProp),
447
- react_1.default.createElement("button", { onClick: function () { return props.onSelect(props.document); } }, editButtonLabel),
448
- react_1.default.createElement("button", { onClick: function () { return props.onDelete(props.document); } }, deleteButtonLabel))); }));
449
- documentClassName = controller.createDocument().className;
450
- expect(react_2.screen.getByText("".concat(crudLabels.addNewDocumentLabel, " ").concat(documentClassName))).toBeInTheDocument();
451
- expect(react_2.screen.getByText("".concat(crudLabels.documentsInCollectionCaption, " ").concat(documentClassName))).toBeInTheDocument();
452
- return [2 /*return*/];
453
- });
454
- }); });
455
- it('should not throw on undefined labels', function () {
456
- expect(function () { return renderResult.rerender(react_1.default.createElement(crud_panel_1.CrudPanel, { controller: controller, labels: undefined },
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 },
457
262
  react_1.default.createElement(TestView, null),
458
- react_1.default.createElement(TestCard, null))); }).not.toThrow();
263
+ react_1.default.createElement(TestCard, null)))).not.toThrow();
459
264
  });
460
265
  });
461
266
  });