<commit_before>require 'feature_helper'
require 'api_test_helper'
require 'cookie_names'

RSpec.describe 'When the user visits the start page' do
  it 'will display the start page in English' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    visit '/start'
    expect(page).to have_content 'GOV.UK Verify'
    expect(page).to have_css 'html[lang=en]'
    expect_feedback_source_to_be(page, 'START_PAGE', '/start')
  end

  it 'will display the start page in Welsh' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    visit '/dechrau'
    expect(page).to have_content 'GOV.UK Verify'
    expect(page).to have_css 'html[lang=cy]'
  end

  it 'will not automatically disable the continue button on submit' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    visit '/start'
    expect(page).to_not have_css '#next-button[data-disable-with]'
  end

  it 'will redirect users to will it work for me page when selecting registration' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    visit '/start'
    choose 'start_form_selection_true', allow_label_click: true
    click_button 'Continue'
    expect(page).to have_current_path(will_it_work_for_me_path)
  end

  it 'will redirect users to sign-in page when selecting sign-in' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    stub_api_idp_list
    visit '/start'
    choose 'start_form_selection_false', allow_label_click: true
    click_button 'Continue'
    expect(page).to have_current_path(sign_in_path)
  end

  context 'when there is an error' do
    before(:each) do
      stub_transactions_list
    end

    it 'will display the no cookies error when all cookies are missing' do
      allow(Rails.logger).to receive(:info)
      expect(Rails.logger).to receive(:info).with("No session cookies can be found").at_least(:once)
      visit "/start"
      expect(page).to have_content "If you can’t access GOV.UK Verify from a service, enable your cookies."
      expect(page).to have_http_status :forbidden
      expect(page).to have_link 'feedback', href: '/feedback?feedback-source=COOKIE_NOT_FOUND_PAGE'
      expect(page).to have_link "register for an identity profile", href: "http://localhost:50130/test-rp"
    end

    it 'will display the generic error when start time is missing from session' do
      set_session!(transaction_simple_id: 'test-rp', verify_session_id: 'my-session-id-cookie', identity_providers: [{ 'simple_id' => 'stub-idp-one' }])
      cookie_hash = create_cookie_hash
      allow(Rails.logger).to receive(:info)
      expect(Rails.logger).to receive(:info).with('start_time not in session').at_least(:once)
      set_cookies!(cookie_hash)
      visit '/start'
      expect(page).to have_content 'Sorry, something went wrong'
      expect(page).to have_http_status :internal_server_error<commit_msg>tt-1609: Small fix for clever questions @rachelthecodesmith @CharlesIC<commit_after>require 'feature_helper'
require 'api_test_helper'
require 'cookie_names'

RSpec.describe 'When the user visits the start page' do
  it 'will display the start page in English' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    visit '/start'
    expect(page).to have_content 'GOV.UK Verify'
    expect(page).to have_css 'html[lang=en]'
    expect_feedback_source_to_be(page, 'START_PAGE', '/start')
  end

  it 'will display the start page in Welsh' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    visit '/dechrau'
    expect(page).to have_content 'GOV.UK Verify'
    expect(page).to have_css 'html[lang=cy]'
  end

  it 'will not automatically disable the continue button on submit' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    visit '/start'
    expect(page).to_not have_css '#next-button[data-disable-with]'
  end

  it 'will redirect users to will it work for me page when selecting registration' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    visit '/start'
    choose 'start_form_selection_true', allow_label_click: true
    click_button 'Continue'
    expect(page).to have_current_path(will_it_work_for_me_path)
  end

  it 'will redirect users to sign-in page when selecting sign-in' do
    set_session_and_ab_session_cookies!('clever_questions' => 'clever_questions_variant')
    stub_api_idp_list_for_sign_in
    visit '/start'
    choose 'start_form_selection_false', allow_label_click: true
    click_button 'Continue'
    expect(page).to have_current_path(sign_in_path)
  end

  context 'when there is an error' do
    before(:each) do
      stub_transactions_list
    end

    it 'will display the no cookies error when all cookies are missing' do
      allow(Rails.logger).to receive(:info)
      expect(Rails.logger).to receive(:info).with("No session cookies can be found").at_least(:once)
      visit "/start"
      expect(page).to have_content "If you can’t access GOV.UK Verify from a service, enable your cookies."
      expect(page).to have_http_status :forbidden
      expect(page).to have_link 'feedback', href: '/feedback?feedback-source=COOKIE_NOT_FOUND_PAGE'
      expect(page).to have_link "register for an identity profile", href: "http://localhost:50130/test-rp"
    end

    it 'will display the generic error when start time is missing from session' do
      set_session!(transaction_simple_id: 'test-rp', verify_session_id: 'my-session-id-cookie', identity_providers: [{ 'simple_id' => 'stub-idp-one' }])
      cookie_hash = create_cookie_hash
      allow(Rails.logger).to receive(:info)
      expect(Rails.logger).to receive(:info).with('start_time not in session').at_least(:once)
      set_cookies!(cookie_hash)
      visit '/start'
      expect(page).to have_content 'Sorry, something went wrong'
      expect(page).to have_http_status :internal_server_error
{'fraction_non_alphanumeric': 0.09860312243221035, 'fraction_numerical': 0.0023007395234182415, 'mean_word_length': 4.568161024702653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4152405', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1896, 'n_words': 488}