<commit_before>require 'application_system_test_case'

class FeedbacksTest < ApplicationSystemTestCase
  def setup
    @volunteer = create :volunteer_with_user
    @volunteer.user.update(email: '<EMAIL>')
    @volunteer.contact.update(primary_email: '<EMAIL>')
    @user_volunteer = @volunteer.user
    @assignment = create :assignment, volunteer: @volunteer, period_start: 7.weeks.ago
    @superadmin = create :user
    @other_volunteer = create :volunteer_with_user
    @group_offer = create :group_offer, necessary_volunteers: 2, title: 'some_group_offer',
      volunteers: [@volunteer, @other_volunteer]
  end

  def setup_feedbacks
    @assignment_volunteer_feedback = create :feedback, volunteer: @volunteer,
      author: @user_volunteer, feedbackable: @assignment,
      comments: 'author_volunteer_assignment_feedback'
    create :feedback, feedbackable: @assignment,
      volunteer: @volunteer, author: @superadmin, comments: 'author_superadmin_assignment_feedback'
    create :feedback, feedbackable: @group_offer, author: @user_volunteer,
      volunteer: @volunteer, comments: 'author_volunteer_group_offer_feedback'
    create :feedback, feedbackable: @group_offer, author: @superadmin, volunteer: @volunteer,
      comments: 'author_superadmin_group_offer_feedback'
    create :feedback, volunteer: @other_volunteer, feedbackable: @group_offer,
      author: @superadmin, comments: 'author_other_volunteer_group_offer_feedback'
  end

  test 'volunteer can see assignment feedbacks index' do
    setup_feedbacks
    login_as @user_volunteer
    visit root_url
    click_link @user_volunteer.full_name
    click_link 'Profil anzeigen'
    within '.assignments-table' do
      click_link 'Feedback index', href: polymorphic_path([@volunteer, @assignment, Feedback])
    end
    refute page.has_text? 'author_superadmin_assignment_feedback'
    assert page.has_text? 'author_volunteer_assignment_feedback'
  end

  test 'volunteer can see group offer feedbacks index' do
    setup_feedbacks
    login_as @user_volunteer
    visit root_url
    click_link @user_volunteer.full_name
    click_link 'Profil anzeigen'
    within '.group-assignments-table' do
      click_link 'Feedback index', href: polymorphic_path([@volunteer, @group_offer, Feedback])
    end
    refute page.has_text? 'author_superadmin_group_offer_feedback'
    assert page.has_text? 'author_volunteer_group_offer_feedback'
  end

  test 'assignment feedback index contains only the feedbacks of one assignment' do
    setup_feedbacks
    login_as @user_volunteer
    visit polymorphic_path([@volunteer, @assignment, @assignment_volunteer_feedback])
    click_link 'Back'
    within '.assignments-table' do
      click_link 'Feedback index', href: polymorphic_path([@volunteer, @assignment, Feedback])
    end
    refute page.has_text? 'author_superadmin_assignment_feedback'
    assert page.has_text? 'author_volunteer_assignment_feedback'
  end

  test 'group offer feedbacks index contains only the feedbacks related to that group offer' do
    setup_feedbacks
    other_group_offer = create :group_offer, title: 'some_other_group_offer',
      volunteers: [@volunteer, @other_volunteer], necessary_volunteers: 2
    create :feedback, volunteer: @volunteer, feedbackable: other_group_offer,<commit_msg>fix feedbacks test<commit_after>require 'application_system_test_case'

class FeedbacksTest < ApplicationSystemTestCase
  def setup
    @volunteer = create :volunteer_with_user
    @volunteer.user.update(email: '<EMAIL>')
    @volunteer.contact.update(primary_email: '<EMAIL>')
    @user_volunteer = @volunteer.user
    @assignment = create :assignment, volunteer: @volunteer, period_start: 7.weeks.ago
    @superadmin = create :user
    @other_volunteer = create :volunteer_with_user
    @group_offer = create :group_offer, necessary_volunteers: 2, title: 'some_group_offer',
      volunteers: [@volunteer, @other_volunteer]
  end

  def setup_feedbacks
    @assignment_volunteer_feedback = create :feedback, volunteer: @volunteer,
      author: @user_volunteer, feedbackable: @assignment,
      comments: 'author_volunteer_assignment_feedback'
    create :feedback, feedbackable: @assignment,
      volunteer: @volunteer, author: @superadmin, comments: 'author_superadmin_assignment_feedback'
    create :feedback, feedbackable: @group_offer, author: @user_volunteer,
      volunteer: @volunteer, comments: 'author_volunteer_group_offer_feedback'
    create :feedback, feedbackable: @group_offer, author: @superadmin, volunteer: @volunteer,
      comments: 'author_superadmin_group_offer_feedback'
    create :feedback, volunteer: @other_volunteer, feedbackable: @group_offer,
      author: @superadmin, comments: 'author_other_volunteer_group_offer_feedback'
  end

  test 'volunteer can see assignment feedbacks index' do
    setup_feedbacks
    login_as @user_volunteer
    visit root_url
    click_link @user_volunteer.full_name
    click_link 'Profil anzeigen'
    within '.assignments-table' do
      click_link 'Feedback index', href: polymorphic_path([@volunteer, @assignment, Feedback])
    end
    refute page.has_text? 'author_superadmin_assignment_feedback'
    assert page.has_text? 'author_volunteer_assignment_feedback'
  end

  test 'volunteer can see group offer feedbacks index' do
    setup_feedbacks
    login_as @user_volunteer
    visit root_url
    click_link @user_volunteer.full_name
    click_link 'Profil anzeigen'
    within '.group-assignments-table' do
      click_link 'Feedback index', href: polymorphic_path([@volunteer, @group_offer, Feedback])
    end
    refute page.has_text? 'author_superadmin_group_offer_feedback'
    assert page.has_text? 'author_volunteer_group_offer_feedback'
  end

  test 'assignment_feedback_index_contains_only_the_feedbacks_of_one_assignment' do
    setup_feedbacks
    login_as @user_volunteer
    visit volunteer_path(@user_volunteer.volunteer)
    within '.assignments-table' do
      click_link 'Feedback index', href: polymorphic_path([@volunteer, @assignment, Feedback])
    end
    refute page.has_text? 'author_superadmin_assignment_feedback'
    assert page.has_text? 'author_volunteer_assignment_feedback'
  end

  test 'group offer feedbacks index contains only the feedbacks related to that group offer' do
    setup_feedbacks
    other_group_offer = create :group_offer, title: 'some_other_group_offer',
      volunteers: [@volunteer, @other_volunteer], necessary_volunteers: 2
    create :feedback, volunteer: @volunteer, feedbackable: other_group_offer,
{'fraction_non_alphanumeric': 0.07928231866278178, 'fraction_numerical': 0.0009201042784848949, 'mean_word_length': 5.229226361031519, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '2204347', 'n_tokens_mistral': 2138, 'n_tokens_neox': 2032, 'n_words': 464}