1- import { launchStudio , loadProjectAndRunSpec , incrementCounter , inputNewTestName } from './helper'
1+ import { launchStudio , loadProjectAndRunSpec , incrementCounter , inputNewTestName , openNewTestFromSpecHeader } from './helper'
22
33describe ( 'Cypress Studio - New Test Creation' , ( ) => {
44 it ( 'does not enter single test mode when creating a new test' , ( ) => {
@@ -15,7 +15,7 @@ describe('Cypress Studio - New Test Creation', () => {
1515 it ( 'creates a new test from spec header' , ( ) => {
1616 launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTestFromSpecHeader : true } )
1717
18- inputNewTestName ( { creatingNewTestFromWelcomeScreen : false } )
18+ inputNewTestName ( )
1919
2020 cy . contains ( 'new-test' ) . click ( )
2121
@@ -128,7 +128,7 @@ describe('studio functionality', () => {
128128 it ( 'creates a new test for a specific suite with the url already defined' , ( ) => {
129129 launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTestFromSuite : true } )
130130
131- inputNewTestName ( { creatingNewTestFromWelcomeScreen : false } )
131+ inputNewTestName ( )
132132
133133 // make sure that the visit has run and we're recording studio commands
134134 cy . get ( '[data-cy="record-button-recording"]' ) . should ( 'be.visible' )
@@ -160,10 +160,41 @@ describe('studio functionality', () => {
160160 } )
161161 } )
162162
163- // TODO: unskip with https://github.com/cypress-io/cypress/pull/33236
164- it . skip ( 'creates a new test from an empty spec' , ( ) => {
163+ it ( 'creates a new test from an empty spec' , ( ) => {
164+ loadProjectAndRunSpec ( { specName : 'empty.cy.js' , specSelector : 'title' } )
165+
166+ cy . contains ( 'Create test with Cypress Studio' ) . click ( )
167+
168+ inputNewTestName ( )
169+
170+ // Cypress re-runs after the new test is saved.
171+ cy . waitForSpecToFinish ( )
172+
173+ cy . get ( '.cm-content' ) . invoke ( 'text' , 'cy.visit("cypress/e2e/index.html")' )
174+
175+ cy . findByTestId ( 'studio-save-button' ) . click ( )
176+
177+ // verify recording is enabled to ensure the panel is fully ready
178+ cy . findByTestId ( 'record-button-recording' ) . should ( 'have.text' , 'Recording...' )
179+
180+ // we should have the commands we executed after we save
181+ cy . withCtx ( async ( ctx ) => {
182+ const spec = await ctx . actions . file . readFileInProject ( 'cypress/e2e/empty.cy.js' )
183+
184+ expect ( spec . trim ( ) . replace ( / \r / g, '' ) ) . to . equal ( `
185+ it('new-test', function() {
186+ cy.visit("cypress/e2e/index.html")
187+ });` . trim ( ) )
188+ } )
189+ } )
190+
191+ it ( 'opens the name test screen from the welcome screen and creates a new test from an empty spec' , ( ) => {
165192 loadProjectAndRunSpec ( { specName : 'empty.cy.js' , specSelector : 'title' } )
166193
194+ cy . findByTestId ( 'studio-button' ) . click ( )
195+
196+ cy . get ( '[data-cy="studio-panel"]' ) . should ( 'be.visible' )
197+
167198 cy . contains ( 'Create test with Cypress Studio' ) . click ( )
168199
169200 inputNewTestName ( )
@@ -207,17 +238,15 @@ it('new-test', function() {
207238 cy . findByTestId ( 'studio-single-test-title' ) . should ( 'have.text' , 'should be the only test to run normally' )
208239 } )
209240
210- // TODO: unskip with https://github.com/cypress-io/cypress/pull/33236
211- it . skip ( 'creates and runs new tests in studio mode when there is a .only test in the spec file' , ( ) => {
241+ it ( 'creates and runs new tests in studio mode when there is a .only test in the spec file' , ( ) => {
212242 loadProjectAndRunSpec ( { specName : 'spec-with-only.cy.js' } )
213243
214244 cy . get ( '.test' ) . should ( 'have.length' , 1 )
215245 cy . get ( '.test' ) . contains ( 'should be the only test to run normally' ) . should ( 'be.visible' )
246+ // create a new test from the spec header
247+ openNewTestFromSpecHeader ( )
216248
217- // launch studio and create a new test
218- cy . findByTestId ( 'studio-button' ) . click ( )
219249 cy . findByTestId ( 'studio-panel' ) . should ( 'be.visible' ) . within ( ( ) => {
220- cy . contains ( 'button' , 'New test' ) . click ( )
221250 cy . get ( '[data-cy="test-name-input"]' ) . type ( 'new test{enter}' )
222251 } )
223252
@@ -226,6 +255,49 @@ it('new-test', function() {
226255 cy . get ( '[data-cy="studio-single-test-title"]' ) . should ( 'have.text' , 'new test' )
227256 } )
228257
258+ it ( 'continues to display the welcome screen after reloading' , ( ) => {
259+ loadProjectAndRunSpec ( { specName : 'spec-w-visit.cy.js' } )
260+
261+ // open welcome screen
262+ cy . findByTestId ( 'studio-button' ) . click ( )
263+
264+ cy . findByTestId ( 'new-test-features' ) . should ( 'be.visible' )
265+ cy . location ( ) . its ( 'hash' ) . should ( 'contain' , 'suiteId=r1' ) . and ( 'contain' , 'studio=' ) . and ( 'contain' , 'entrySource=welcome' )
266+
267+ cy . reload ( )
268+
269+ cy . findByTestId ( 'new-test-features' ) . should ( 'be.visible' )
270+ cy . location ( ) . its ( 'hash' ) . should ( 'contain' , 'suiteId=r1' ) . and ( 'contain' , 'studio=' ) . and ( 'contain' , 'entrySource=welcome' )
271+ } )
272+
273+ it ( 'continues to display the name test screen after reloading the page for a new test from root suite' , ( ) => {
274+ launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTestFromSpecHeader : true } )
275+
276+ cy . location ( ) . its ( 'hash' ) . should ( 'contain' , 'suiteId=r1' ) . and ( 'contain' , 'studio=' ) . and ( 'contain' , 'entrySource=new-test-root' )
277+
278+ cy . get ( '[data-cy="name-test-container"]' ) . should ( 'be.visible' )
279+
280+ cy . reload ( )
281+
282+ cy . location ( ) . its ( 'hash' ) . should ( 'contain' , 'suiteId=r1' ) . and ( 'contain' , 'studio=' ) . and ( 'contain' , 'entrySource=new-test-root' )
283+
284+ cy . get ( '[data-cy="name-test-container"]' ) . should ( 'be.visible' )
285+ } )
286+
287+ it ( 'continues to display the name test screen after reloading the page for a new test from suite' , ( ) => {
288+ launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTestFromSuite : true } )
289+
290+ cy . location ( ) . its ( 'hash' ) . should ( 'contain' , 'suiteId=r2' ) . and ( 'contain' , 'studio=' ) . and ( 'contain' , 'entrySource=new-test-suite' )
291+
292+ cy . get ( '[data-cy="name-test-container"]' ) . should ( 'be.visible' )
293+
294+ cy . reload ( )
295+
296+ cy . location ( ) . its ( 'hash' ) . should ( 'contain' , 'suiteId=r2' ) . and ( 'contain' , 'studio=' ) . and ( 'contain' , 'entrySource=new-test-suite' )
297+
298+ cy . get ( '[data-cy="name-test-container"]' ) . should ( 'be.visible' )
299+ } )
300+
229301 describe ( 'prompt for a new url' , ( ) => {
230302 const urlPrompt = '// Visit a page by entering a url in the address bar or typing a cy.visit command here'
231303 const autUrl = 'http://localhost:4455/cypress/e2e/index.html'
0 commit comments