@@ -2015,6 +2015,31 @@ describe('Home page', () => {
20152015 . scrollIntoView ( )
20162016 . should ( 'have.value' , '' ) ;
20172017 } ) ;
2018+
2019+ /*
2020+ * Verifies that when a new item is created after a focused item that has expanded children, the new item's
2021+ * linkId is properly populated. This ensures that the fix correctly assigns a linkId even when the previous
2022+ * node is expanded and has children.
2023+ */
2024+ it ( 'should populate linkId when creating a new item after a focused item with expanded children' , ( ) => {
2025+ // Click on '2 Family member health history'
2026+ cy . getTreeNode ( 'Family member health history' ) . click ( ) ;
2027+
2028+ cy . toggleTreeNodeExpansion ( 'Family member health history' ) ;
2029+
2030+ // Click the 'Add new item'
2031+ cy . contains ( 'button' , 'Add new item' ) . click ( ) ;
2032+ // Click on the new added item
2033+ cy . getTreeNode ( 'New item 1' ) . click ( ) ;
2034+
2035+ // Go to the link id section
2036+ cy . editableLinkId ( )
2037+ . scrollIntoView ( )
2038+ . should ( 'be.visible' )
2039+ . invoke ( 'val' )
2040+ . should ( 'not.be.empty' ) ;
2041+ } ) ;
2042+
20182043 } ) ;
20192044
20202045 describe ( 'Test descendant items and display/group type changes' , ( ) => {
@@ -2103,28 +2128,23 @@ describe('Home page', () => {
21032128 cy . get ( 'lfb-node-dialog' ) . find ( '#moveTarget1' ) . click ( ) . clear ( ) . type ( 'Display Data Type' ) ;
21042129 cy . get ( 'lfb-node-dialog' ) . find ( 'button.dropdown-item' ) . should ( 'exist' ) . should ( 'have.length' , 1 ) . click ( ) ;
21052130
2106- cy . get ( 'lfb-node-dialog' ) . find ( 'ul' ) . within ( ( ) => {
2107- cy . get ( 'li' ) . should ( 'have.length' , 2 ) ;
2108- cy . get ( 'li' ) . eq ( 0 ) . should ( 'contain.text' , 'After the target item.' ) ;
2109- cy . get ( 'li' ) . eq ( 1 ) . should ( 'contain.text' , 'Before the target item.' ) ;
2110- } ) ;
2111-
2112- // Clear the target again. 3 drop locations should be presented.
2113- cy . get ( 'lfb-node-dialog' ) . find ( '#moveTarget1' ) . click ( ) . clear ( ) ;
2114- cy . get ( 'lfb-node-dialog form' ) . click ( ) ;
21152131 cy . get ( 'lfb-node-dialog' ) . find ( 'ul' ) . within ( ( ) => {
21162132 cy . get ( 'li' ) . should ( 'have.length' , 3 ) ;
2117- cy . get ( 'li' ) . eq ( 0 ) . should ( 'contain.text' , 'After the target item.' ) ;
2118- cy . get ( 'li' ) . eq ( 1 ) . should ( 'contain.text' , 'Before the target item.' ) ;
2119- cy . get ( 'li' ) . eq ( 2 ) . should ( 'contain.text' , 'As a child of target item.' ) ;
2120- // Select the 'As a child of target item.' option.
21212133 cy . get ( 'li' ) . eq ( 2 ) . should ( 'contain.text' , 'As a child of target item.' )
21222134 . find ( 'input[type="radio"' ) . check ( ) ;
21232135
21242136 } ) ;
2125- // The 'Display Data Type' item should be excluded from the target item list.
2126- cy . get ( 'lfb-node-dialog' ) . find ( '#moveTarget1' ) . click ( ) . clear ( ) . type ( 'Display Data Type' ) ;
2127- cy . get ( 'lfb-node-dialog' ) . find ( 'button.dropdown-item' ) . should ( 'not.exist' ) ;
2137+
2138+ cy . get ( 'lfb-node-dialog' ) . contains ( 'button' , 'Move' ) . as ( 'moveBtn' ) . click ( ) ;
2139+
2140+ // The modal is displayed.
2141+ cy . get ( 'lfb-confirm-dlg > div.modal-header' ) . should ( 'contain.text' , 'Move Not Allowed' ) ;
2142+ cy . get ( 'lfb-confirm-dlg > div.modal-body' )
2143+ . invoke ( 'text' )
2144+ . should ( 'match' , / C a n n o t d r o p i n t o i t e m ' D i s p l a y D a t a T y p e ' \( l i n k I d : [ ^ ) ] + \) o f t y p e ' d i s p l a y ' b e c a u s e i t c a n n o t c o n t a i n c h i l d r e n \. / ) ;
2145+
2146+ // Close the modal by clicking the close button
2147+ cy . get ( 'lfb-confirm-dlg' ) . contains ( 'button' , 'Close' ) . click ( ) ;
21282148 } ) ;
21292149
21302150 it ( 'should not be able to insert a new child item to an item of type "display"' , ( ) => {
@@ -2149,6 +2169,43 @@ describe('Home page', () => {
21492169 // Due to the data type 'display', the option 'Insert a new child item.' should be hidden.
21502170 cy . get ( 'div.dropdown-menu.show' ) . should ( 'not.contain' , 'Insert a new child item' ) ;
21512171 } ) ;
2172+
2173+ it ( 'should show "display" data type if the last child is removed from the item' , ( ) => {
2174+ cy . toggleTreeNodeExpansion ( 'Family member health history' ) ;
2175+ cy . getTreeNode ( 'Race' ) . click ( ) ;
2176+
2177+ // Add a new item under the 'Race' item.
2178+ cy . contains ( 'Add new item' ) . scrollIntoView ( ) . click ( ) ;
2179+ cy . getItemTextField ( ) . clear ( ) . type ( 'Item with child' ) ;
2180+ cy . getItemTypeField ( ) . as ( 'dataTypes' ) ;
2181+ // Confirm that the data type 'display' is included in the list.
2182+ cy . get ( '@dataTypes' ) . find ( 'option' ) . should ( 'contain.text' , 'display' ) ;
2183+
2184+ // Create a chid item.
2185+ cy . getTreeNode ( 'Item with child' ) . as ( 'contextNode' ) ;
2186+ cy . get ( '@contextNode' ) . find ( 'button.dropdown-toggle' ) . click ( ) ;
2187+ cy . get ( 'div.dropdown-menu.show' ) . contains ( 'button.dropdown-item' , 'Insert a new child item' ) . click ( ) ;
2188+ cy . getItemTextField ( ) . should ( 'have.value' , 'New item 2' ) ;
2189+
2190+ // Click back to the parent item 'Item with child'.
2191+ cy . getTreeNode ( 'Item with child' ) . click ( ) ;
2192+ // The data type 'display' should no longer be on the list.
2193+ cy . getItemTypeField ( ) . as ( 'dataTypes' ) ;
2194+ cy . get ( '@dataTypes' ) . find ( 'option' ) . should ( 'not.contain.text' , 'display' ) ;
2195+
2196+ // Delete the child item
2197+ cy . getTreeNode ( 'New item 2' ) . as ( 'childItem' ) . click ( ) ;
2198+ cy . get ( '@childItem' ) . find ( 'button.dropdown-toggle' ) . click ( ) ;
2199+ cy . get ( 'div.dropdown-menu.show' ) . contains ( 'button.dropdown-item' , 'Remove this item' ) . click ( ) ;
2200+ cy . contains ( 'button' , 'Yes' ) . click ( ) ;
2201+
2202+ // The parent item 'Item with child' should now be the focused node.
2203+ cy . get ( '#text' ) . should ( 'contain.value' , 'Item with child' ) ;
2204+ // As the item 'Item with child' no longer has any children, the data type 'display' should once again be available.
2205+ cy . getItemTypeField ( ) . as ( 'dataTypes' ) ;
2206+ cy . get ( '@dataTypes' ) . find ( 'option' ) . should ( 'contain.text' , 'display' ) ;
2207+ } ) ;
2208+
21522209 } ) ;
21532210} ) ;
21542211
0 commit comments