<commit_before># frozen_string_literal: true
require 'capybara_feature_test'
include ActionView::Helpers::TextHelper

class LoginTest < CapybaraFeatureTest
  CHECK = /result_symbol_check/
  DASH = /result_symbol_dash/
  QUESTION = /result_symbol_question/
  X = /result_symbol_x/

  setup do
    FastlyRails.configure do |c|
      c.purging_enabled = true
    end
    @user = users(:test_user)
    @project = projects(:one)
  end

  teardown do
    FastlyRails.configure do |c|
      c.purging_enabled = false
    end
  end

  # rubocop:disable Metrics/BlockLength
  scenario 'Can Login and edit using custom account', js: true do
    visit projects_path
    click_on 'Login'
    fill_in 'Email', with: @user.email
    fill_in 'Password', with: 'password'
    click_button 'Log in using custom account'
    assert has_content? 'Signed in!'
    assert_equal current_path, projects_path
    # Check we are redirected back to root if we try to get login again
    visit login_path
    assert_equal current_path, root_path

    visit edit_project_path(@project)
    kill_sticky_headers # This is necessary for Chrome and Firefox

    fill_in 'project_name', with: 'It doesnt matter'
    # Below we are clicking the final save button, it has a value of ''
    click_button('Save', exact: true)
    assert_equal current_path, edit_project_path(@project)
    assert has_content? 'Project was successfully updated.'
    # TODO: Get the clicking working again with capybara.
    # Details: If we expand all panels first and dont click this test passes.
    #          If we instead click each section, Capybara has issues not seen
    #          in real world scenarios, mainly it doesn't correctly identify
    #          an elements parents, leading to errors.
    click_on('Expand all panels')
    ensure_choice 'project_discussion_status_unmet'
    assert_match X, find('#discussion_enough')['src']

    ensure_choice 'project_english_status_met'
    assert_match CHECK, find('#english_enough')['src']

    ensure_choice 'project_contribution_status_met' # No URL given, so fails
    assert_match QUESTION, find('#contribution_enough')['src']

    ensure_choice 'project_contribution_requirements_status_unmet' # No URL
    # assert_match QUESTION, find('#contribution_requirements_enough')['src']

    # click_on 'Change Control'
    assert has_content? 'repo_public'
    ensure_choice 'project_repo_public_status_unmet'
    assert_match X, find('#repo_public_enough')['src']

    assert find('#project_repo_distributed_status_')['checked']
    ensure_choice 'project_repo_distributed_status_unmet' # SUGGESTED, so enough
    assert find('#project_repo_distributed_status_unmet')['checked']
    assert_match DASH, find('#repo_distributed_enough')['src']

    # click_on 'Reporting'
    assert has_content? 'report_process'
    ensure_choice 'project_report_process_status_unmet'
    assert_match X, find('#report_process_enough')['src']

    click_on('Submit', match: :first)
    assert_match X, find('#discussion_enough')['src']
  end<commit_msg>Insert wait_for_jquery commands in login_test<commit_after># frozen_string_literal: true
require 'capybara_feature_test'
include ActionView::Helpers::TextHelper

class LoginTest < CapybaraFeatureTest
  CHECK = /result_symbol_check/
  DASH = /result_symbol_dash/
  QUESTION = /result_symbol_question/
  X = /result_symbol_x/

  setup do
    FastlyRails.configure do |c|
      c.purging_enabled = true
    end
    @user = users(:test_user)
    @project = projects(:one)
  end

  teardown do
    FastlyRails.configure do |c|
      c.purging_enabled = false
    end
  end

  # rubocop:disable Metrics/BlockLength
  scenario 'Can Login and edit using custom account', js: true do
    visit projects_path
    click_on 'Login'
    fill_in 'Email', with: @user.email
    fill_in 'Password', with: 'password'
    click_button 'Log in using custom account'
    assert has_content? 'Signed in!'
    assert_equal current_path, projects_path
    # Check we are redirected back to root if we try to get login again
    visit login_path
    assert_equal current_path, root_path

    visit edit_project_path(@project)

    fill_in 'project_name', with: 'It doesnt matter'
    # Below we are clicking the final save button, it has a value of ''
    click_button('Save', exact: true)
    assert_equal current_path, edit_project_path(@project)
    assert has_content? 'Project was successfully updated.'
    # TODO: Get the clicking working again with capybara.
    # Details: If we expand all panels first and dont click this test passes.
    #          If we instead click each section, Capybara has issues not seen
    #          in real world scenarios, mainly it doesn't correctly identify
    #          an elements parents, leading to errors.
    kill_sticky_headers # This is necessary for Chrome and Firefox
    ensure_choice 'project_discussion_status_unmet'
    wait_for_jquery
    assert_match X, find('#discussion_enough')['src']

    ensure_choice 'project_english_status_met'
    wait_for_jquery
    assert_match CHECK, find('#english_enough')['src']

    ensure_choice 'project_contribution_status_met' # No URL given, so fails
    wait_for_jquery
    assert_match QUESTION, find('#contribution_enough')['src']

    ensure_choice 'project_contribution_requirements_status_unmet' # No URL
    wait_for_jquery
    assert_match QUESTION, find('#contribution_requirements_enough')['src']

    refute has_content? 'repo_public'
    find('#changecontrol').click
    wait_for_jquery
    assert has_content? 'repo_public'
    ensure_choice 'project_repo_public_status_unmet'
    wait_for_jquery
    assert_match X, find('#repo_public_enough')['src']

    assert find('#project_repo_distributed_status_')['checked']
    ensure_choice 'project_repo_distributed_status_unmet' # SUGGESTED, so enough
    wait_for_jquery
    assert find('#project_repo_distributed_status_unmet')['checked']
    assert_match DASH, find('#repo_distributed_enough')['src']

    refute has_content? 'report_process'
    find('#reporting').click
    wait_for_jquery
    assert has_content? 'report_process'
    ensure_choice 'project_report_process_status_unmet'
    wait_for_jquery
    assert_match X, find('#report_process_enough')['src']

    click_on('Submit', match: :first)
    wait_for_jquery
    assert_match X, find('#discussion_enough')['src']
  end
{'fraction_non_alphanumeric': 0.08186675047140163, 'fraction_numerical': 0.0, 'mean_word_length': 4.269039735099338, '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': '6584303', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1870, 'n_words': 523}