# frozen_string_literal: true
require 'test_helper'

class QuestionErrorTest < ActionDispatch::IntegrationTest
  test "testing full quiz for question error messages" do
    auth_candidate candidates(:gillian)

    # text
    post post_answer_path, params: { answer: { question_id: questions(:fed1).id } }
    assert_select 'h2', questions(:fed1).question
    assert_select '.error', /an answer/
    post post_answer_path, params: { answer: { question_id: questions(:fed1).id, answer: "fooBarBaz" } }

    # checkbox
    post post_answer_path, params: { answer: { question_id: questions(:fed2).id } }
    assert_select 'h2', questions(:fed2).question
    assert_select '.error', /an answer/
    post post_answer_path, params: { answer: { question_id: questions(:fed2).id, answer: "fooBarBaz" } }

    # live_code
    post post_answer_path, params: { answer: { question_id: questions(:fed3).id } }
    assert_select 'h2', questions(:fed3).question
    assert_select '.error', /comments or code/
    post post_answer_path, params: { answer: {
      question_id: questions(:fed3).id, answer_hash: { html: "fooBarBaz" }
    } }

    # text
    post post_answer_path, params: { answer: { question_id: questions(:fed4).id, answer: "fooBarBaz" } }

    # radio
    post post_answer_path, params: { answer: { question_id: questions(:fed5).id } }
    assert_select 'h2', questions(:fed5).question
    assert_select '.error', /an answer/
    post post_answer_path, params: { answer: { question_id: questions(:fed5).id, answer: "fooBarBaz" } }

    # text
    post post_answer_path, params: { answer: { question_id: questions(:fed6).id, answer: "fooBarBaz" } }

    # live_code
    post post_answer_path, params: { answer: {
      question_id: questions(:fed7).id, answer_hash: { html: "fooBarBaz" }
    } }

    # radio_other
    post post_answer_path, params: { answer: { question_id: questions(:fed8).id } }
    assert_select 'h2', questions(:fed8).question
    assert_select '.error', /an answer/
    post post_answer_path, params: { answer: {
      question_id: questions(:fed8).id, answer_hash: { options: "fooBarBaz" }
    } }

    # checkbox_other
    post post_answer_path, params: { answer: { question_id: questions(:fed9).id } }
    assert_select 'h2', questions(:fed9).question
    assert_select '.error', /an answer/
    post post_answer_path, params: { answer: {
      question_id: questions(:fed9).id, answer_hash: { options: "fooBarBaz" }
    } }

    # checkbox
    post post_answer_path, params: { answer: { question_id: questions(:fed10).id, answer: "fooBarBaz" } }

    # checkbox
    post post_answer_path, params: { answer: { question_id: questions(:fed11).id, answer: "fooBarBaz" } }

    # checkbox
    post post_answer_path, params: { answer: { question_id: questions(:fed12).id, answer: "fooBarBaz" } }
  end
end
