<commit_before>require "rails_helper"

describe "Public area translatable records" do
  let(:user) { create(:user, :in_census) }

  before do
    Setting["feature.translation_interface"] = true
    login_as(user)
  end

  context "New records", :js do
    scenario "Add only single translation at once" do
      visit new_debate_path

      fill_in "Debate title", with: "Who won the debate?"
      fill_in_ckeditor "Initial debate text", with: "And who will win this debate?"
      check "debate_terms_of_service"
      click_button "Start a debate"

      expect(page).to have_content "Debate created successfully"
    end

    scenario "Add single translation maintains introduced field values" do
      visit new_proposal_path

      fill_in "Proposal title", with: "Olympic Games in Melbourne"
      fill_in "Proposal summary", with: "Full proposal for our candidature"
      fill_in_ckeditor "Proposal text", with: "2032 will make Australia famous again"
      check "proposal_terms_of_service"
      click_button "Create proposal"

      expect(page).to have_content "Proposal created successfully"
      expect(page).to have_content "Olympic Games in Melbourne"
      expect(page).to have_content "Full proposal for our candidature"
      expect(page).to have_content "2032 will make Australia famous again"
    end

    scenario "Add multiple translations at once" do
      budget = create(:budget_heading, name: "Everywhere").group.budget

      visit new_budget_investment_path(budget)

      fill_in "Title", with: "My awesome project"
      fill_in_ckeditor "Description", with: "Everything is awesome!"

      select "Français", from: :add_language
      fill_in "Title", with: "Titre en Français"
      fill_in_ckeditor "Description", with: "Contenu en Français"

      select "Everywhere", from: "budget_investment_heading_id"
      check "budget_investment_terms_of_service"
      click_button "Create Investment"

      expect(page).to have_content "Budget Investment created successfully"
    end

    scenario "Add only single translation at once not having the current locale" do
      visit new_proposal_path
      click_link "Remove language"
      select "Français", from: :add_language

      fill_in "Proposal title", with: "Titre en Français"
      fill_in "Proposal summary", with: "Résumé en Français"
      check "proposal_terms_of_service"
      click_button "Create proposal"

      expect(page).to have_content "Proposal created successfully"
    end

    scenario "Add a translation for a locale with non-underscored name" do
      budget = create(:budget_heading, name: "Everywhere").group.budget

      visit new_budget_investment_path(budget)
      click_link "Remove language"
      select "Português brasileiro", from: :add_language
      fill_in "Title", with: "Titre en Français"
      fill_in_ckeditor "Description", with: "Contenu en Français"

      select "Everywhere", from: "budget_investment_heading_id"
      check "budget_investment_terms_of_service"
      click_button "Create Investment"

      expect(page).to have_content "Budget Investment created successfully"
    end

    scenario "Add an invalid translation" do
      visit new_debate_path

      check "debate_terms_of_service"
      click_button "Start a debate"

      expect(page).to have_css "#error_explanation"
      expect(page).to have_field "Debate title", with: "", class: "is-invalid-input"
    end

    scenario "Shows errors when submiting without any active translations" do
      budget = create(:budget_heading, name: "Everywhere").group.budget

      visit new_budget_investment_path(budget)
      click_link "Remove language"

      select "Everywhere", from: "budget_investment_heading_id"
      check "budget_investment_terms_of_service"
      click_button "Create Investment"

      expect(page).to have_css "#error_explanation"
      expect(page).to have_field "Title", with: ""
    end
  end

  context "Globalize javascript interface", :js do
    scenario "Highlight current locale" do
      visit new_debate_path

      expect_to_have_language_selected "English"
    end

    scenario "Highlight new locale added" do
      visit new_proposal_path

      select "Español", from: "locale-switcher"

      expect_to_have_language_selected "Español"
    end

    scenario "Select a locale and add it to the form" do
      visit new_budget_investment_path(create(:budget_investment))

      select "Français", from: :add_language

      expect(page).to have_field "Title", with: ""
    end

    scenario "Remove a translation" do
      visit new_budget_investment_path(create(:budget_investment))

      expect(find("#select_language").value).to eq "en"
      click_link "Remove language"

      expect_not_to_have_language("English")
    end

    context "Languages in use" do
      scenario "Show default description" do
        visit new_debate_path

        expect(page).to have_content "1 language in use"
      end

      scenario "Increase description count after add new language" do
        visit new_proposal_path

        select "Español", from: :add_language

        expect(page).to have_content "2 languages in use"
      end

      scenario "Decrease description count after remove a language" do<commit_msg>Fix typos in translatable spec<commit_after>require "rails_helper"

describe "Public area translatable records" do
  let(:user) { create(:user, :in_census) }

  before do
    Setting["feature.translation_interface"] = true
    login_as(user)
  end

  context "New records", :js do
    scenario "Add only single translation at once" do
      visit new_debate_path

      fill_in "Debate title", with: "Who won the debate?"
      fill_in_ckeditor "Initial debate text", with: "And who will win this debate?"
      check "debate_terms_of_service"
      click_button "Start a debate"

      expect(page).to have_content "Debate created successfully"
    end

    scenario "Add single translation maintains introduced field values" do
      visit new_proposal_path

      fill_in "Proposal title", with: "Olympic Games in Melbourne"
      fill_in "Proposal summary", with: "Full proposal for our candidature"
      fill_in_ckeditor "Proposal text", with: "2032 will make Australia famous again"
      check "proposal_terms_of_service"
      click_button "Create proposal"

      expect(page).to have_content "Proposal created successfully"
      expect(page).to have_content "Olympic Games in Melbourne"
      expect(page).to have_content "Full proposal for our candidature"
      expect(page).to have_content "2032 will make Australia famous again"
    end

    scenario "Add multiple translations at once" do
      budget = create(:budget_heading, name: "Everywhere").group.budget

      visit new_budget_investment_path(budget)

      fill_in "Title", with: "My awesome project"
      fill_in_ckeditor "Description", with: "Everything is awesome!"

      select "Français", from: :add_language
      fill_in "Title", with: "Titre en Français"
      fill_in_ckeditor "Description", with: "Contenu en Français"

      select "Everywhere", from: "budget_investment_heading_id"
      check "budget_investment_terms_of_service"
      click_button "Create Investment"

      expect(page).to have_content "Budget Investment created successfully"
    end

    scenario "Add only single translation at once not having the current locale" do
      visit new_proposal_path
      click_link "Remove language"
      select "Français", from: :add_language

      fill_in "Proposal title", with: "Titre en Français"
      fill_in "Proposal summary", with: "Résumé en Français"
      check "proposal_terms_of_service"
      click_button "Create proposal"

      expect(page).to have_content "Proposal created successfully"
    end

    scenario "Add a translation for a locale with non-underscored name" do
      budget = create(:budget_heading, name: "Everywhere").group.budget

      visit new_budget_investment_path(budget)
      click_link "Remove language"
      select "Português brasileiro", from: :add_language
      fill_in "Title", with: "Titre en Français"
      fill_in_ckeditor "Description", with: "Contenu en Français"

      select "Everywhere", from: "budget_investment_heading_id"
      check "budget_investment_terms_of_service"
      click_button "Create Investment"

      expect(page).to have_content "Budget Investment created successfully"
    end

    scenario "Add an invalid translation" do
      visit new_debate_path

      check "debate_terms_of_service"
      click_button "Start a debate"

      expect(page).to have_css "#error_explanation"
      expect(page).to have_field "Debate title", with: "", class: "is-invalid-input"
    end

    scenario "Shows errors when submiting without any active translations" do
      budget = create(:budget_heading, name: "Everywhere").group.budget

      visit new_budget_investment_path(budget)
      click_link "Remove language"

      select "Everywhere", from: "budget_investment_heading_id"
      check "budget_investment_terms_of_service"
      click_button "Create Investment"

      expect(page).to have_css "#error_explanation"
      expect(page).to have_field "Title", with: ""
    end
  end

  context "Globalize javascript interface", :js do
    scenario "Highlight current locale" do
      visit new_debate_path

      expect_to_have_language_selected "English"
    end

    scenario "Highlight new locale added" do
      visit new_proposal_path

      select "Español", from: "locale-switcher"

      expect_to_have_language_selected "Español"
    end

    scenario "Select a locale and add it to the form" do
      visit new_budget_investment_path(create(:budget))

      select "Français", from: :add_language

      expect(page).to have_field "Title", with: ""
    end

    scenario "Remove a translation" do
      visit new_budget_investment_path(create(:budget))

      expect(find("#select_language").value).to eq "en"
      click_link "Remove language"

      expect_not_to_have_language("English")
    end

    context "Languages in use" do
      scenario "Show default description" do
        visit new_debate_path

        expect(page).to have_content "1 language in use"
      end

      scenario "Increase description count after add new language" do
        visit new_proposal_path

        select "Español", from: :add_language

        expect(page).to have_content "2 languages in use"
      end

      scenario "Decrease description count after remove a language" do
{'fraction_non_alphanumeric': 0.07446909818112561, 'fraction_numerical': 0.00190458051614132, 'mean_word_length': 3.5443530938987453, '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': '5917830', 'n_tokens_mistral': 3143, 'n_tokens_neox': 2994, 'n_words': 943}