<commit_before>require "rails_helper"

describe "Admin custom information texts" do

  before do
    admin = create(:administrator)
    login_as(admin.user)
  end

  it_behaves_like "edit_translatable",
                  "i18n_content",
                  "admin_site_customization_information_texts_path",
                  %w[value]

  scenario "page is correctly loaded" do
    visit admin_site_customization_information_texts_path

    click_link "Basic customization"
    expect(page).to have_content "Help about debates"
    expect(page).to have_content "Help about proposals"
    expect(page).to have_content "Help about voting"
    expect(page).to have_content "Help about collaborative legislation"
    expect(page).to have_content "Help with participatory budgets"

    within("#information-texts-tabs") { click_link "Debates" }
    expect(page).to have_content "Help about debates"

    within("#information-texts-tabs") { click_link "Community" }
    expect(page).to have_content "Access the community"

    within("#information-texts-tabs") { click_link "Proposals" }
    expect(page).to have_content "Create proposal"

    within "#information-texts-tabs" do
      click_link "Polls"
    end

    expect(page).to have_content "Results"

    click_link "Layouts"
    expect(page).to have_content "Accessibility"

    click_link "Emails"
    expect(page).to have_content "Confirm your email"

    within "#information-texts-tabs" do
      click_link "Management"
    end

    expect(page).to have_content "This user account is already verified."

    click_link "Welcome"
    expect(page).to have_content "See all debates"
  end

  scenario "check that tabs are highlight when click it" do
    visit admin_site_customization_information_texts_path

    within("#information-texts-tabs") { click_link "Proposals" }
    expect(find("a[href=\"/admin/site_customization/information_texts?tab=proposals\"].is-active"))
          .to have_content "Proposals"
  end

  context "Globalization" do

    scenario "Add a translation", :js do
      key = "debates.index.section_footer.title"

      visit admin_site_customization_information_texts_path

      select "Français", from: :add_language
      fill_in "contents[content_#{key}]values[value_fr]", with: "Aide personalise sur les débats"

      click_button "Save"

      expect(page).to have_content "Translation updated successfully"

      visit admin_site_customization_information_texts_path
      select "Français", from: :select_language

      expect(page).to have_content "Aide personalise sur les débats"
      expect(page).not_to have_content "Aide sur les débats"
    end

    scenario "Update a translation", :js do
      key = "proposals.form.proposal_title"

      visit admin_site_customization_information_texts_path(tab: "proposals")<commit_msg>Fix error during rebase<commit_after>require "rails_helper"

describe "Admin custom information texts" do

  before do
    admin = create(:administrator)
    login_as(admin.user)
  end

  it_behaves_like "edit_translatable",
                  "i18n_content",
                  "admin_site_customization_information_texts_path",
                  %w[value]

  scenario "page is correctly loaded" do
    visit admin_site_customization_information_texts_path

    click_link "Basic customization"
    expect(page).to have_content "Help about debates"
    expect(page).to have_content "Help about proposals"
    expect(page).to have_content "Help about voting"
    expect(page).to have_content "Help about collaborative legislation"
    expect(page).to have_content "Help with participatory budgets"

    within("#information-texts-tabs") { click_link "Debates" }
    expect(page).to have_content "Help about debates"

    within("#information-texts-tabs") { click_link "Community" }
    expect(page).to have_content "Access the community"

    within("#information-texts-tabs") { click_link "Proposals" }
    expect(page).to have_content "Create proposal"

    within "#information-texts-tabs" do
      click_link "Polls"
    end

    expect(page).to have_content "Results"

    click_link "Layouts"
    expect(page).to have_content "Accessibility"

    click_link "Emails"
    expect(page).to have_content "Confirm your email"

    within "#information-texts-tabs" do
      click_link "Management"
    end

    expect(page).to have_content "This user account is already verified."

    click_link "Welcome"
    expect(page).to have_content "See all debates"
  end

  scenario "check that tabs are highlight when click it" do
    visit admin_site_customization_information_texts_path

    within("#information-texts-tabs") { click_link "Proposals" }
    expect(find("a[href=\"/admin/site_customization/information_texts?tab=proposals\"].is-active"))
          .to have_content "Proposals"
  end

  context "Globalization" do

    scenario "Add a translation", :js do
      key = "debates.index.section_footer.title"

      visit admin_site_customization_information_texts_path

      select "Français", from: :add_language
      fill_in "contents[content_#{key}]values[value_fr]", with: "Aide personalise sur les débats"

      click_button "Save"

      expect(page).to have_content "Translation updated successfully"

      visit admin_site_customization_information_texts_path
      select "Français", from: :select_language

      expect(page).to have_content "Aide personalise sur les débats"
      expect(page).not_to have_content "Aide sur les débats"
    end

    scenario "Update a translation", :js do
      key = "proposals.form.proposal_title"
      create(:i18n_content, key: key, value_fr: "Titre de la proposition")

      visit admin_site_customization_information_texts_path(tab: "proposals")
{'fraction_non_alphanumeric': 0.0892264711017985, 'fraction_numerical': 0.0010476689366160294, 'mean_word_length': 3.8460236886632826, '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': '2014399', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1668, 'n_words': 422}