@@ -10,11 +10,13 @@ import {
1010 EditorView ,
1111 ModalDialog ,
1212 until ,
13+ WebView ,
1314} from "vscode-extension-tester" ;
1415import {
1516 sleep ,
1617 getWebviewByLocator ,
1718 workbenchExecuteCommand ,
19+ dismissNotifications ,
1820} from "./uiTestHelper" ;
1921
2022config . truncateThreshold = 0 ;
@@ -40,11 +42,7 @@ describe("Verify Role generation feature works as expected", function () {
4042 ) ;
4143 await workbenchExecuteCommand ( "View: Close All Editor Groups" ) ;
4244
43- const notifications = await workbench . getNotifications ( ) ;
44- for ( let i = 0 ; i < notifications . length ; i ++ ) {
45- const n = notifications [ i ] ;
46- await n . dismiss ( ) ;
47- }
45+ await dismissNotifications ( workbench ) ;
4846 } ) ;
4947
5048 after ( async function ( ) {
@@ -106,13 +104,15 @@ describe("Verify Role generation feature works as expected", function () {
106104} ) ;
107105
108106describe ( "Verify Role generation reset button works as expected" , function ( ) {
107+ let webView : WebView ;
108+
109109 before ( function ( ) {
110110 if ( ! process . env . TEST_LIGHTSPEED_URL ) {
111111 this . skip ( ) ;
112112 }
113113 } ) ;
114114
115- it ( "Go on the 2nd page and change the collection name" , async function ( ) {
115+ async function setupPage1 ( ) {
116116 await VSBrowser . instance . openResources (
117117 "test/units/lightspeed/utils/samples/" ,
118118 ) ;
@@ -122,28 +122,30 @@ describe("Verify Role generation reset button works as expected", function () {
122122 ) ;
123123 await workbenchExecuteCommand ( "View: Close All Editor Groups" ) ;
124124
125- const notifications = await workbench . getNotifications ( ) ;
126- for ( let i = 0 ; i < notifications . length ; i ++ ) {
127- const n = notifications [ i ] ;
128- await n . dismiss ( ) ;
129- }
125+ await dismissNotifications ( workbench ) ;
130126
131127 await workbenchExecuteCommand ( "Ansible Lightspeed: Role generation" ) ;
132128 await sleep ( 500 ) ;
133- const webView = await getWebviewByLocator (
129+ webView = await getWebviewByLocator (
134130 By . xpath ( "//*[text()='Create a role with Ansible Lightspeed']" ) ,
135131 ) ;
136132 const textArea = await webView . findWebElement (
137133 By . xpath ( "//vscode-text-area" ) ,
138134 ) ;
139135 await textArea . sendKeys ( "Install and configure Nginx" ) ;
136+ }
140137
141- (
142- await webView . findWebElement (
143- By . xpath ( "//vscode-button[@id='submit-button']" ) ,
144- )
145- ) . click ( ) ;
138+ async function gotoPage2 ( ) {
139+ const submitButton = await webView . findWebElement (
140+ By . xpath ( "//vscode-button[@id='submit-button']" ) ,
141+ ) ;
142+ await submitButton . click ( ) ;
146143 await sleep ( 5000 ) ;
144+ }
145+
146+ it ( "Go on the 2nd page and change the collection name" , async function ( ) {
147+ await setupPage1 ( ) ;
148+ await gotoPage2 ( ) ;
147149
148150 await webView . findWebElement (
149151 By . xpath ( "//*[contains(text(), 'Review the suggested')]" ) ,
@@ -158,5 +160,59 @@ describe("Verify Role generation reset button works as expected", function () {
158160 await getWebviewByLocator (
159161 By . xpath ( "//*[text()='What do you want the role to accomplish?']" ) ,
160162 ) ;
163+
164+ await workbenchExecuteCommand ( "View: Close All Editor Groups" ) ;
165+ } ) ;
166+
167+ it ( "Role generation (outline reset, cancel)" , async function ( ) {
168+ await setupPage1 ( ) ;
169+ await gotoPage2 ( ) ;
170+
171+ // Verify outline output and text edit
172+ let outlineList = await webView . findWebElement (
173+ By . xpath ( "//ol[@id='outline-list']" ) ,
174+ ) ;
175+ expect ( outlineList , "An ordered list should exist." ) . to . be . not . undefined ;
176+ let text = await outlineList . getText ( ) ;
177+ expect ( text . includes ( "Install the Nginx packages" ) ) . to . be . true ;
178+
179+ // Test Reset button
180+ await outlineList . sendKeys ( "# COMMENT\n" ) ;
181+ text = await outlineList . getText ( ) ;
182+ expect ( text . includes ( "# COMMENT\n" ) ) ;
183+
184+ let resetButton = await webView . findWebElement (
185+ By . xpath ( "//vscode-button[@id='reset-button']" ) ,
186+ ) ;
187+ expect ( resetButton , "resetButton should not be undefined" ) . not . to . be
188+ . undefined ;
189+ expect ( await resetButton . isEnabled ( ) , "reset button should be enabled now" )
190+ . to . be . true ;
191+
192+ await resetButton . click ( ) ;
193+ await sleep ( 500 ) ;
194+
195+ // Cancel reset of Outline
196+ await webView . switchBack ( ) ;
197+ const resetOutlineDialog = new ModalDialog ( ) ;
198+ await resetOutlineDialog . pushButton ( "Cancel" ) ;
199+ await sleep ( 250 ) ;
200+ // Sadly we need to switch context and so we must reload the WebView elements
201+ webView = await getWebviewByLocator (
202+ By . xpath ( "//*[text()='Create a role with Ansible Lightspeed']" ) ,
203+ ) ;
204+ outlineList = await webView . findWebElement (
205+ By . xpath ( "//ol[@id='outline-list']" ) ,
206+ ) ;
207+ resetButton = await webView . findWebElement (
208+ By . xpath ( "//vscode-button[@id='reset-button']" ) ,
209+ ) ;
210+
211+ text = await outlineList . getText ( ) ;
212+ expect ( text . includes ( "# COMMENT\n" ) ) ;
213+ expect ( await resetButton . isEnabled ( ) , "reset button should be enabled now" )
214+ . to . be . true ;
215+
216+ await workbenchExecuteCommand ( "View: Close All Editor Groups" ) ;
161217 } ) ;
162218} ) ;
0 commit comments