Skip to content

Commit b774b1d

Browse files
committed
update and add tests
1 parent e03907f commit b774b1d

File tree

3 files changed

+215
-20
lines changed

3 files changed

+215
-20
lines changed

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,37 @@ describe('DiagramEditorSidePanel', function () {
7070
result.plugin.store.dispatch(
7171
selectRelationship('204b1fc0-601f-4d62-bba3-38fade71e049')
7272
);
73-
expect(screen.getByText('Edit Relationship')).to.be.visible;
73+
74+
const name = screen.getByLabelText('Name');
75+
expect(name).to.be.visible;
76+
expect(name).to.have.value('Airport Country');
77+
78+
const localCollectionInput = screen.getByLabelText('Local collection');
79+
expect(localCollectionInput).to.be.visible;
80+
expect(localCollectionInput).to.have.value('countries');
81+
82+
const foreignCollectionInput = screen.getByLabelText('Foreign collection');
83+
expect(foreignCollectionInput).to.be.visible;
84+
expect(foreignCollectionInput).to.have.value('airports');
85+
86+
const localFieldInput = screen.getByLabelText('Local field');
87+
expect(localFieldInput).to.be.visible;
88+
expect(localFieldInput).to.have.value('name');
89+
90+
const foreignFieldInput = screen.getByLabelText('Foreign field');
91+
expect(foreignFieldInput).to.be.visible;
92+
expect(foreignFieldInput).to.have.value('Country');
93+
94+
const localCardinalityInput = screen.getByLabelText('Local cardinality');
95+
expect(localCardinalityInput).to.be.visible;
96+
expect(localCardinalityInput).to.have.value('1');
97+
98+
const foreignCardinalityInput = screen.getByLabelText(
99+
'Foreign cardinality'
100+
);
101+
expect(foreignCardinalityInput).to.be.visible;
102+
expect(foreignCardinalityInput).to.have.value('100');
103+
74104
expect(
75105
document.querySelector(
76106
'[data-relationship-id="204b1fc0-601f-4d62-bba3-38fade71e049"]'
@@ -123,7 +153,7 @@ describe('DiagramEditorSidePanel', function () {
123153
userEvent.click(
124154
within(relationshipCard!).getByRole('button', { name: 'Edit' })
125155
);
126-
expect(screen.getByText('Edit Relationship')).to.be.visible;
156+
expect(screen.getByLabelText('Local field')).to.be.visible;
127157

128158
// Select new values
129159
await comboboxSelectItem('Local collection', 'planes');
@@ -151,7 +181,7 @@ describe('DiagramEditorSidePanel', function () {
151181
{
152182
ns: 'flights.countries',
153183
fields: ['iso_code'],
154-
cardinality: 1,
184+
cardinality: 100,
155185
},
156186
]);
157187
});

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

Lines changed: 180 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,14 @@ describe('getFieldsFromSchema', function () {
262262
},
263263
});
264264
expect(result).to.deep.equal([
265-
{ name: 'name', type: 'string', depth: 0, glyphs: [] },
266-
{ name: 'age', type: 'int', depth: 0, glyphs: [] },
265+
{
266+
name: 'name',
267+
type: 'string',
268+
depth: 0,
269+
glyphs: [],
270+
variant: undefined,
271+
},
272+
{ name: 'age', type: 'int', depth: 0, glyphs: [], variant: undefined },
267273
]);
268274
});
269275

@@ -274,9 +280,45 @@ describe('getFieldsFromSchema', function () {
274280
age: { bsonType: ['int', 'string'] },
275281
},
276282
});
277-
expect(result[0]).to.deep.include({ name: 'age', depth: 0, glyphs: [] });
283+
expect(result[0]).to.deep.include({
284+
name: 'age',
285+
depth: 0,
286+
glyphs: [],
287+
variant: undefined,
288+
});
278289
await validateMixedType(result[0].type, /int, string/);
279290
});
291+
292+
it('highlights the correct field', function () {
293+
const result = getFieldsFromSchema(
294+
{
295+
bsonType: 'object',
296+
properties: {
297+
name: { bsonType: 'string' },
298+
age: { bsonType: 'int' },
299+
profession: { bsonType: 'string' },
300+
},
301+
},
302+
['age']
303+
);
304+
expect(result).to.deep.equal([
305+
{
306+
name: 'name',
307+
type: 'string',
308+
depth: 0,
309+
glyphs: [],
310+
variant: undefined,
311+
},
312+
{ name: 'age', type: 'int', depth: 0, glyphs: [], variant: 'preview' },
313+
{
314+
name: 'profession',
315+
type: 'string',
316+
depth: 0,
317+
glyphs: [],
318+
variant: undefined,
319+
},
320+
]);
321+
});
280322
});
281323

282324
describe('nested schema', function () {
@@ -300,11 +342,102 @@ describe('getFieldsFromSchema', function () {
300342
},
301343
});
302344
expect(result).to.deep.equal([
303-
{ name: 'person', type: 'object', depth: 0, glyphs: [] },
304-
{ name: 'name', type: 'string', depth: 1, glyphs: [] },
305-
{ name: 'address', type: 'object', depth: 1, glyphs: [] },
306-
{ name: 'street', type: 'string', depth: 2, glyphs: [] },
307-
{ name: 'city', type: 'string', depth: 2, glyphs: [] },
345+
{
346+
name: 'person',
347+
type: 'object',
348+
depth: 0,
349+
glyphs: [],
350+
variant: undefined,
351+
},
352+
{
353+
name: 'name',
354+
type: 'string',
355+
depth: 1,
356+
glyphs: [],
357+
variant: undefined,
358+
},
359+
{
360+
name: 'address',
361+
type: 'object',
362+
depth: 1,
363+
glyphs: [],
364+
variant: undefined,
365+
},
366+
{
367+
name: 'street',
368+
type: 'string',
369+
depth: 2,
370+
glyphs: [],
371+
variant: undefined,
372+
},
373+
{
374+
name: 'city',
375+
type: 'string',
376+
depth: 2,
377+
glyphs: [],
378+
variant: undefined,
379+
},
380+
]);
381+
});
382+
383+
it('highlights a field for a nested schema', function () {
384+
const result = getFieldsFromSchema(
385+
{
386+
bsonType: 'object',
387+
properties: {
388+
person: {
389+
bsonType: 'object',
390+
properties: {
391+
name: { bsonType: 'string' },
392+
address: {
393+
bsonType: 'object',
394+
properties: {
395+
street: { bsonType: 'string' },
396+
city: { bsonType: 'string' },
397+
},
398+
},
399+
},
400+
},
401+
},
402+
},
403+
['person', 'address', 'street']
404+
);
405+
expect(result).to.deep.equal([
406+
{
407+
name: 'person',
408+
type: 'object',
409+
depth: 0,
410+
glyphs: [],
411+
variant: undefined,
412+
},
413+
{
414+
name: 'name',
415+
type: 'string',
416+
depth: 1,
417+
glyphs: [],
418+
variant: undefined,
419+
},
420+
{
421+
name: 'address',
422+
type: 'object',
423+
depth: 1,
424+
glyphs: [],
425+
variant: undefined,
426+
},
427+
{
428+
name: 'street',
429+
type: 'string',
430+
depth: 2,
431+
glyphs: [],
432+
variant: 'preview',
433+
},
434+
{
435+
name: 'city',
436+
type: 'string',
437+
depth: 2,
438+
glyphs: [],
439+
variant: undefined,
440+
},
308441
]);
309442
});
310443

@@ -319,7 +452,7 @@ describe('getFieldsFromSchema', function () {
319452
},
320453
});
321454
expect(result).to.deep.equal([
322-
{ name: 'tags', type: '[]', depth: 0, glyphs: [] },
455+
{ name: 'tags', type: '[]', depth: 0, glyphs: [], variant: undefined },
323456
]);
324457
});
325458

@@ -340,9 +473,21 @@ describe('getFieldsFromSchema', function () {
340473
},
341474
});
342475
expect(result).to.deep.equal([
343-
{ name: 'todos', type: '[]', depth: 0, glyphs: [] },
344-
{ name: 'title', type: 'string', depth: 1, glyphs: [] },
345-
{ name: 'completed', type: 'boolean', depth: 1, glyphs: [] },
476+
{ name: 'todos', type: '[]', depth: 0, glyphs: [], variant: undefined },
477+
{
478+
name: 'title',
479+
type: 'string',
480+
depth: 1,
481+
glyphs: [],
482+
variant: undefined,
483+
},
484+
{
485+
name: 'completed',
486+
type: 'boolean',
487+
depth: 1,
488+
glyphs: [],
489+
variant: undefined,
490+
},
346491
]);
347492
});
348493

@@ -365,19 +510,26 @@ describe('getFieldsFromSchema', function () {
365510
},
366511
});
367512
expect(result).to.have.lengthOf(3);
368-
expect(result[0]).to.deep.include({ name: 'name', depth: 0, glyphs: [] });
513+
expect(result[0]).to.deep.include({
514+
name: 'name',
515+
depth: 0,
516+
glyphs: [],
517+
variant: undefined,
518+
});
369519
await validateMixedType(result[0].type, /string, object/);
370520
expect(result[1]).to.deep.equal({
371521
name: 'first',
372522
type: 'string',
373523
depth: 1,
374524
glyphs: [],
525+
variant: undefined,
375526
});
376527
expect(result[2]).to.deep.equal({
377528
name: 'last',
378529
type: 'string',
379530
depth: 1,
380531
glyphs: [],
532+
variant: undefined,
381533
});
382534
});
383535

@@ -403,9 +555,21 @@ describe('getFieldsFromSchema', function () {
403555
},
404556
});
405557
expect(result).to.deep.equal([
406-
{ name: 'todos', type: '[]', depth: 0, glyphs: [] },
407-
{ name: 'title', type: 'string', depth: 1, glyphs: [] },
408-
{ name: 'completed', type: 'boolean', depth: 1, glyphs: [] },
558+
{ name: 'todos', type: '[]', depth: 0, glyphs: [], variant: undefined },
559+
{
560+
name: 'title',
561+
type: 'string',
562+
depth: 1,
563+
glyphs: [],
564+
variant: undefined,
565+
},
566+
{
567+
name: 'completed',
568+
type: 'boolean',
569+
depth: 1,
570+
glyphs: [],
571+
variant: undefined,
572+
},
409573
]);
410574
});
411575
});

packages/compass-data-modeling/test/fixtures/data-model-with-relationships.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
"type": "AddRelationship",
262262
"relationship": {
263263
"id": "204b1fc0-601f-4d62-bba3-38fade71e049",
264+
"name": "Airport Country",
264265
"relationship": [
265266
{
266267
"ns": "flights.countries",
@@ -269,7 +270,7 @@
269270
},
270271
{
271272
"ns": "flights.airports",
272-
"cardinality": 1,
273+
"cardinality": 100,
273274
"fields": ["Country"]
274275
}
275276
],

0 commit comments

Comments
 (0)