<commit_before>require 'rails_helper'

RSpec.feature 'unexpected journeys through the application' do
  before do
    Capybara.current_driver = :rack_test
  end

  def complete_prisoner_details
    fill_in 'Prisoner first name', with: 'Arthur'
    fill_in 'Prisoner last name', with: 'Raffles'
    fill_in 'Day', with: '1'
    fill_in 'Month', with: '1'
    fill_in 'Year', with: '1980'
    fill_in 'Prisoner number', with: 'a1234bc'
    select 'Cardiff', from: 'Name of the prison'
  end

  def complete_visitor_details
    fill_in 'Your first name', with: 'Harry'
    fill_in 'Your last name', with: 'Manders'
    fill_in 'Day', with: '1'
    fill_in 'Month', with: '1'
    fill_in 'Year', with: '1980'
    fill_in 'Email address', with: '<EMAIL>'
    fill_in 'Phone number', with: '0115 496 0123'
  end

  def complete_visit_details
    slot = first('.SlotPicker-input option[value!=""]').text
    select slot, from: 'Option 1'
  end

  def status
    page.driver.browser.last_response.status
  end

  def clear_session
    # THE SHAME OF IT
    # rack-test lets us set a cookie, or clear all of them, but deleting a
    # single cookie is concealed beneath a few layers of indirection.
    page.driver.browser.current_session.
      instance_variable_get('@rack_mock_session').cookie_jar.delete 'pvbs'
  end

  def have_title(t)
    have_selector('h1', text: t)
  end

  before do
    visit '/prisoner'
  end

  context 'session expires' do
    scenario 'while entering prisoner details' do
      complete_prisoner_details
      clear_session
      click_button 'Continue'

      expect(status).to eq(200)
      expect(page).to have_text('Your session timed out')
      expect(page).to have_title('Who are you visiting?')
    end

    scenario 'while entering visitor details' do
      complete_prisoner_details
      click_button 'Continue'

      complete_visitor_details
      clear_session
      click_button 'Continue'

      expect(status).to eq(200)
      expect(page).to have_text('Your session timed out')
      expect(page).to have_title('Who are you visiting?')
    end

    scenario 'while entering visit details' do
      complete_prisoner_details
      click_button 'Continue'

      complete_visitor_details
      click_button 'Continue'

      complete_visit_details
      clear_session
      click_button 'Continue'

      expect(status).to eq(200)
      expect(page).to have_text('Your session timed out')
      expect(page).to have_title('Who are you visiting?')
    end

    scenario 'on the confirmation page' do
      complete_prisoner_details
      click_button 'Continue'

      complete_visitor_details
      click_button 'Continue'

      complete_visit_details
      click_button 'Continue'

      clear_session
      click_button 'Send request'

      expect(status).to eq(200)
      expect(page).to have_text('Your session timed out')
      expect(page).to have_title('Who are you visiting?')
    end
  end
end<commit_msg>Add failing tests for skipping a step<commit_after>require 'rails_helper'

RSpec.feature 'unexpected journeys through the application' do
  before do
    Capybara.current_driver = :rack_test
  end

  def complete_prisoner_details
    fill_in 'Prisoner first name', with: 'Arthur'
    fill_in 'Prisoner last name', with: 'Raffles'
    fill_in 'Day', with: '1'
    fill_in 'Month', with: '1'
    fill_in 'Year', with: '1980'
    fill_in 'Prisoner number', with: 'a1234bc'
    select prison_name, from: 'Name of the prison'
  end

  def complete_visitor_details
    fill_in 'Your first name', with: 'Harry'
    fill_in 'Your last name', with: 'Manders'
    fill_in 'Day', with: '1'
    fill_in 'Month', with: '1'
    fill_in 'Year', with: '1980'
    fill_in 'Email address', with: '<EMAIL>'
    fill_in 'Phone number', with: '0115 496 0123'
  end

  def complete_visit_details
    slot = first('.SlotPicker-input option[value!=""]').text
    select slot, from: 'Option 1'
  end

  def status
    page.driver.browser.last_response.status
  end

  def clear_session
    # THE SHAME OF IT
    # rack-test lets us set a cookie, or clear all of them, but deleting a
    # single cookie is concealed beneath a few layers of indirection.
    page.driver.browser.current_session.
      instance_variable_get('@rack_mock_session').cookie_jar.delete 'pvbs'
  end

  def have_title(t)
    have_selector('h1', text: t)
  end

  def start_page
    '/prisoner'
  end

  before do
    visit start_page
  end

  context 'deferred' do
    let(:prison_name) { 'Cardiff' }

    context 'session expires' do
      scenario 'while entering prisoner details' do
        complete_prisoner_details
        clear_session
        click_button 'Continue'

        expect(status).to eq(200)
        expect(page).to have_text('Your session timed out')
        expect(page).to have_title('Who are you visiting?')
      end

      scenario 'while entering visitor details' do
        complete_prisoner_details
        click_button 'Continue'

        complete_visitor_details
        clear_session
        click_button 'Continue'

        expect(status).to eq(200)
        expect(page).to have_text('Your session timed out')
        expect(page).to have_title('Who are you visiting?')
      end

      scenario 'while entering visit details' do
        complete_prisoner_details
        click_button 'Continue'

        complete_visitor_details
        click_button 'Continue'

        complete_visit_details
        clear_session
        click_button 'Continue'

        expect(status).to eq(200)
        expect(page).to have_text('Your session timed out')
        expect(page).to have_title('Who are you visiting?')
      end

      scenario 'on the confirmation page' do
        complete_prisoner_details
        click_button 'Continue'

        complete_visitor_details
        click_button 'Continue'

        complete_visit_details
        click_button 'Continue'

        clear_session
        click_button 'Send request'

        expect(status).to eq(200)
        expect(page).to have_text('Your session timed out')
        expect(page).to have_title('Who are you visiting?')
      end
    end

    context 'skipping the prisoner step' do
      scenario 'and going to visitor details' do
        visit '/deferred/visitors'

        expect(status).to eq(200)
        expect(current_path).to eq(start_page)
        expect(page).to have_title('Who are you visiting?')
      end

      scenario 'and going directly to visit details' do
        visit '/deferred/slots'

        expect(status).to eq(200)
        expect(current_path).to eq(start_page)
        expect(page).to have_title('Who are you visiting?')
      end

      scenario 'and going directly to the confirmation page' do
        visit '/deferred/visit'

        expect(status).to eq(200)
        expect(current_path).to eq(start_page)
        expect(page).to have_title('Who are you visiting?')
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08696281290695992, 'fraction_numerical': 0.013167414267110404, 'mean_word_length': 2.9205899035734544, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4613493', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2043, 'n_words': 618}