# frozen_string_literal: true
require 'test_helper'

class AnswerFormatValidatorTest < ActiveSupport::TestCase
  test "checkbox should PASS with populated array" do
    obj = AnswerValidatable.new('checkbox')
    obj.answer = ["", "", "valid answer"]

    assert obj.valid?
    assert obj.errors.messages.empty?
  end

  test "checkbox should FAIL with nil" do
    obj = AnswerValidatable.new('checkbox')
    obj.answer = nil

    refute obj.valid?
    assert_match(/select.*answer/, obj.errors.messages[:answer][0])
  end

  test "checkbox should FAIL with empty string" do
    obj = AnswerValidatable.new('checkbox')
    obj.answer = " "

    refute obj.valid?
    assert_match(/select.*answer/, obj.errors.messages[:answer][0])
  end

  test "checkbox should FAIL with array of empty strings" do
    obj = AnswerValidatable.new('checkbox')
    obj.answer = ["", "", "  "]

    refute obj.valid?
    assert_match(/select.*answer/, obj.errors.messages[:answer][0])
  end
end
