context('Scenarios', () => {
  before(() => {
    cy.setupProject('scratch')
  })

  beforeEach(() => {
    // identify and open the scenarios panel, if closed
    cy.findByText(/Scenarios/)
      .parent()
      .as('scenarioPanel')
    cy.get('@scenarioPanel').then((pan) => {
      if (!pan.text().includes('Create a scenario')) {
        cy.get('@scenarioPanel').click()
      }
    })
  })

  it('start with "baseline" and "default"', () => {
    cy.get('@scenarioPanel')
      .contains(/Baseline/)
      .findByTitle(/Delete this scenario/)
      .should('not.exist')
    cy.get('@scenarioPanel')
      .contains(/Default/)
      .findByTitle(/Rename this scenario/)
      .should('exist')
  })

  it('can be created and deleted', function () {
    let scenarioName = 'scenario ' + Date.now()
    cy.window().then((win) => {
      cy.stub(win, 'prompt')
        .onFirstCall()
        .returns(scenarioName)
        .onSecondCall()
        .returns(scenarioName + ' altered')
    })
    cy.findByRole('link', {name: 'Create a scenario'}).click()
    // TODO stub not returning altered value on second call
    //cy.get('@scenarioPanel')
    //  .contains(scenarioName)
    //  .findByTitle(/Rename/)
    //  .click()
    cy.get('@scenarioPanel')
      .contains(scenarioName)
      .findByTitle(/Delete this scenario/)
      .click()
    cy.get('@scenarioPanel').findByText(scenarioName).should('not.exist')
  })
})

@@ -265,16 +265,18 @@
 hen((pan
+el
 ) =%3E %7B%0A 
@@ -288,16 +288,18 @@
 if (!pan
+el
 .text().
@@ -402,29 +402,26 @@
  it(
-'start with %22
+%22include '
 baseline
 %22 an
@@ -420,24 +420,22 @@
 line
-%22 and %22
+' & '
 default
-%22
 '
+%22
 , ()
@@ -715,20 +715,28 @@
  created
- and
+, renamed, &
  deleted
@@ -864,40 +864,8 @@
 pt')
-%0A        .onFirstCall()%0A        
 .ret
@@ -893,34 +893,10 @@
     
-  .onSecondCall()%0A        
+//
 .ret
@@ -1005,70 +1005,138 @@
     
-// TODO stub not returning altered value on second call
+cy.window().then((win) =%3E %7B%0A      win.prompt.restore()%0A      cy.stub(win, 'prompt').returns(scenarioName + ' altered')%0A    %7D)
 %0A    
-//
 cy.g
@@ -1156,26 +1156,24 @@
 Panel')%0A    
-//
   .contains(
@@ -1190,18 +1190,16 @@
 me)%0A    
-//
   .findB
@@ -1219,18 +1219,16 @@
 e/)%0A    
-//
   .click
@@ -1279,32 +1279,45 @@
 ins(scenarioName
+ + ' altered'
 )%0A      .findByT

test renaming of scenarios