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

Code before:
  cy.specsPageIsVisible()
  cy.get(`[${specSelector}="${specName}"]`).click()

  cy.waitForSpecToFinish()
}

export function launchStudio ({ specName = 'spec.cy.js', createNewTest = false, cliArgs = [''] } = {}) {
  loadProjectAndRunSpec({ specName, cliArgs })

  const testTitle = 'visits a basic html page'

  if (createNewTest) {
    cy.contains('studio functionality').as('item')
  } else {
    cy.contains(testTitle).as('item')
  }

  cy.get('@item')
  .closest('.runnable-wrapper').as('runnable-wrapper')

  if (createNewTest) {
    cy.get('@runnable-wrapper').realHover().findByTestId('create-new-test-button').click()
    cy.findByTestId('studio-panel').should('be.visible')
    cy.findByTestId('new-test-button').should('be.visible')
  } else {
    cy.get('@runnable-wrapper')
    .findByTestId('launch-studio')
    .click()

    // Studio re-executes spec before waiting for commands - wait for the spec to finish executing.
    cy.waitForSpecToFinish()

    cy.get('[data-cy="studio-single-test-title"]').contains(testTitle)

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

export function assertClosingPanelWithoutChanges () {
  // Cypress re-runs after you cancel Studio.
  // Original spec should pass
  cy.waitForSpecToFinish({ passCount: 1 })

  cy.get('.command').should('have.length', 1)

  // Assert the spec was executed without any new commands.
  cy.get('.command-name-visit').within(() => {
    cy.contains('visit')
    cy.contains('cypress/e2e/index.html')
  })

Review comment (suggestion):
```suggestion
    if (createNewTestFromSpecHeader) {
      cy.findByTestId('create-new-test-from-spec-header').click()
    } else if (createNewTestFromSuite) {
      cy.get('@runnable-wrapper').realHover().findByTestId('create-new-test-from-suite').click()
    }
```

Code after:
  cy.specsPageIsVisible()
  cy.get(`[${specSelector}="${specName}"]`).click()

  cy.waitForSpecToFinish()
}

export function launchStudio ({ specName = 'spec.cy.js', createNewTestFromSuite = false, createNewTestFromSpecHeader = false, cliArgs = [''] } = {}) {
  loadProjectAndRunSpec({ specName, cliArgs })

  const testTitle = 'visits a basic html page'

  if (createNewTestFromSuite || createNewTestFromSpecHeader) {
    cy.contains('studio functionality').as('item')
  } else {
    cy.contains(testTitle).as('item')
  }

  cy.get('@item')
  .closest('.runnable-wrapper').as('runnable-wrapper')

  if (createNewTestFromSuite || createNewTestFromSpecHeader) {
    if (createNewTestFromSpecHeader) {
      cy.findByTestId('create-new-test-from-spec-header').click()
    } else {
      cy.get('@runnable-wrapper').realHover().findByTestId('create-new-test-from-suite').click()
    }

    cy.findByTestId('studio-panel').should('be.visible')
    cy.findByTestId('new-test-button').should('be.visible')
  } else {
    cy.get('@runnable-wrapper')
    .findByTestId('launch-studio')
    .click()

    // Studio re-executes spec before waiting for commands - wait for the spec to finish executing.
    cy.waitForSpecToFinish()

    cy.get('[data-cy="studio-single-test-title"]').contains(testTitle)

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

export function assertClosingPanelWithoutChanges () {
  // Cypress re-runs after you cancel Studio.
  // Original spec should pass
  cy.waitForSpecToFinish({ passCount: 1 })

  cy.get('.command').should('have.length', 1)