Skip to content

Commit 7694648

Browse files
committed
add tests and update selection
1 parent 54e086a commit 7694648

File tree

3 files changed

+72
-9
lines changed

3 files changed

+72
-9
lines changed

packages/compass-data-modeling/src/components/drawer/diagram-editor-side-panel.spec.tsx

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ const waitForDrawerToOpen = async () => {
3636
});
3737
};
3838

39+
const updateInputWithBlur = (label: string, text: string) => {
40+
const input = screen.getByLabelText(label);
41+
userEvent.clear(input);
42+
userEvent.type(input, text);
43+
44+
// Blur/unfocus the input.
45+
userEvent.click(document.body);
46+
};
47+
3948
async function comboboxSelectItem(
4049
label: string,
4150
value: string,
@@ -136,8 +145,8 @@ describe('DiagramEditorSidePanel', function () {
136145
).to.be.visible;
137146
});
138147

139-
describe('Field context drawer', function () {
140-
it('should render a field context drawer when field is clicked', async function () {
148+
describe('When a field is selected', function () {
149+
it('should render a field context drawer', async function () {
141150
const result = renderDrawer();
142151
result.plugin.store.dispatch(selectField('flights.airlines', ['alias']));
143152

@@ -154,7 +163,7 @@ describe('DiagramEditorSidePanel', function () {
154163
expect(selectedTypes).to.include('int');
155164
});
156165

157-
it('should render a nested field context drawer when field is clicked', async function () {
166+
it('should render a nested field context drawer', async function () {
158167
const result = renderDrawer();
159168
result.plugin.store.dispatch(
160169
selectField('flights.routes', ['airline', 'id'])
@@ -171,6 +180,53 @@ describe('DiagramEditorSidePanel', function () {
171180
expect(selectedTypes).to.have.lengthOf(1);
172181
expect(selectedTypes).to.include('string');
173182
});
183+
184+
it('should delete a field', async function () {
185+
const result = renderDrawer();
186+
result.plugin.store.dispatch(
187+
selectField('flights.routes', ['airline', 'id'])
188+
);
189+
190+
await waitForDrawerToOpen();
191+
expect(screen.getByTitle('routes.airline.id')).to.be.visible;
192+
193+
userEvent.click(screen.getByLabelText(/delete field/i));
194+
195+
await waitFor(() => {
196+
expect(screen.queryByText('routes.airline.id')).not.to.exist;
197+
});
198+
expect(screen.queryByLabelText('Name')).to.not.exist;
199+
200+
const modifiedCollection = selectCurrentModelFromState(
201+
result.plugin.store.getState()
202+
).collections.find((coll) => {
203+
return coll.ns === 'flights.routes';
204+
});
205+
206+
expect(
207+
modifiedCollection.jsonSchema.properties.airline.properties
208+
).to.not.have.property('id'); // deleted field
209+
expect(
210+
modifiedCollection.jsonSchema.properties.airline.properties
211+
).to.have.property('name'); // sibling field remains
212+
});
213+
214+
it('should rename a field and keep it selected', async function () {
215+
const result = renderDrawer();
216+
result.plugin.store.dispatch(
217+
selectField('flights.routes', ['airline', 'name'])
218+
);
219+
220+
await waitForDrawerToOpen();
221+
expect(screen.getByTitle('routes.airline.name')).to.be.visible;
222+
223+
updateInputWithBlur('Field name', 'new_name');
224+
225+
await waitFor(() => {
226+
expect(screen.queryByText('routes.airline.name')).not.to.exist;
227+
expect(screen.queryByText('routes.airline.new_name')).to.exist;
228+
});
229+
});
174230
});
175231

176232
it('should change the content of the drawer when selecting different items', async function () {
@@ -486,11 +542,7 @@ describe('DiagramEditorSidePanel', function () {
486542
expect(activeElement).to.equal(nameInput);
487543

488544
// Update the name.
489-
userEvent.clear(nameInput);
490-
userEvent.type(nameInput, 'pineapple');
491-
492-
// Blur/unfocus the input - now the collection should be names
493-
userEvent.click(document.body);
545+
updateInputWithBlur('Name', 'pineapple');
494546

495547
// Check the name in the model.
496548
const newCollection = selectCurrentModelFromState(

packages/compass-data-modeling/src/components/drawer/diagram-editor-side-panel.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ function DiagramEditorSidePanel({
110110
></FieldDrawerContent>
111111
),
112112
actions: [
113-
{ action: 'delete', label: 'Delete', icon: 'Trash' as const },
113+
{
114+
action: 'delete',
115+
label: 'Delete Field',
116+
icon: 'Trash' as const,
117+
},
114118
],
115119
handleAction: (actionName: string) => {
116120
if (actionName === 'delete') {

packages/compass-data-modeling/src/store/diagram.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ const updateSelectedItemsFromAppliedEdit = (
387387
id: edit.ns,
388388
};
389389
}
390+
case 'RenameField': {
391+
return {
392+
type: 'field',
393+
namespace: edit.ns,
394+
fieldPath: [...edit.from.slice(0, edit.from.length - 1), edit.to],
395+
};
396+
}
390397
}
391398

392399
return currentSelection;

0 commit comments

Comments
 (0)