<commit_before>require_relative '../test_helper'
require_relative '../helpers/i18n_test_helper'
require_relative '../fixtures/smart_answer_flows/smart-answers-controller-sample-with-value-question'
require_relative 'smart_answers_controller_test_helper'
require 'gds_api/test_helpers/content_api'

class SmartAnswersControllerValueQuestionTest < ActionController::TestCase
  tests SmartAnswersController

  include I18nTestHelper
  include SmartAnswersControllerTestHelper
  include GdsApi::TestHelpers::ContentApi

  def setup
    stub_content_api_default_artefact

    @flow = SmartAnswer::SmartAnswersControllerSampleWithValueQuestionFlow.build
    load_path = fixture_file('smart_answer_flows')
    SmartAnswer::FlowRegistry.stubs(:instance).returns(stub("Flow registry", find: @flow, load_path: load_path))
    use_additional_translation_file(fixture_file('smart_answer_flows/locales/en/smart-answers-controller-sample-with-value-question.yml'))
  end

  def teardown
    reset_translation_files
  end

  context "GET /<slug>" do
    context "value question" do
      should "display question" do
        get :show, id: 'smart-answers-controller-sample-with-value-question', started: 'y'
        assert_select ".step.current h2", /How many green bottles\?/
        assert_select "input[type=text][name=response]"
      end

      should "accept question input and redirect to canonical url" do
        submit_response "10"
        assert_redirected_to '/smart-answers-controller-sample-with-value-question/y/10'
      end

      should "display collapsed question, and format number" do
        get :show, id: 'smart-answers-controller-sample-with-value-question', started: 'y', responses: "12345"
        assert_select ".done-questions", /How many green bottles\?\s+12,345/
      end

      context "label in translation file" do<commit_msg>Avoid stubbing FlowRegistry in SmartAnswersControllerValueQuestionTest<commit_after>require_relative '../test_helper'
require_relative '../helpers/i18n_test_helper'
require_relative '../helpers/fixture_flows_helper'
require_relative '../fixtures/smart_answer_flows/smart-answers-controller-sample-with-value-question'
require_relative 'smart_answers_controller_test_helper'
require 'gds_api/test_helpers/content_api'

class SmartAnswersControllerValueQuestionTest < ActionController::TestCase
  tests SmartAnswersController

  include I18nTestHelper
  include FixtureFlowsHelper
  include SmartAnswersControllerTestHelper
  include GdsApi::TestHelpers::ContentApi

  def setup
    stub_content_api_default_artefact

    setup_fixture_flows
    use_additional_translation_file(fixture_file('smart_answer_flows/locales/en/smart-answers-controller-sample-with-value-question.yml'))
  end

  def teardown
    teardown_fixture_flows
    reset_translation_files
  end

  context "GET /<slug>" do
    context "value question" do
      should "display question" do
        get :show, id: 'smart-answers-controller-sample-with-value-question', started: 'y'
        assert_select ".step.current h2", /How many green bottles\?/
        assert_select "input[type=text][name=response]"
      end

      should "accept question input and redirect to canonical url" do
        submit_response "10"
        assert_redirected_to '/smart-answers-controller-sample-with-value-question/y/10'
      end

      should "display collapsed question, and format number" do
        get :show, id: 'smart-answers-controller-sample-with-value-question', started: 'y', responses: "12345"
        assert_select ".done-questions", /How many green bottles\?\s+12,345/
      end

      context "label in translation file" do
{'fraction_non_alphanumeric': 0.09073412152873248, 'fraction_numerical': 0.010448171569975254, 'mean_word_length': 4.478915662650603, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3871592', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1047, 'n_words': 223}