Repository: cypress-io/cypress
File: packages/app/cypress/e2e/studio/studio-new-tests.cy.ts (TypeScript)

Code before:
    // we should have the commands we executed after we save
    cy.withCtx(async (ctx) => {
      const spec = await ctx.actions.file.readFileInProject('cypress/e2e/spec-w-visit.cy.js')

      expect(spec.trim().replace(/\r/g, '')).to.equal(`
describe('studio functionality', () => {
  beforeEach(() => {
    cy.visit('cypress/e2e/index.html')
  });

  it('visits a basic html page', () => {
    cy.get('h1').should('have.text', 'Hello, Studio!')
  })

  it('new-test', function() {
    cy.get('#increment').click();
  });
})`.trim())
    })
  })

  it('creates a new test from an empty spec', () => {
    loadProjectAndRunSpec({ specName: 'empty.cy.js', specSelector: 'title' })

    cy.waitForSpecToFinish()

    openNewTestFromSpecHeader()

    inputNewTestName()

    // Cypress re-runs after the new test is saved.
    cy.waitForSpecToFinish()

    cy.get('.cm-content').invoke('text', 'cy.visit("cypress/e2e/index.html")')

    cy.findByTestId('studio-save-button').click()

    // verify recording is enabled to ensure the panel is fully ready
    cy.findByTestId('record-button-recording').should('have.text', 'Recording...')

    // we should have the commands we executed after we save
    cy.withCtx(async (ctx) => {
      const spec = await ctx.actions.file.readFileInProject('cypress/e2e/empty.cy.js')

      expect(spec.trim().replace(/\r/g, '')).to.equal(`
it('new-test', function() {
    cy.visit("cypress/e2e/index.html")
});`.trim())
    })
  })


Review comment (suggestion):
I think we do want to click the `Create test with Cypress Studio` link since we want to test creating a new test from that view.

Code after:
    // we should have the commands we executed after we save
    cy.withCtx(async (ctx) => {
      const spec = await ctx.actions.file.readFileInProject('cypress/e2e/spec-w-visit.cy.js')

      expect(spec.trim().replace(/\r/g, '')).to.equal(`
describe('studio functionality', () => {
  beforeEach(() => {
    cy.visit('cypress/e2e/index.html')
  });

  it('visits a basic html page', () => {
    cy.get('h1').should('have.text', 'Hello, Studio!')
  })

  it('new-test', function() {
    cy.get('#increment').click();
  });
})`.trim())
    })
  })

  it('creates a new test from an empty spec', () => {
    loadProjectAndRunSpec({ specName: 'empty.cy.js', specSelector: 'title' })

    cy.contains('Create test with Cypress Studio').click()

    inputNewTestName()

    // Cypress re-runs after the new test is saved.
    cy.waitForSpecToFinish()

    cy.get('.cm-content').invoke('text', 'cy.visit("cypress/e2e/index.html")')

    cy.findByTestId('studio-save-button').click()

    // verify recording is enabled to ensure the panel is fully ready
    cy.findByTestId('record-button-recording').should('have.text', 'Recording...')

    // we should have the commands we executed after we save
    cy.withCtx(async (ctx) => {
      const spec = await ctx.actions.file.readFileInProject('cypress/e2e/empty.cy.js')

      expect(spec.trim().replace(/\r/g, '')).to.equal(`
it('new-test', function() {
    cy.visit("cypress/e2e/index.html")
});`.trim())
    })
  })

  it('opens the name test screen from the welcome screen and creates a new test from an empty spec', () => {
    loadProjectAndRunSpec({ specName: 'empty.cy.js', specSelector: 'title' })