<commit_before>require 'rails_helper'

RSpec.describe 'Remote clinic volunteer uploads a draft', type: :feature, js: true do
  let(:community) { create(:community) }
  let(:volunteer) { create(:user, :volunteer, community: community) }
  let!(:release) { create(:release, friend: friend) }
  let(:friend) { create(:friend, community: community) }
  let!(:user_friend_association) { create(:user_friend_association, friend: friend, user: volunteer)}

  before do
    login_as(volunteer)
    visit root_path
    click_link 'Clinic'
    click_link friend.name
  end

  context 'there is not a remote clinic lawyer assigned to the friend yet' do
    scenario 'upload a draft and submit for review; should email the regional admin' do
      upload_draft_and_submit

      # TODO: regional admin should get an email 'Lawyer Assignment Needed'
    end
  end

  context 'there is a remote clinic lawyer assigned to the friend' do
    let!(:remote_clinic_lawyer) { create(:user, :remote_clinic_lawyer) }
    let!(:lawyer_friend_assocition) { create(:user_friend_association, user: remote_clinic_lawyer, friend: friend, remote: true) }

    scenario 'upload a draft and submit for review; should email the remote clinic lawyer' do
      upload_draft_and_submit

      # TODO: remote clinic lawyer should get an email 'Review needed'
    end
  end

  def upload_draft_and_submit
    click_link 'Documents'
    expect(page).to have_content 'There are no files associated with this user.'
    click_on 'Create Document'
    expect(page).to have_content 'New Document'
    attach_file 'File Upload', Rails.root.join('spec', 'support', 'images', 'nsc_logo.png'), make_visible: true
    select 'Asylum', from: 'application[category]'
    # TODO
    # add self to volunteers list
    # Save; should land back on Documents tab
    # should see Submit For Review button
    # click Submit For Review
    # should see In Review
  end
end<commit_msg>finish implementing spec except for the email receiving part<commit_after>require 'rails_helper'

RSpec.describe 'Remote clinic volunteer uploads a draft', type: :feature, js: true do
  let(:region) { create(:region) }
  let(:community) { create(:community, region: region) }
  let!(:regional_admin) { create(:user, :regional_admin, community: community) }
  let(:volunteer) { create(:user, :volunteer, community: community) }
  let!(:release) { create(:release, friend: friend) }
  let(:friend) { create(:friend, community: community, region: region) }
  let!(:user_friend_association) { create(:user_friend_association, friend: friend, user: volunteer)}

  before do
    login_as(volunteer)
    visit root_path
    click_link 'Clinic'
    click_link friend.name
  end

  context 'there is not a remote clinic lawyer assigned to the friend yet' do
    scenario 'upload a draft and submit for review; should email the regional admin' do
      upload_draft_and_submit

      # TODO: regional admin should get an email 'Lawyer Assignment Needed'
    end
  end

  context 'there is a remote clinic lawyer assigned to the friend' do
    let!(:remote_clinic_lawyer) { create(:user, :remote_clinic_lawyer) }
    let!(:lawyer_friend_assocition) { create(:user_friend_association, user: remote_clinic_lawyer, friend: friend, remote: true) }

    scenario 'upload a draft and submit for review; should email the remote clinic lawyer' do
      upload_draft_and_submit

      # TODO: remote clinic lawyer should get an email 'Review needed'
    end
  end

  def upload_draft_and_submit
    # Upload a new document
    click_link 'Documents'
    expect(page).to have_content 'There are no files associated with this user.'
    click_on 'Create Document'
    expect(page).to have_content 'New Document'
    attach_file 'File Upload', Rails.root.join('spec', 'support', 'images', 'nsc_logo.png'), make_visible: true
    select 'Asylum', from: 'application[category]'

    # Add self as a volunteer
    find('#draft_user_ids_chosen').click
    within('.chosen-results') do
      find('li', text: volunteer.name).click
    end
    within('.chosen-choices') do
      expect(page).to have_content volunteer.name
    end

    # Save and submit for review
    click_on 'Save'
    expect(page).to have_content 'Application draft saved'
    click_on 'Submit for Review'
    within('span.status') do
      expect(page).to have_content 'In review'
    end
  end
end
{'fraction_non_alphanumeric': 0.09244851258581235, 'fraction_numerical': 0.0, 'mean_word_length': 4.136310223266745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7241062', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1260, 'n_words': 436}