@@ -2126,6 +2126,115 @@ define(function (require, exports, module) {
21262126
21272127 await endEditModePreviewSession ( ) ;
21282128 } , 30000 ) ;
2129+
2130+ it ( "should delete element from source code when delete button is clicked" , async function ( ) {
2131+ await awaitsForDone ( SpecRunnerUtils . openProjectFiles ( [ "simple1.html" ] ) ,
2132+ "SpecRunnerUtils.openProjectFiles simple1.html" ) ;
2133+
2134+ await waitsForLiveDevelopmentToOpenWithEditMode ( 'hover' ) ;
2135+
2136+ // Get original source code content
2137+ const originalContent = DocumentManager . getCurrentDocument ( ) . getText ( ) ;
2138+ expect ( originalContent ) . toContain ( 'id="testId"' ) ; // Ensure test element exists
2139+
2140+ // Click on the test element to show more options box
2141+ await forRemoteExec ( `document.getElementById('testId').click()` ) ;
2142+
2143+ // Wait for more options box to appear
2144+ await waitForMoreOptionsBox ( true ) ;
2145+
2146+ // Click the delete button in the shadow DOM
2147+ await forRemoteExec ( `
2148+ const shadowHosts = Array.from(document.body.children).filter(el => el.shadowRoot);
2149+ let deleteButton = null;
2150+
2151+ shadowHosts.forEach(host => {
2152+ if (host.shadowRoot && host.shadowRoot.innerHTML.includes('phoenix-more-options-box')) {
2153+ deleteButton = host.shadowRoot.querySelector('span[data-action="delete"]');
2154+ }
2155+ });
2156+
2157+ if (deleteButton) {
2158+ deleteButton.click();
2159+ }
2160+ ` ) ;
2161+
2162+ // Wait for the operation to complete
2163+ await awaits ( 1000 ) ;
2164+
2165+ // Verify the element is removed from source code
2166+ const updatedContent = DocumentManager . getCurrentDocument ( ) . getText ( ) ;
2167+ expect ( updatedContent ) . not . toContain ( 'id="testId"' ) ;
2168+ expect ( updatedContent . length ) . toBeLessThan ( originalContent . length ) ;
2169+
2170+ // Verify the element is also removed from DOM
2171+ await forRemoteExec ( `!!document.getElementById('testId')` , ( result ) => {
2172+ return result === false ;
2173+ } ) ;
2174+
2175+ await endEditModePreviewSession ( ) ;
2176+ } , 30000 ) ;
2177+
2178+ it ( "should duplicate element in source code when duplicate button is clicked" , async function ( ) {
2179+ await awaitsForDone ( SpecRunnerUtils . openProjectFiles ( [ "simple1.html" ] ) ,
2180+ "SpecRunnerUtils.openProjectFiles simple1.html" ) ;
2181+
2182+ await waitsForLiveDevelopmentToOpenWithEditMode ( 'hover' ) ;
2183+
2184+ // Get original source code content
2185+ const originalContent = DocumentManager . getCurrentDocument ( ) . getText ( ) ;
2186+ expect ( originalContent ) . toContain ( 'id="testId"' ) ; // Ensure test element exists
2187+
2188+ // Count initial occurrences of the test element
2189+ const originalTestIdCount = ( originalContent . match ( / i d = " t e s t I d " / g) || [ ] ) . length ;
2190+ expect ( originalTestIdCount ) . toBe ( 1 ) ; // Should have exactly one initially
2191+
2192+ // Click on the test element to show more options box
2193+ await forRemoteExec ( `document.getElementById('testId').click()` ) ;
2194+
2195+ // Wait for more options box to appear
2196+ await waitForMoreOptionsBox ( true ) ;
2197+
2198+ // Click the duplicate button in the shadow DOM
2199+ await forRemoteExec ( `
2200+ const shadowHosts = Array.from(document.body.children).filter(el => el.shadowRoot);
2201+ let duplicateButton = null;
2202+
2203+ shadowHosts.forEach(host => {
2204+ if (host.shadowRoot && host.shadowRoot.innerHTML.includes('phoenix-more-options-box')) {
2205+ duplicateButton = host.shadowRoot.querySelector('span[data-action="duplicate"]');
2206+ }
2207+ });
2208+
2209+ if (duplicateButton) {
2210+ duplicateButton.click();
2211+ }
2212+ ` ) ;
2213+
2214+ // Wait for the operation to complete
2215+ await awaits ( 1000 ) ;
2216+
2217+ // Verify the element is duplicated in source code
2218+ const updatedContent = DocumentManager . getCurrentDocument ( ) . getText ( ) ;
2219+ const newTestIdCount = ( updatedContent . match ( / i d = " t e s t I d " / g) || [ ] ) . length ;
2220+ expect ( newTestIdCount ) . toBe ( 2 ) ; // Should now have two instances
2221+ expect ( updatedContent . length ) . toBeGreaterThan ( originalContent . length ) ;
2222+
2223+ // Verify both elements exist in the DOM
2224+ await forRemoteExec ( `document.querySelectorAll('[id="testId"]').length` , ( result ) => {
2225+ return result === 2 ;
2226+ } ) ;
2227+
2228+ // Verify both elements have the same text content
2229+ await forRemoteExec ( `
2230+ const elements = document.querySelectorAll('[id="testId"]');
2231+ elements.length === 2 && elements[0].textContent === elements[1].textContent
2232+ ` , ( result ) => {
2233+ return result === true ;
2234+ } ) ;
2235+
2236+ await endEditModePreviewSession ( ) ;
2237+ } , 30000 ) ;
21292238 } ) ;
21302239 } ) ;
21312240} ) ;
0 commit comments