Skip to content

Commit 93dfcf1

Browse files
authored
fix: allow multiple highlighted fields COMPASS-9650 (#7162)
1 parent 6959c9e commit 93dfcf1

File tree

3 files changed

+498
-364
lines changed

3 files changed

+498
-364
lines changed

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

Lines changed: 0 additions & 346 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {
44
createPluginTestHelpers,
55
screen,
66
waitFor,
7-
render,
8-
userEvent,
97
} from '@mongodb-js/testing-library-compass';
108
import DiagramEditor from './diagram-editor';
119
import type { DataModelingStore } from '../../test/setup-store';
@@ -18,7 +16,6 @@ import sinon from 'sinon';
1816
import { DiagramProvider } from '@mongodb-js/diagramming';
1917
import { DataModelingWorkspaceTab } from '..';
2018
import { openDiagram } from '../store/diagram';
21-
import { getFieldsFromSchema } from '../utils/nodes-and-edges';
2219

2320
const storageItems: MongoDBDataModelDescription[] = [
2421
{
@@ -201,346 +198,3 @@ describe('DiagramEditor', function () {
201198
});
202199
});
203200
});
204-
205-
describe('getFieldsFromSchema', function () {
206-
const validateMixedType = async (
207-
type: React.ReactNode,
208-
expectedTooltip: RegExp
209-
) => {
210-
render(<>{type}</>);
211-
const mixed = screen.getByText('(mixed)');
212-
expect(mixed).to.be.visible;
213-
expect(screen.queryByText(expectedTooltip)).to.not.exist;
214-
userEvent.hover(mixed);
215-
await waitFor(() => {
216-
expect(screen.getByText(expectedTooltip)).to.be.visible;
217-
});
218-
};
219-
220-
describe('flat schema', function () {
221-
it('return empty array for empty schema', function () {
222-
const result = getFieldsFromSchema({});
223-
expect(result).to.deep.equal([]);
224-
});
225-
226-
it('returns fields for a simple schema', function () {
227-
const result = getFieldsFromSchema({
228-
bsonType: 'object',
229-
properties: {
230-
name: { bsonType: 'string' },
231-
age: { bsonType: 'int' },
232-
},
233-
});
234-
expect(result).to.deep.equal([
235-
{
236-
name: 'name',
237-
type: 'string',
238-
depth: 0,
239-
glyphs: [],
240-
variant: undefined,
241-
},
242-
{ name: 'age', type: 'int', depth: 0, glyphs: [], variant: undefined },
243-
]);
244-
});
245-
246-
it('returns mixed fields with tooltip on hover', async function () {
247-
const result = getFieldsFromSchema({
248-
bsonType: 'object',
249-
properties: {
250-
age: { bsonType: ['int', 'string'] },
251-
},
252-
});
253-
expect(result[0]).to.deep.include({
254-
name: 'age',
255-
depth: 0,
256-
glyphs: [],
257-
variant: undefined,
258-
});
259-
await validateMixedType(result[0].type, /int, string/);
260-
});
261-
262-
it('highlights the correct field', function () {
263-
const result = getFieldsFromSchema(
264-
{
265-
bsonType: 'object',
266-
properties: {
267-
name: { bsonType: 'string' },
268-
age: { bsonType: 'int' },
269-
profession: { bsonType: 'string' },
270-
},
271-
},
272-
['age']
273-
);
274-
expect(result).to.deep.equal([
275-
{
276-
name: 'name',
277-
type: 'string',
278-
depth: 0,
279-
glyphs: [],
280-
variant: undefined,
281-
},
282-
{ name: 'age', type: 'int', depth: 0, glyphs: [], variant: 'preview' },
283-
{
284-
name: 'profession',
285-
type: 'string',
286-
depth: 0,
287-
glyphs: [],
288-
variant: undefined,
289-
},
290-
]);
291-
});
292-
});
293-
294-
describe('nested schema', function () {
295-
it('returns fields for a nested schema', function () {
296-
const result = getFieldsFromSchema({
297-
bsonType: 'object',
298-
properties: {
299-
person: {
300-
bsonType: 'object',
301-
properties: {
302-
name: { bsonType: 'string' },
303-
address: {
304-
bsonType: 'object',
305-
properties: {
306-
street: { bsonType: 'string' },
307-
city: { bsonType: 'string' },
308-
},
309-
},
310-
},
311-
},
312-
},
313-
});
314-
expect(result).to.deep.equal([
315-
{
316-
name: 'person',
317-
type: 'object',
318-
depth: 0,
319-
glyphs: [],
320-
variant: undefined,
321-
},
322-
{
323-
name: 'name',
324-
type: 'string',
325-
depth: 1,
326-
glyphs: [],
327-
variant: undefined,
328-
},
329-
{
330-
name: 'address',
331-
type: 'object',
332-
depth: 1,
333-
glyphs: [],
334-
variant: undefined,
335-
},
336-
{
337-
name: 'street',
338-
type: 'string',
339-
depth: 2,
340-
glyphs: [],
341-
variant: undefined,
342-
},
343-
{
344-
name: 'city',
345-
type: 'string',
346-
depth: 2,
347-
glyphs: [],
348-
variant: undefined,
349-
},
350-
]);
351-
});
352-
353-
it('highlights a field for a nested schema', function () {
354-
const result = getFieldsFromSchema(
355-
{
356-
bsonType: 'object',
357-
properties: {
358-
person: {
359-
bsonType: 'object',
360-
properties: {
361-
name: { bsonType: 'string' },
362-
address: {
363-
bsonType: 'object',
364-
properties: {
365-
street: { bsonType: 'string' },
366-
city: { bsonType: 'string' },
367-
},
368-
},
369-
},
370-
},
371-
},
372-
},
373-
['person', 'address', 'street']
374-
);
375-
expect(result).to.deep.equal([
376-
{
377-
name: 'person',
378-
type: 'object',
379-
depth: 0,
380-
glyphs: [],
381-
variant: undefined,
382-
},
383-
{
384-
name: 'name',
385-
type: 'string',
386-
depth: 1,
387-
glyphs: [],
388-
variant: undefined,
389-
},
390-
{
391-
name: 'address',
392-
type: 'object',
393-
depth: 1,
394-
glyphs: [],
395-
variant: undefined,
396-
},
397-
{
398-
name: 'street',
399-
type: 'string',
400-
depth: 2,
401-
glyphs: [],
402-
variant: 'preview',
403-
},
404-
{
405-
name: 'city',
406-
type: 'string',
407-
depth: 2,
408-
glyphs: [],
409-
variant: undefined,
410-
},
411-
]);
412-
});
413-
414-
it('returns [] for array', function () {
415-
const result = getFieldsFromSchema({
416-
bsonType: 'object',
417-
properties: {
418-
tags: {
419-
bsonType: 'array',
420-
items: { bsonType: 'string' },
421-
},
422-
},
423-
});
424-
expect(result).to.deep.equal([
425-
{ name: 'tags', type: '[]', depth: 0, glyphs: [], variant: undefined },
426-
]);
427-
});
428-
429-
it('returns fields for an array of objects', function () {
430-
const result = getFieldsFromSchema({
431-
bsonType: 'object',
432-
properties: {
433-
todos: {
434-
bsonType: 'array',
435-
items: {
436-
bsonType: 'object',
437-
properties: {
438-
title: { bsonType: 'string' },
439-
completed: { bsonType: 'boolean' },
440-
},
441-
},
442-
},
443-
},
444-
});
445-
expect(result).to.deep.equal([
446-
{ name: 'todos', type: '[]', depth: 0, glyphs: [], variant: undefined },
447-
{
448-
name: 'title',
449-
type: 'string',
450-
depth: 1,
451-
glyphs: [],
452-
variant: undefined,
453-
},
454-
{
455-
name: 'completed',
456-
type: 'boolean',
457-
depth: 1,
458-
glyphs: [],
459-
variant: undefined,
460-
},
461-
]);
462-
});
463-
464-
it('returns fields for a mixed schema with objects', async function () {
465-
const result = getFieldsFromSchema({
466-
bsonType: 'object',
467-
properties: {
468-
name: {
469-
anyOf: [
470-
{ bsonType: 'string' },
471-
{
472-
bsonType: 'object',
473-
properties: {
474-
first: { bsonType: 'string' },
475-
last: { bsonType: 'string' },
476-
},
477-
},
478-
],
479-
},
480-
},
481-
});
482-
expect(result).to.have.lengthOf(3);
483-
expect(result[0]).to.deep.include({
484-
name: 'name',
485-
depth: 0,
486-
glyphs: [],
487-
variant: undefined,
488-
});
489-
await validateMixedType(result[0].type, /string, object/);
490-
expect(result[1]).to.deep.equal({
491-
name: 'first',
492-
type: 'string',
493-
depth: 1,
494-
glyphs: [],
495-
variant: undefined,
496-
});
497-
expect(result[2]).to.deep.equal({
498-
name: 'last',
499-
type: 'string',
500-
depth: 1,
501-
glyphs: [],
502-
variant: undefined,
503-
});
504-
});
505-
506-
it('returns fields for an array of mixed (including objects)', function () {
507-
const result = getFieldsFromSchema({
508-
bsonType: 'object',
509-
properties: {
510-
todos: {
511-
bsonType: 'array',
512-
items: {
513-
anyOf: [
514-
{
515-
bsonType: 'object',
516-
properties: {
517-
title: { bsonType: 'string' },
518-
completed: { bsonType: 'boolean' },
519-
},
520-
},
521-
{ bsonType: 'string' },
522-
],
523-
},
524-
},
525-
},
526-
});
527-
expect(result).to.deep.equal([
528-
{ name: 'todos', type: '[]', depth: 0, glyphs: [], variant: undefined },
529-
{
530-
name: 'title',
531-
type: 'string',
532-
depth: 1,
533-
glyphs: [],
534-
variant: undefined,
535-
},
536-
{
537-
name: 'completed',
538-
type: 'boolean',
539-
depth: 1,
540-
glyphs: [],
541-
variant: undefined,
542-
},
543-
]);
544-
});
545-
});
546-
});

0 commit comments

Comments
 (0)