<commit_before>require 'rails_helper'

describe 'Resolve an open discussion in a merge request by creating an issue', :js do
  let(:user) { create(:user) }
  let(:project) { create(:project, :repository, only_allow_merge_if_all_discussions_are_resolved: true) }
  let(:merge_request) { create(:merge_request, source_project: project) }
  let!(:discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }

  def resolve_discussion_selector
    title = 'Resolve this thread in a new issue'
    url = new_project_issue_path(project, discussion_to_resolve: discussion.id, merge_request_to_resolve_discussions_of: merge_request.iid)
    "a[data-original-title=\"#{title}\"][href=\"#{url}\"]"
  end

  describe 'As a user with access to the project' do
    before do
      project.add_maintainer(user)
      sign_in user
      visit project_merge_request_path(project, merge_request)
    end

    context 'with the internal tracker disabled' do
      before do
        project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)
        visit project_merge_request_path(project, merge_request)
      end

      it 'does not show a link to create a new issue' do
        expect(page).not_to have_css resolve_discussion_selector
      end
    end

    context 'resolving the discussion' do
      before do
        click_button 'Resolve thread'
      end

      it 'hides the link for creating a new issue' do
        expect(page).not_to have_css resolve_discussion_selector
      end

      it 'shows the link for creating a new issue when unresolving a discussion' do
        page.within '.diff-content' do
          click_button 'Unresolve thread'
        end

        expect(page).to have_css resolve_discussion_selector
      end
    end

    it 'has a link to create a new issue for a discussion' do
      expect(page).to have_css resolve_discussion_selector
    end

    context 'creating the issue' do
      before do
        find(resolve_discussion_selector).click
      end

      it 'has a hidden field for the discussion' do
        discussion_field = find('#discussion_to_resolve', visible: false)

        expect(discussion_field.value).to eq(discussion.id.to_s)
      end

      it_behaves_like 'creating an issue for a discussion'
    end
  end

  describe 'as a reporter' do
    before do
      project.add_reporter(user)
      sign_in user
      visit new_project_issue_path(project, merge_request_to_resolve_discussions_of: merge_request.iid,
                                            discussion_to_resolve: discussion.id)
    end

    it 'Shows a notice to ask someone else to resolve the discussions' do
      expect(page).to have_content("The discussion at #{merge_request.to_reference}"\
                                   " (discussion #{discussion.first_note.id}) will stay unresolved."\
                                   " Ask someone with permission to resolve it.")
    end
  end
end<commit_msg>updated test<commit_after>require 'rails_helper'

describe 'Resolve an open thread in a merge request by creating an issue', :js do
  let(:user) { create(:user) }
  let(:project) { create(:project, :repository, only_allow_merge_if_all_discussions_are_resolved: true) }
  let(:merge_request) { create(:merge_request, source_project: project) }
  let!(:discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }

  def resolve_discussion_selector
    title = 'Resolve this thread in a new issue'
    url = new_project_issue_path(project, discussion_to_resolve: discussion.id, merge_request_to_resolve_discussions_of: merge_request.iid)
    "a[data-original-title=\"#{title}\"][href=\"#{url}\"]"
  end

  describe 'As a user with access to the project' do
    before do
      project.add_maintainer(user)
      sign_in user
      visit project_merge_request_path(project, merge_request)
    end

    context 'with the internal tracker disabled' do
      before do
        project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)
        visit project_merge_request_path(project, merge_request)
      end

      it 'does not show a link to create a new issue' do
        expect(page).not_to have_css resolve_discussion_selector
      end
    end

    context 'resolving the thread' do
      before do
        click_button 'Resolve thread'
      end

      it 'hides the link for creating a new issue' do
        expect(page).not_to have_css resolve_discussion_selector
      end

      it 'shows the link for creating a new issue when unresolving a thread' do
        page.within '.diff-content' do
          click_button 'Unresolve thread'
        end

        expect(page).to have_css resolve_discussion_selector
      end
    end

    it 'has a link to create a new issue for a thread' do
      expect(page).to have_css resolve_discussion_selector
    end

    context 'creating the issue' do
      before do
        find(resolve_discussion_selector).click
      end

      it 'has a hidden field for the thread' do
        discussion_field = find('#discussion_to_resolve', visible: false)

        expect(discussion_field.value).to eq(discussion.id.to_s)
      end

      it_behaves_like 'creating an issue for a thread'
    end
  end

  describe 'as a reporter' do
    before do
      project.add_reporter(user)
      sign_in user
      visit new_project_issue_path(project, merge_request_to_resolve_discussions_of: merge_request.iid,
                                            discussion_to_resolve: discussion.id)
    end

    it 'Shows a notice to ask someone else to resolve the threads' do
      expect(page).to have_content("The thread at #{merge_request.to_reference}"\
                                   " (discussion #{discussion.first_note.id}) will stay unresolved."\
                                   " Ask someone with permission to resolve it.")
    end
  end
end
{'fraction_non_alphanumeric': 0.0694980694980695, 'fraction_numerical': 0.0, 'mean_word_length': 2.9352708058124173, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7153952', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1629, 'n_words': 510}