<commit_before># frozen_string_literal: true

require "test_helper"

module GobiertoParticipation
  module Processes
    module ProcessContributions
      class PermissionLevelsTest < ActionDispatch::IntegrationTest
        def site
          @site ||= sites(:madrid)
        end

        def registered_level_user
          @registered_level_user ||= users(:susan)
        end

        def verified_level_user
          @verified_level_user ||= users(:peter)
        end

        def registered_level_contribution_container
          @registered_level_contribution_container ||= gobierto_participation_contribution_containers(:children_contributions)
        end

        def verified_level_contribution_container
          @verified_level_contribution_container ||= gobierto_participation_contribution_containers(:neighbors_contributions)
        end

        def container_path(container)
          gobierto_participation_process_contribution_container_path(container.process.slug, container.slug)
        end

        def new_participation_path(container)
          new_gobierto_participation_process_contribution_container_contribution_path(container.process.slug, container.slug)
        end

        def with_js_session_of_user(user)
          sign_out_user
          with_current_site(site) do
            with_javascript do
              with_signed_in_user(user) do
                yield
              end
            end
          end
        end

        def test_not_registered_user_contributions
          sign_out_user
          with_current_site(site) do
            visit container_path registered_level_contribution_container
            refute has_link? 'Have an idea!', href: new_participation_path(registered_level_contribution_container)

            visit container_path verified_level_contribution_container
            refute has_link? 'Have an idea!', href: new_participation_path(verified_level_contribution_container)
          end
        end

        def test_registered_level_user_contributions_registered_level
          with_js_session_of_user(registered_level_user) do
            visit container_path registered_level_contribution_container
            assert has_link? 'Have an idea!', href: new_participation_path(registered_level_contribution_container)
            page.find("a", text: "Have an idea!").trigger("click")
            assert page.has_content? "WRITE YOUR IDEA CONCISE"
          end
        end

        def test_registered_level_user_contributions_verified_level<commit_msg>#1265: Fix tests using javascript to sign out before each test run<commit_after># frozen_string_literal: true

require "test_helper"

module GobiertoParticipation
  module Processes
    module ProcessContributions
      class PermissionLevelsTest < ActionDispatch::IntegrationTest
        def site
          @site ||= sites(:madrid)
        end

        def registered_level_user
          @registered_level_user ||= users(:susan)
        end

        def verified_level_user
          @verified_level_user ||= users(:peter)
        end

        def registered_level_contribution_container
          @registered_level_contribution_container ||= gobierto_participation_contribution_containers(:children_contributions)
        end

        def verified_level_contribution_container
          @verified_level_contribution_container ||= gobierto_participation_contribution_containers(:neighbors_contributions)
        end

        def container_path(container)
          gobierto_participation_process_contribution_container_path(container.process.slug, container.slug)
        end

        def new_participation_path(container)
          new_gobierto_participation_process_contribution_container_contribution_path(container.process.slug, container.slug)
        end

        def with_js_session_of_user(user)
          visit root_path
          sign_out_user unless has_content? "Sign in"
          with_current_site(site) do
            with_javascript do
              with_signed_in_user(user) do
                yield
              end
            end
          end
        end

        def test_not_registered_user_contributions
          sign_out_user
          with_current_site(site) do
            visit container_path registered_level_contribution_container
            refute has_link? 'Have an idea!', href: new_participation_path(registered_level_contribution_container)

            visit container_path verified_level_contribution_container
            refute has_link? 'Have an idea!', href: new_participation_path(verified_level_contribution_container)
          end
        end

        def test_registered_level_user_contributions_registered_level
          with_js_session_of_user(registered_level_user) do
            visit container_path registered_level_contribution_container
            assert has_link? 'Have an idea!', href: new_participation_path(registered_level_contribution_container)
            page.find("a", text: "Have an idea!").trigger("click")
            assert page.has_content? "WRITE YOUR IDEA CONCISE"
          end
        end

        def test_registered_level_user_contributions_verified_level
{'fraction_non_alphanumeric': 0.04511132623426912, 'fraction_numerical': 0.0007744433688286545, 'mean_word_length': 2.94954128440367, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3878232', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1335, 'n_words': 254}