Skip to content

Commit 48cdeb9

Browse files
committed
Fix issue #4
1 parent 00b9354 commit 48cdeb9

File tree

3 files changed

+99
-32
lines changed

3 files changed

+99
-32
lines changed

src/components/Editor/oasSchema/row.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const displayArrayItemEntity = (schema) =>
1616
schema.type === 'array' &&
1717
Object.prototype.hasOwnProperty.call(schema.items, 'type')
1818
? `${schema.type} [${schema.items.type}]`
19+
: isRefSchema(schema.items)
20+
? `${schema.type} [${displayRefItemEntity(schema.items)}]`
1921
: null;
2022

2123
const displayRefItemEntity = (schema) =>

src/components/Pickers/schema/selectors.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,32 @@ const SubSchema = ({schema, onClick}) => {
4646
<div
4747
className={`flex items-center justify-center mr-2 px-2 py-1 rounded cursor-pointer
4848
${
49-
schema.type === type
50-
? 'bg-green-600 text-white'
49+
schema.type === type ||
50+
(isRefSchema(schema) && type === '$ref')
51+
? 'bg-green-600 text-white schema-literal-selected'
5152
: 'hover:bg-gray-300 dark:hover:bg-gray-600'
5253
}`}
5354
key={index}
54-
onClick={() => onClick(type, ['items', 'type'])}
55+
onClick={() =>
56+
onClick(type === '$ref' ? '' : type, [
57+
'items',
58+
type === '$ref' ? '$ref' : 'type',
59+
])
60+
}
5561
selected={schema.type === type}>
5662
{type}
5763
</div>
5864
);
5965
})}
6066
</div>
6167
</div>
68+
{isRefSchema(schema) && (
69+
<RefSchema
70+
schemaRef={schema['$ref']}
71+
onClick={(e) => onClick(e, ['items', '$ref'])}
72+
onBlur={(e) => onClick(e, ['items', '$ref'])}
73+
/>
74+
)}
6275
</div>
6376
);
6477
};

src/components/Sidebar/__tests__/Sidebar.test.js

Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import React from 'react';
22
import {Classes, ContextMenu, Menu, Popover} from '@blueprintjs/core';
33
import {Classes as PopoverClasses} from '@blueprintjs/popover2';
4-
import {act, render, screen, within, fireEvent, Stores} from '../../../../test-utils';
4+
import {
5+
act,
6+
render,
7+
screen,
8+
within,
9+
fireEvent,
10+
Stores,
11+
} from '../../../../test-utils';
512
import userEvent from '@testing-library/user-event';
613
import Sidebar from '../Sidebar';
714
import {wait} from '@testing-library/user-event/dist/utils';
@@ -36,11 +43,11 @@ describe('Sidebar tests', () => {
3643

3744
// Assert icons
3845
expect(getIconElement(items[0])).toHaveAttribute('icon', 'star');
39-
expect(getIconElement(items[1])).toHaveAttribute('icon', 'folder-open');
40-
expect(getIconElement(items[2])).toHaveAttribute('icon', 'folder-open');
41-
expect(getIconElement(items[3])).toHaveAttribute('icon', 'folder-open');
42-
expect(getIconElement(items[4])).toHaveAttribute('icon', 'folder-open');
43-
expect(getIconElement(items[5])).toHaveAttribute('icon', 'folder-open');
46+
expect(getIconElement(items[1])).toHaveAttribute('icon', 'folder-open');
47+
expect(getIconElement(items[2])).toHaveAttribute('icon', 'folder-open');
48+
expect(getIconElement(items[3])).toHaveAttribute('icon', 'folder-open');
49+
expect(getIconElement(items[4])).toHaveAttribute('icon', 'folder-open');
50+
expect(getIconElement(items[5])).toHaveAttribute('icon', 'folder-open');
4451
expect(getIconElement(items[6])).toHaveAttribute('icon', 'folder-open');
4552

4653
// Asserting that sidebar have 7 list items automatically means it doesn't
@@ -79,12 +86,12 @@ describe('Sidebar tests', () => {
7986
expect(editableItems).toHaveLength(1);
8087

8188
// The new item is just next to the current "right-clicked" item
82-
const editableInput = within(editableItems[0]).getByRole(/textbox/)
89+
const editableInput = within(editableItems[0]).getByRole(/textbox/);
8390
expect(editableInput).toBeInTheDocument();
8491
expect(editableInput).toHaveValue('');
8592

8693
// No editable text is present inside other sidebar items
87-
const _editableInput = within(sidebarItems[4]).queryByRole(/textbox/)
94+
const _editableInput = within(sidebarItems[4]).queryByRole(/textbox/);
8895
expect(_editableInput).toBeNull();
8996
});
9097

@@ -107,7 +114,7 @@ describe('Sidebar tests', () => {
107114
await act(async () => {
108115
userEvent.type(
109116
within(getByRole(/edititem/)).getByRole(/textbox/),
110-
`${newItemName}{Enter}`
117+
`${newItemName}{Enter}`,
111118
);
112119
});
113120
// Assert that item is in the menu
@@ -148,11 +155,11 @@ describe('Sidebar tests', () => {
148155
await act(async () => {
149156
userEvent.type(
150157
within(screen.getByRole(/edititem/)).getByRole(/textbox/),
151-
'UserModel{Enter}'
158+
'UserModel{Enter}',
152159
);
153160
});
154161

155-
const childNode = screen.getByLabelText(NodeTypes.Model)
162+
const childNode = screen.getByLabelText(NodeTypes.Model);
156163
expect(screen.getAllByRole(/menuitem/)).toHaveLength(8);
157164
expect(childNode).toHaveTextContent(/UserModel/);
158165
await act(async () => {
@@ -182,15 +189,15 @@ describe('Sidebar tests', () => {
182189
await act(async () => {
183190
userEvent.type(
184191
within(screen.getByRole(/edititem/)).getByRole(/textbox/),
185-
'UserModel{Enter}'
192+
'UserModel{Enter}',
186193
);
187194
});
188195

189-
const childNode = screen.getByLabelText(NodeTypes.Model)
196+
const childNode = screen.getByLabelText(NodeTypes.Model);
190197
expect(screen.getAllByRole(/menuitem/)).toHaveLength(8);
191198
expect(childNode).toHaveTextContent(/UserModel/);
192199
await act(async () => {
193-
fireEvent.contextMenu(childNode);
200+
fireEvent.contextMenu(childNode);
194201
});
195202
const menuItems = getContextMenuItems();
196203
expect(menuItems[0]).toHaveTextContent(/Rename/);
@@ -215,7 +222,7 @@ describe('Sidebar tests', () => {
215222
await act(async () => {
216223
userEvent.type(
217224
within(screen.getByRole(/edititem/)).getByRole(/textbox/),
218-
'/users{Enter}'
225+
'/users{Enter}',
219226
);
220227
});
221228

@@ -224,21 +231,42 @@ describe('Sidebar tests', () => {
224231
expect(childNode).toHaveTextContent('sresu/get');
225232
expect(within(childNode).getByRole('button')).toHaveTextContent('get');
226233
await act(async () => {
227-
fireEvent.contextMenu(childNode);
234+
fireEvent.contextMenu(childNode);
228235
});
229236
const menuItems = getContextMenuItems();
230237
expect(menuItems[0]).toHaveTextContent(/Rename/);
231238
expect(menuItems[1]).toHaveTextContent(/Delete path/);
232239
expect(menuItems[2]).toHaveTextContent(/Delete Operation/);
233240
});
234241

235-
it.skip('Can rename node', async () => {
242+
it('Can rename node', async () => {
236243
render(<Sidebar />);
237244
const assertRename = async (nodeType) => {
238245
const childName = `${generateRandomName()}${nodeType}`;
239246
const renamedChildName = `${generateRandomName()}${nodeType}`;
240-
const childNode = await addChildNode(nodeType, childName);
241-
const newSidebarItems = await screen.queryAllByText(childName);
247+
248+
// Right click models
249+
await act(async () => {
250+
fireEvent.contextMenu(screen.getByLabelText(nodeType));
251+
});
252+
// Click first item in context menu
253+
const contextMenus = getContextMenuItems();
254+
const newItemMenuName = getAddButtonLabel(nodeType);
255+
await act(async () => {
256+
fireEvent.click(within(contextMenus[0]).getByText(newItemMenuName));
257+
});
258+
259+
// Enter new Model name
260+
await act(async () => {
261+
userEvent.type(
262+
within(screen.getByRole(/edititem/)).getByRole(/textbox/),
263+
`${childName}{Enter}`,
264+
);
265+
});
266+
267+
const childNodeType = getChildNodeType(nodeType);
268+
const childNode = screen.getByLabelText(childNodeType);
269+
const newSidebarItems = screen.queryAllByText(childName);
242270
expect(newSidebarItems).toHaveLength(1);
243271
await act(async () => {
244272
await fireEvent.contextMenu(childNode);
@@ -247,9 +275,9 @@ describe('Sidebar tests', () => {
247275
await act(async () => {
248276
await userEvent.click(menuItems[0].querySelector('a'));
249277
});
250-
const editItem = getNodeFromSidebar(
251-
getChildNodeType(nodeType),
252-
).querySelector('input');
278+
const editItem = screen
279+
.getByLabelText(childNodeType)
280+
.querySelector('input');
253281
expect(editItem).toHaveValue(childName);
254282
await act(async () => {
255283
await userEvent.type(editItem, `${renamedChildName}{Enter}`);
@@ -266,13 +294,37 @@ describe('Sidebar tests', () => {
266294
expect(screen.getAllByRole(/menuitem/)).toHaveLength(10);
267295
});
268296

269-
it.skip('Can delete node', async () => {
297+
it('Can delete node', async () => {
270298
render(<Sidebar />);
271299
const assertDelete = async (nodeType) => {
272300
expect(screen.getAllByRole(/menuitem/)).toHaveLength(7);
273301
const childName = `${generateRandomName()}${nodeType}`;
274-
const childNode = await addChildNode(nodeType, childName);
275-
const newSidebarItems = await screen.queryAllByText(childName);
302+
// Right click models
303+
await act(async () => {
304+
fireEvent.contextMenu(screen.getByLabelText(nodeType));
305+
});
306+
// Click first item in context menu
307+
const contextMenus = getContextMenuItems();
308+
const newItemMenuName = getAddButtonLabel(nodeType);
309+
await act(async () => {
310+
fireEvent.click(within(contextMenus[0]).getByText(newItemMenuName));
311+
});
312+
313+
// Enter new Model name
314+
await act(async () => {
315+
userEvent.type(
316+
within(screen.getByRole(/edititem/)).getByRole(/textbox/),
317+
`${childName}{Enter}`,
318+
);
319+
});
320+
321+
const childNodeType = getChildNodeType(nodeType);
322+
323+
const childNode = screen.getByLabelText(childNodeType);
324+
325+
//const childNode = await addChildNode(nodeType, childName);
326+
327+
const newSidebarItems = screen.queryAllByText(childName);
276328
expect(newSidebarItems).toHaveLength(1);
277329
expect(screen.getAllByRole(/menuitem/)).toHaveLength(8);
278330
await act(async () => {
@@ -307,7 +359,7 @@ describe('Sidebar tests', () => {
307359
await act(async () => {
308360
userEvent.type(
309361
within(screen.getByRole(/edititem/)).getByRole(/textbox/),
310-
'/users{Enter}'
362+
'/users{Enter}',
311363
);
312364
});
313365

@@ -349,7 +401,7 @@ describe('Sidebar tests', () => {
349401
await act(async () => {
350402
userEvent.type(
351403
within(screen.getByRole(/edititem/)).getByRole(/textbox/),
352-
'/users{Enter}'
404+
'/users{Enter}',
353405
);
354406
});
355407

@@ -383,11 +435,11 @@ describe('Sidebar tests', () => {
383435
await act(async () => {
384436
userEvent.type(
385437
within(screen.getByRole(/edititem/)).getByRole(/textbox/),
386-
'/users{Enter}'
438+
'/users{Enter}',
387439
);
388440
});
389441

390-
const childNode = screen.getByLabelText(NodeTypes.Path)
442+
const childNode = screen.getByLabelText(NodeTypes.Path);
391443
expect(screen.getAllByRole(/menuitem/)).toHaveLength(8);
392444
await act(async () => {
393445
await fireEvent.contextMenu(childNode);

0 commit comments

Comments
 (0)