Repository: cypress-io/cypress
File: packages/launchpad/cypress/e2e/integration/choose-a-browser.spec.ts (TypeScript)

Code before:
      }

      sinon.stub(ctx._apis.appApi, 'getBrowsers').resolves([])
    })
  }

  // Creates and returns aliases for browsers found on the DOM
  const getBrowserAliases = function () {
    cy.get('[data-cy="open-browser-list"] [data-selected-browser]').eq(0).as('chromeRadioOption')
    cy.get('[data-cy="open-browser-list"] [data-selected-browser]').eq(1).as('firefoxRadioOption')
    cy.get('[data-cy="open-browser-list"] [data-selected-browser]').eq(2).as('electronRadioOption')
    cy.get('[data-cy="open-browser-list"] [data-selected-browser]').eq(3).as('edgeRadioOption')

    return {
      chrome: '@chromeRadioOption',
      firefox: '@firefoxRadioOption',
      electron: '@electronRadioOption',
      edge: '@edgeRadioOption',
    }
  }

  beforeEach(() => {
    cy.scaffoldProject('launchpad')
  })

  describe('with found browsers', () => {
    beforeEach(() => {
      setupMockBrowsers()
    })

    it('preselects browser that is provided through the command line', () => {
      cy.openProject('launchpad', ['--e2e', '--browser', 'edge'])

      cy.visitLaunchpad()
      stepThroughConfigPages()

      cy.get('h1').should('contain', 'Choose a Browser')

      cy.get('[data-cy="open-browser-list"] [data-selected-browser="true"]')
      .should('contain', 'Edge')
    })

    it('shows warning when launched with --browser name that cannot be found', () => {
      cy.openProject('launchpad', ['--e2e', '--browser', 'doesNotExist'])
      cy.visitLaunchpad()

      stepThroughConfigPages()

      cy.get('h1').should('contain', 'Choose a Browser')
      cy.get('[data-cy="alert-header"]').should('contain', 'Warning: Browser Not Found')
      cy.get('[data-cy="alert-body"]')

Review comment (suggestion):
total nit, when reading this the through, I wasn't expected the test case `shows warning when launched with --browser name that cannot be found` given this describe block name.

Code after:
      cy.get('[data-cy="alert-header"]').should('not.exist')
    })

    it('shows installed browsers with their relevant properties', () => {
      cy.openProject('launchpad', ['--e2e'])

      cy.visitLaunchpad()

      stepThroughConfigPages()

      cy.get('h1').should('contain', 'Choose a Browser')

      cy.findByRole('radio', { name: 'Chrome v1' })

      cy.findByRole('radio', { name: 'Firefox v5' })

      cy.findByRole('radio', { name: 'Electron v12' })

      cy.findByRole('radio', { name: 'Edge v8' })
    })

    it('performs mutation to launch selected browser when launch button is pressed', () => {
      cy.openProject('launchpad', ['--e2e'])

      cy.visitLaunchpad()

      stepThroughConfigPages()

      cy.get('h1').should('contain', 'Choose a Browser')

      cy.contains('button', 'Launch Chrome').as('launchButton')

      // Stub out response to prevent browser launch but not break internals
      cy.intercept('mutation-OpenBrowser_LaunchProject', {
        body: {
          data: {
            launchOpenProject: true,
            setProjectPreferences: {
              currentProject: {
                id: 'test-id',
                title: 'launchpad',
                __typename: 'CurrentProject',
              },
              __typename: 'Query',
            },
          },
        },
      }).as('launchProject')

      cy.get('@launchButton').click()