@evoke-platform/ui-components 1.10.0-testing.2 → 1.10.0-testing.3
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.
|
@@ -87,7 +87,7 @@ export const ActionDialog = (props) => {
|
|
|
87
87
|
borderBottom: action.type === 'delete' ? undefined : '1px solid #e9ecef',
|
|
88
88
|
} },
|
|
89
89
|
action && hasAccess && !loading ? action?.name : '',
|
|
90
|
-
React.createElement(IconButton, { sx: styles.closeIcon, onClick: onClose },
|
|
90
|
+
React.createElement(IconButton, { sx: styles.closeIcon, onClick: onClose, "aria-label": "Close" },
|
|
91
91
|
React.createElement(Close, { fontSize: "small" })),
|
|
92
92
|
formHeaderProps.hasAccordions && React.createElement(AccordionActions, { ...formHeaderProps })));
|
|
93
93
|
}, renderBody: (bodyProps) => (React.createElement(DialogContent, { sx: {
|
|
@@ -1021,4 +1021,210 @@ describe('Form component', () => {
|
|
|
1021
1021
|
});
|
|
1022
1022
|
});
|
|
1023
1023
|
});
|
|
1024
|
+
describe('when passed a one-to-many collection entry', () => {
|
|
1025
|
+
const setupTestMocks = (object, form, instances) => {
|
|
1026
|
+
server.use(http.get(`/api/data/objects/${object.id}/effective`, () => HttpResponse.json(object)), http.get(`/api/data/forms/${form.id}`, () => HttpResponse.json(form)), http.get(`/api/data/forms?filter={"where":{"actionId":"${form.actionId}","objectId":"${object.id}"}}`, () => HttpResponse.json([form])), http.get(`/api/data/objects/${object.id}/instances`, () => HttpResponse.json(instances || [])), http.get(`/api/data/objects/${object.id}/instances/checkAccess`, () => HttpResponse.json({
|
|
1027
|
+
result: true,
|
|
1028
|
+
})));
|
|
1029
|
+
};
|
|
1030
|
+
const form = {
|
|
1031
|
+
id: 'collectionTestForm',
|
|
1032
|
+
name: 'Collection Test Form',
|
|
1033
|
+
entries: [
|
|
1034
|
+
{
|
|
1035
|
+
type: 'inputField',
|
|
1036
|
+
input: {
|
|
1037
|
+
id: 'collection',
|
|
1038
|
+
type: 'collection',
|
|
1039
|
+
objectId: 'collectionObject',
|
|
1040
|
+
relatedPropertyId: 'relatedObject',
|
|
1041
|
+
},
|
|
1042
|
+
display: {
|
|
1043
|
+
label: 'Collection',
|
|
1044
|
+
},
|
|
1045
|
+
},
|
|
1046
|
+
],
|
|
1047
|
+
actionId: '_update',
|
|
1048
|
+
objectId: 'testObjectForCollections',
|
|
1049
|
+
};
|
|
1050
|
+
beforeEach(() => {
|
|
1051
|
+
const collectionFormObject = {
|
|
1052
|
+
id: 'testObjectForCollections',
|
|
1053
|
+
name: 'Object for one-to-many collections tests',
|
|
1054
|
+
actions: [
|
|
1055
|
+
{
|
|
1056
|
+
id: '_update',
|
|
1057
|
+
name: 'Update',
|
|
1058
|
+
type: 'update',
|
|
1059
|
+
outputEvent: 'updated',
|
|
1060
|
+
},
|
|
1061
|
+
],
|
|
1062
|
+
properties: [
|
|
1063
|
+
{
|
|
1064
|
+
id: 'collection',
|
|
1065
|
+
name: 'Collection',
|
|
1066
|
+
type: 'collection',
|
|
1067
|
+
objectId: 'collectionObject',
|
|
1068
|
+
relatedPropertyId: 'relatedObject',
|
|
1069
|
+
},
|
|
1070
|
+
],
|
|
1071
|
+
};
|
|
1072
|
+
setupTestMocks(collectionFormObject, form);
|
|
1073
|
+
const collectionObject = {
|
|
1074
|
+
id: 'collectionObject',
|
|
1075
|
+
name: 'Collection Object',
|
|
1076
|
+
properties: [
|
|
1077
|
+
{
|
|
1078
|
+
name: 'Name',
|
|
1079
|
+
id: 'name',
|
|
1080
|
+
type: 'string',
|
|
1081
|
+
},
|
|
1082
|
+
{
|
|
1083
|
+
name: 'Related Object',
|
|
1084
|
+
id: 'relatedObject',
|
|
1085
|
+
type: 'object',
|
|
1086
|
+
objectId: 'testObjectForCollections',
|
|
1087
|
+
},
|
|
1088
|
+
],
|
|
1089
|
+
actions: [
|
|
1090
|
+
{
|
|
1091
|
+
id: '_create',
|
|
1092
|
+
name: 'Create',
|
|
1093
|
+
type: 'create',
|
|
1094
|
+
outputEvent: 'created',
|
|
1095
|
+
parameters: [
|
|
1096
|
+
{
|
|
1097
|
+
id: 'name',
|
|
1098
|
+
name: 'Name',
|
|
1099
|
+
type: 'string',
|
|
1100
|
+
},
|
|
1101
|
+
{
|
|
1102
|
+
id: 'relatedObject',
|
|
1103
|
+
name: 'Related Object',
|
|
1104
|
+
type: 'object',
|
|
1105
|
+
objectId: 'testObjectForCollections',
|
|
1106
|
+
},
|
|
1107
|
+
],
|
|
1108
|
+
},
|
|
1109
|
+
],
|
|
1110
|
+
};
|
|
1111
|
+
const collectionObjectForm = {
|
|
1112
|
+
id: 'collectionObjectForm',
|
|
1113
|
+
name: 'Collection Object Form',
|
|
1114
|
+
entries: [
|
|
1115
|
+
{
|
|
1116
|
+
type: 'input',
|
|
1117
|
+
parameterId: 'name',
|
|
1118
|
+
display: {
|
|
1119
|
+
label: 'Name',
|
|
1120
|
+
},
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
type: 'input',
|
|
1124
|
+
parameterId: 'relatedObject',
|
|
1125
|
+
display: {
|
|
1126
|
+
label: 'Related Object',
|
|
1127
|
+
relatedObjectDisplay: 'dropdown',
|
|
1128
|
+
},
|
|
1129
|
+
},
|
|
1130
|
+
],
|
|
1131
|
+
actionId: '_create',
|
|
1132
|
+
objectId: 'collectionObject',
|
|
1133
|
+
};
|
|
1134
|
+
setupTestMocks(collectionObject, collectionObjectForm);
|
|
1135
|
+
});
|
|
1136
|
+
it('should render collection field', async () => {
|
|
1137
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1138
|
+
await screen.findByText('Collection');
|
|
1139
|
+
});
|
|
1140
|
+
it('should not render an add button if user does not have permission to create collection items', async () => {
|
|
1141
|
+
server.use(http.get('/api/data/objects/collectionObject/instances/checkAccess', () => HttpResponse.json({
|
|
1142
|
+
result: false,
|
|
1143
|
+
})));
|
|
1144
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1145
|
+
const addButton = screen.queryByRole('button', { name: /add/i });
|
|
1146
|
+
expect(addButton).not.toBeInTheDocument();
|
|
1147
|
+
});
|
|
1148
|
+
it('should render an add button for the collection when user has permission to create collection items', async () => {
|
|
1149
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1150
|
+
await screen.findByRole('button', { name: /add/i });
|
|
1151
|
+
});
|
|
1152
|
+
it('should open a dialog when clicking the add button', async () => {
|
|
1153
|
+
const user = userEvent.setup();
|
|
1154
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1155
|
+
const addButton = await screen.findByRole('button', { name: /add/i });
|
|
1156
|
+
await user.click(addButton);
|
|
1157
|
+
await screen.findByRole('dialog');
|
|
1158
|
+
});
|
|
1159
|
+
it('should render a close button in the collection dialog', async () => {
|
|
1160
|
+
const user = userEvent.setup();
|
|
1161
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1162
|
+
const addButton = await screen.findByRole('button', { name: /add/i });
|
|
1163
|
+
await user.click(addButton);
|
|
1164
|
+
await screen.findByRole('button', { name: 'Close' });
|
|
1165
|
+
});
|
|
1166
|
+
it('should allow closing the collection dialog using the close button', async () => {
|
|
1167
|
+
const user = userEvent.setup();
|
|
1168
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1169
|
+
const addButton = await screen.findByRole('button', { name: /add/i });
|
|
1170
|
+
await user.click(addButton);
|
|
1171
|
+
const dialog = await screen.findByRole('dialog');
|
|
1172
|
+
const closeButton = await screen.findByRole('button', { name: 'Close' });
|
|
1173
|
+
await user.click(closeButton);
|
|
1174
|
+
await waitFor(() => expect(dialog).not.toBeInTheDocument());
|
|
1175
|
+
});
|
|
1176
|
+
it('shows a cancel button in the collection dialog', async () => {
|
|
1177
|
+
const user = userEvent.setup();
|
|
1178
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1179
|
+
await user.click(await screen.findByRole('button', { name: 'Add' }));
|
|
1180
|
+
await screen.findByRole('button', { name: 'Cancel' });
|
|
1181
|
+
});
|
|
1182
|
+
it('closes dialog in the collection dialog clicking cancel', async () => {
|
|
1183
|
+
const user = userEvent.setup();
|
|
1184
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1185
|
+
await user.click(await screen.findByRole('button', { name: 'Add' }));
|
|
1186
|
+
const dialog = await screen.findByRole('dialog');
|
|
1187
|
+
await user.click(await screen.findByRole('button', { name: 'Cancel' }));
|
|
1188
|
+
await waitFor(() => expect(dialog).not.toBeInTheDocument());
|
|
1189
|
+
});
|
|
1190
|
+
it('displays a submit button in the collection dialog', async () => {
|
|
1191
|
+
const user = userEvent.setup();
|
|
1192
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1193
|
+
await user.click(await screen.findByRole('button', { name: 'Add' }));
|
|
1194
|
+
await screen.findByRole('button', { name: 'Submit' });
|
|
1195
|
+
});
|
|
1196
|
+
it('should hide related object field in collection item form', async () => {
|
|
1197
|
+
const user = userEvent.setup();
|
|
1198
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1199
|
+
const addButton = await screen.findByRole('button', { name: /add/i });
|
|
1200
|
+
await user.click(addButton);
|
|
1201
|
+
await screen.findByRole('dialog');
|
|
1202
|
+
// Make sure other form entry is present
|
|
1203
|
+
await screen.findByRole('textbox', { name: 'Name' });
|
|
1204
|
+
const relatedObjectField = screen.queryByRole('textbox', { name: 'Related Object' });
|
|
1205
|
+
expect(relatedObjectField).not.toBeInTheDocument();
|
|
1206
|
+
});
|
|
1207
|
+
it('should add newly created collection item to the collection list upon submission', async () => {
|
|
1208
|
+
const user = userEvent.setup();
|
|
1209
|
+
server.use(http.post('/api/data/objects/collectionObject/instances/actions', () => HttpResponse.json({
|
|
1210
|
+
id: 'newCollectionItemId',
|
|
1211
|
+
name: 'New Collection Item',
|
|
1212
|
+
objectId: 'collectionObject',
|
|
1213
|
+
relatedObject: {
|
|
1214
|
+
id: 'testInstanceId',
|
|
1215
|
+
name: 'Test Instance',
|
|
1216
|
+
},
|
|
1217
|
+
})));
|
|
1218
|
+
render(React.createElement(FormRenderer, { form: form, onChange: () => { } }));
|
|
1219
|
+
const addButton = await screen.findByRole('button', { name: /add/i });
|
|
1220
|
+
await user.click(addButton);
|
|
1221
|
+
await screen.findByRole('dialog');
|
|
1222
|
+
const nameField = screen.getByRole('textbox', { name: 'Name' });
|
|
1223
|
+
await user.type(nameField, 'New Collection Item');
|
|
1224
|
+
const submitButton = screen.getByRole('button', { name: 'Submit' });
|
|
1225
|
+
await user.click(submitButton);
|
|
1226
|
+
await screen.findByRole('columnheader', { name: 'Name' });
|
|
1227
|
+
screen.getByRole('cell', { name: 'New Collection Item' });
|
|
1228
|
+
});
|
|
1229
|
+
});
|
|
1024
1230
|
});
|