11import React from 'react' ;
22import { Classes , ContextMenu , Menu , Popover } from '@blueprintjs/core' ;
33import { 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' ;
512import userEvent from '@testing-library/user-event' ;
613import Sidebar from '../Sidebar' ;
714import { 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 ( / t e x t b o x / )
89+ const editableInput = within ( editableItems [ 0 ] ) . getByRole ( / t e x t b o x / ) ;
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 ( / t e x t b o x / )
94+ const _editableInput = within ( sidebarItems [ 4 ] ) . queryByRole ( / t e x t b o x / ) ;
8895 expect ( _editableInput ) . toBeNull ( ) ;
8996 } ) ;
9097
@@ -107,7 +114,7 @@ describe('Sidebar tests', () => {
107114 await act ( async ( ) => {
108115 userEvent . type (
109116 within ( getByRole ( / e d i t i t e m / ) ) . getByRole ( / t e x t b o x / ) ,
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 ( / e d i t i t e m / ) ) . getByRole ( / t e x t b o x / ) ,
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 ( / m e n u i t e m / ) ) . toHaveLength ( 8 ) ;
157164 expect ( childNode ) . toHaveTextContent ( / U s e r M o d e l / ) ;
158165 await act ( async ( ) => {
@@ -182,15 +189,15 @@ describe('Sidebar tests', () => {
182189 await act ( async ( ) => {
183190 userEvent . type (
184191 within ( screen . getByRole ( / e d i t i t e m / ) ) . getByRole ( / t e x t b o x / ) ,
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 ( / m e n u i t e m / ) ) . toHaveLength ( 8 ) ;
191198 expect ( childNode ) . toHaveTextContent ( / U s e r M o d e l / ) ;
192199 await act ( async ( ) => {
193- fireEvent . contextMenu ( childNode ) ;
200+ fireEvent . contextMenu ( childNode ) ;
194201 } ) ;
195202 const menuItems = getContextMenuItems ( ) ;
196203 expect ( menuItems [ 0 ] ) . toHaveTextContent ( / R e n a m e / ) ;
@@ -215,7 +222,7 @@ describe('Sidebar tests', () => {
215222 await act ( async ( ) => {
216223 userEvent . type (
217224 within ( screen . getByRole ( / e d i t i t e m / ) ) . getByRole ( / t e x t b o x / ) ,
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 ( / R e n a m e / ) ;
231238 expect ( menuItems [ 1 ] ) . toHaveTextContent ( / D e l e t e p a t h / ) ;
232239 expect ( menuItems [ 2 ] ) . toHaveTextContent ( / D e l e t e O p e r a t i o n / ) ;
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 ( / e d i t i t e m / ) ) . getByRole ( / t e x t b o x / ) ,
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 ( / m e n u i t e m / ) ) . 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 ( / m e n u i t e m / ) ) . 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 ( / e d i t i t e m / ) ) . getByRole ( / t e x t b o x / ) ,
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 ( / m e n u i t e m / ) ) . toHaveLength ( 8 ) ;
278330 await act ( async ( ) => {
@@ -307,7 +359,7 @@ describe('Sidebar tests', () => {
307359 await act ( async ( ) => {
308360 userEvent . type (
309361 within ( screen . getByRole ( / e d i t i t e m / ) ) . getByRole ( / t e x t b o x / ) ,
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 ( / e d i t i t e m / ) ) . getByRole ( / t e x t b o x / ) ,
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 ( / e d i t i t e m / ) ) . getByRole ( / t e x t b o x / ) ,
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 ( / m e n u i t e m / ) ) . toHaveLength ( 8 ) ;
392444 await act ( async ( ) => {
393445 await fireEvent . contextMenu ( childNode ) ;
0 commit comments