<commit_before>require 'rails_helper'

# I'm disabling this Rubocop check to allow writing readable scenarios
# rubocop:disable RSpec/InstanceVariable

RSpec.feature 'Manager has to setup their office and preferences', type: :feature do

  scenario 'Manager signing in for second time or later and their office is not setup is redirected to office setup' do
    given_the_office_is_not_setup
    and_manager_has_signed_in_before
    when_they_sign_in
    they_are_redirected_to_the_office_setup
  end

  scenario 'Manager signing in for second time or later and their office is already setup is redirected to dashboard' do
    given_the_office_is_setup
    and_manager_has_signed_in_before
    when_they_sign_in
    they_are_redirected_to_the_dashboard
  end

  scenario 'Manager signing in for the first time is redirected to office setup' do
    given_the_office_is_not_setup
    and_manager_has_not_signed_in_before
    when_they_sign_in
    they_are_redirected_to_the_office_setup
  end

  def given_the_office_is_not_setup
    @office = create :office
  end

  def given_the_office_is_setup
    @office = create :office_with_jurisdictions
  end

  def and_manager_has_signed_in_before
    @manager = create :manager, office: @office, sign_in_count: 2
  end

  def and_manager_has_not_signed_in_before
    @manager = create :manager, office: @office, sign_in_count: 0
  end

  def when_they_sign_in
    visit new_user_session_path
    fill_in 'user_email', with: @manager.email
    fill_in 'user_password', with: <PASSWORD>
    click_button 'Sign in'
  end

  def they_are_redirected_to_the_office_setup
    expect(page.current_path).to eql "/offices/#{@office.id}/edit"
  end

  def they_are_redirected_to_the_dashboard
    expect(page.current_path).to eql '/'
  end
end<commit_msg>Add more scenarios<commit_after>require 'rails_helper'

# I'm disabling this Rubocop check to allow writing readable scenarios
# rubocop:disable RSpec/InstanceVariable

RSpec.feature 'Manager has to setup their office and preferences', type: :feature do

  scenario 'Signing in for second time or later and their office is not setup is redirected to office setup' do
    given_the_office_is_not_setup
    and_manager_has_signed_in_before
    when_they_sign_in
    then_they_are_redirected_to_the_office_setup
  end

  scenario 'Signing in for second time or later and their office is already setup is redirected to dashboard' do
    given_the_office_is_setup
    and_manager_has_signed_in_before
    when_they_sign_in
    then_they_are_redirected_to_the_dashboard
  end

  scenario 'Signing in for the first time is redirected to office setup' do
    given_the_office_is_not_setup
    and_manager_has_not_signed_in_before
    when_they_sign_in
    then_they_are_redirected_to_the_office_setup
  end

  scenario 'After setting up the office, they are redirected to their profile setup if signing in for the first time' do
    given_the_office_is_not_setup
    and_manager_has_not_signed_in_before
    and_they_sign_in
    when_they_setup_the_office
    then_they_are_redirected_to_the_profile_setup
  end

  scenario 'After setting up the office, they are redirected to dashboard if signing in for second time or later' do
    given_the_office_is_not_setup
    and_manager_has_signed_in_before
    and_they_sign_in
    when_they_setup_the_office
    then_they_are_redirected_to_the_dashboard
  end

  scenario 'After setting up their profile, they are redirected to dashboard if signing in for the first time' do
    given_the_office_is_not_setup
    and_manager_has_not_signed_in_before
    and_they_sign_in
    when_they_setup_the_office
    when_whey_setup_their_profile
    then_they_are_redirected_to_the_dashboard
  end

  def given_the_office_is_not_setup
    @office = create :office
  end

  def given_the_office_is_setup
    @office = create :office_with_jurisdictions
  end

  def and_manager_has_signed_in_before
    @manager = create :manager, office: @office, sign_in_count: 2
  end

  def and_manager_has_not_signed_in_before
    @manager = create :manager, office: @office, sign_in_count: 0
  end

  def when_they_sign_in
    visit new_user_session_path
    fill_in 'user_email', with: @manager.email
    fill_in 'user_password', with: <PASSWORD>
    click_button 'Sign in'
  end
  alias_method :and_they_sign_in, :when_they_sign_in

  def when_they_setup_the_office
    check Jurisdiction.first.name
    click_button 'Update Office'
  end

  def when_whey_setup_their_profile
    choose Jurisdiction.first.name
    click_button 'Save changes'
  end

  def then_they_are_redirected_to_the_office_setup
    expect(page.current_path).to eql "/offices/#{@office.id}/edit"
  end

  def then_they_are_redirected_to_the_dashboard
    expect(page.current_path).to eql '/'
  end

  def then_they_are_redirected_to_the_profile_setup
    expect(page.current_path).to eql "/users/#{@manager.id}/edit"
  end
end
{'fraction_non_alphanumeric': 0.039175678432972864, 'fraction_numerical': 0.0008161599673536013, 'mean_word_length': 4.713286713286713, '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': '6537332', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1591, 'n_words': 414}