<commit_before>require "rails_helper"
include Warden::Test::Helpers

Warden.test_mode!

describe "Assessor submits appraisal form", %(
  As Assessor
  I want to be able to edit, submit the appraisal form.
), js: true do
  let!(:lead) { create(:assessor, :lead_for_all) }
  let!(:form_answer) { create(:form_answer, :innovation) }
  let(:primary) { "#section-appraisal-form-primary" }
  let(:secondary) { "#section-appraisal-form-secondary" }
  let(:moderated) { "#section-appraisal-form-moderated" }

  before do
    login_as(lead, scope: :assessor)
    visit assessor_form_answer_path(form_answer)
  end

  describe "RAG change" do
    let(:rag_case) do
      lambda do
        rag = ".rag-text"
        expect(page).to have_selector(rag, text: "Select RAG", count: 3)
        expect(page).to have_selector(rag, text: "Select verdict", count: 1)

        first(".btn-rag").click
        find(".dropdown-menu .rag-negative").click

        expect(page).to have_selector(rag, text: "Select RAG", count: 2)
        expect(page).to have_selector(rag, text: "Red", count: 1)
        expect(page).to have_selector(rag, text: "Select verdict", count: 1)
        sleep(0.5)
        visit assessor_form_answer_path(form_answer)

        expect(page).to have_selector(rag, text: "Select RAG", count: 2)
        expect(page).to have_selector(rag, text: "Red", count: 1)
        expect(page).to have_selector(rag, text: "Select verdict", count: 1)
      end
    end

    it "updates the rag rate" do
      within(primary) { rag_case.call }
      within(secondary) { rag_case.call }
      within(moderated) { rag_case.call }
    end
  end

  describe "Description change" do
    let(:text) { "textareatext123" }

    let(:description_case) do
      lambda do
        first(".form-edit-link").click
        expect(page).to have_selector("textarea", count: 1)
        fill_in("assessor_assignment_level_of_innovation_desc", with: text)
        find(".form-save-link").click
        sleep(0.5)
        visit assessor_form_answer_path(form_answer)
        expect(page).to have_selector(".form-value p", text: text, count: 1)
        first(".form-edit-link").click
        expect(page).to have_selector("textarea", text: text)
      end
    end

    it "updates the description" do
      within(primary) { description_case.call }
      within(secondary) { description_case.call }
      within(moderated) { description_case.call }
    end
  end

  describe "Overall verdict change" do
    let(:verdict_case) do
      lambda do
        expect(page).to have_selector(".rag-text", text: "Select verdict", count: 1)
        all(".btn-rag").last.click
        find(".dropdown-menu .rag-positive").click
        sleep(0.5)
        visit assessor_form_answer_path(form_answer)
        expect(page).to_not have_selector(".rag-text", text: "Select verdict")
        expect(page).to have_selector(".rag-text", text: "Recommended", count: 1)
      end
    end

    it "updates verdict" do
      within(primary) { verdict_case.call }
      within(secondary) { verdict_case.call }
      within(moderated) { verdict_case.call }
    end
  end

  it "submits the form" do
    allow_any_instance_of(AssessorAssignment).to receive(:valid?).and_return(true)
    within "#section-appraisal-form-primary" do
      click_button "Submit Case Assessment"
    end
    expect(page).to have_selector(".feedbackHolder", text: "Assessment Submitted")
    expect(form_answer.assessor_assignments.primary).to be_submitted
  end
end
<commit_msg>fix appraisal form specs<commit_after>require "rails_helper"
include Warden::Test::Helpers

Warden.test_mode!

describe "Assessor submits appraisal form", %(
  As Assessor
  I want to be able to edit, submit the appraisal form.
), js: true do
  let!(:lead) { create(:assessor, :lead_for_all) }
  let!(:form_answer) { create(:form_answer, :innovation) }
  let(:primary) { "#section-appraisal-form-primary" }
  let(:secondary) { "#section-appraisal-form-secondary" }
  let(:moderated) { "#section-appraisal-form-moderated" }
  let(:primary_header) { "#appraisal-form-primary-heading" }
  let(:secondary_header) { "#appraisal-form-secondary-heading" }
  let(:moderated_header) { "#appraisal-form-moderated-heading" }

  before do
    login_as(lead, scope: :assessor)
    visit assessor_form_answer_path(form_answer)
  end

  describe "RAG change" do
    let(:rag_case) do
      lambda do |section_id, header_id|
        rag = ".rag-text"

        find("#{header_id} .panel-title a").click

        within section_id do
          expect(page).to have_selector(rag, text: "Select RAG", count: 3)
          expect(page).to have_selector(rag, text: "Select verdict", count: 1)

          first(".btn-rag").click
          find(".dropdown-menu .rag-negative").click

          expect(page).to have_selector(rag, text: "Select RAG", count: 2)
          expect(page).to have_selector(rag, text: "Red", count: 1)
          expect(page).to have_selector(rag, text: "Select verdict", count: 1)
        end

        sleep(0.5)
        visit assessor_form_answer_path(form_answer)

        find("#{header_id} .panel-title a").click

        within section_id do
          expect(page).to have_selector(rag, text: "Select RAG", count: 2)
          expect(page).to have_selector(rag, text: "Red", count: 1)
          expect(page).to have_selector(rag, text: "Select verdict", count: 1)
        end
      end
    end

    it "updates the rag rate" do
      rag_case.call(primary, primary_header)
      visit assessor_form_answer_path(form_answer)
      rag_case.call(secondary, secondary_header)
      visit assessor_form_answer_path(form_answer)
      rag_case.call(moderated, moderated_header)
    end
  end

  describe "Description change" do
    let(:text) { "textareatext123" }

    let(:description_case) do
      lambda do |section_id, header_id|
        find("#{header_id} .panel-title a").click

        within section_id do
          first(".form-edit-link").click
          expect(page).to have_selector("textarea", count: 1)
          fill_in("assessor_assignment_level_of_innovation_desc", with: text)
          find(".form-save-link").click
        end

        sleep(0.5)
        visit assessor_form_answer_path(form_answer)

        find("#{header_id} .panel-title a").click

        within section_id do
          expect(page).to have_selector(".form-value p", text: text, count: 1)
          first(".form-edit-link").click
          expect(page).to have_selector("textarea", text: text)
        end
      end
    end

    it "updates the description" do
      description_case.call(primary, primary_header)
      visit assessor_form_answer_path(form_answer)
      description_case.call(secondary, secondary_header)
      visit assessor_form_answer_path(form_answer)
      description_case.call(moderated, moderated_header)
    end
  end

  describe "Overall verdict change" do
    let(:verdict_case) do
      lambda do |section_id, header_id|
        find("#{header_id} .panel-title a").click

        within section_id do
          expect(page).to have_selector(".rag-text", text: "Select verdict", count: 1)
          all(".btn-rag").last.click
          find(".dropdown-menu .rag-positive").click
        end

        sleep(0.5)
        visit assessor_form_answer_path(form_answer)
        page.find("#{header_id} .panel-title a").click

        within section_id do
          expect(page).to_not have_selector(".rag-text", text: "Select verdict")
          expect(page).to have_selector(".rag-text", text: "Recommended", count: 1)
        end
      end
    end

    it "updates verdict" do
      verdict_case.call(primary, primary_header)
      visit assessor_form_answer_path(form_answer)
      verdict_case.call(secondary, secondary_header)
      visit assessor_form_answer_path(form_answer)
      verdict_case.call(moderated, moderated_header)
    end
  end

  it "submits the form" do
    allow_any_instance_of(AssessorAssignment).to receive(:valid?).and_return(true)
    find("#{primary_header} .panel-title a").click

    within "#section-appraisal-form-primary" do
      click_button "Submit Case Assessment"
    end
    expect(page).to have_selector(".feedbackHolder", text: "Assessment Submitted")
    expect(form_answer.assessor_assignments.primary).to be_submitted
  end
end

{'fraction_non_alphanumeric': 0.11973445986722993, 'fraction_numerical': 0.005069402534701267, 'mean_word_length': 3.1596385542168677, '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': '2765270', 'n_tokens_mistral': 2707, 'n_tokens_neox': 2561, 'n_words': 576}