diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2018-05-09 23:08:34 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-05-09 23:08:34 +0000 |
commit | f5c8bfeacb3eeaeb07899328a580e390107b69a7 (patch) | |
tree | 14d1d4c309601209e4736d99f040f3fead3e2711 /spec | |
parent | f4c36fac60e56ec3e50bb08581b5fababa05c693 (diff) | |
download | gitlab-ce-f5c8bfeacb3eeaeb07899328a580e390107b69a7.tar.gz |
Replace the `project/issues/references.feature` spinach test with an rspec analog
Diffstat (limited to 'spec')
3 files changed, 267 insertions, 193 deletions
diff --git a/spec/features/issuables/markdown_references/internal_references_spec.rb b/spec/features/issuables/markdown_references/internal_references_spec.rb new file mode 100644 index 00000000000..8af4b157cd8 --- /dev/null +++ b/spec/features/issuables/markdown_references/internal_references_spec.rb @@ -0,0 +1,80 @@ +require "rails_helper" + +describe "Internal references", :js do + include Spec::Support::Helpers::Features::NotesHelpers + + let(:private_project_user) { private_project.owner } + let(:private_project) { create(:project, :private, :repository) } + let(:private_project_issue) { create(:issue, project: private_project) } + let(:private_project_merge_request) { create(:merge_request, source_project: private_project) } + let(:public_project_user) { public_project.owner } + let(:public_project) { create(:project, :public, :repository) } + let(:public_project_issue) { create(:issue, project: public_project) } + + context "when referencing to open issue" do + context "from private project" do + context "from issue" do + before do + sign_in(private_project_user) + + visit(project_issue_path(private_project, private_project_issue)) + + add_note("##{public_project_issue.to_reference(private_project)}") + end + + context "when user doesn't have access to private project" do + before do + sign_in(public_project_user) + + visit(project_issue_path(public_project, public_project_issue)) + end + + it { expect(page).not_to have_css(".note") } + end + end + + context "from merge request" do + before do + sign_in(private_project_user) + + visit(project_merge_request_path(private_project, private_project_merge_request)) + + add_note("##{public_project_issue.to_reference(private_project)}") + end + + context "when user doesn't have access to private project" do + before do + sign_in(public_project_user) + + visit(project_issue_path(public_project, public_project_issue)) + end + + it "doesn't show any references" do + page.within(".issue-details") do + expect(page).not_to have_content("#merge-requests .merge-requests-title") + end + end + end + + context "when user has access to private project" do + before do + visit(project_issue_path(public_project, public_project_issue)) + end + + it "shows references" do + page.within("#merge-requests .merge-requests-title") do + expect(page).to have_content("1 Related Merge Request") + end + + page.within("#merge-requests ul") do + expect(page).to have_content(private_project_merge_request.title) + end + + expect(page).to have_content("mentioned in merge request #{private_project_merge_request.to_reference(public_project)}") + .and have_content(private_project_user.name) + end + end + end + end + end +end diff --git a/spec/features/issuables/markdown_references/jira_spec.rb b/spec/features/issuables/markdown_references/jira_spec.rb new file mode 100644 index 00000000000..fa0ab88624e --- /dev/null +++ b/spec/features/issuables/markdown_references/jira_spec.rb @@ -0,0 +1,187 @@ +require "rails_helper" + +describe "Jira", :js do + let(:user) { create(:user) } + let(:actual_project) { create(:project, :public, :repository) } + let(:merge_request) { create(:merge_request, target_project: actual_project, source_project: actual_project) } + let(:issue_actual_project) { create(:issue, project: actual_project) } + let!(:other_project) { create(:project, :public) } + let!(:issue_other_project) { create(:issue, project: other_project) } + let(:issues) { [issue_actual_project, issue_other_project] } + + shared_examples "correct references" do + before do + remotelink = double(:remotelink, all: [], build: double(save!: true)) + + stub_request(:get, "https://jira.example.com/rest/api/2/issue/JIRA-5") + stub_request(:post, "https://jira.example.com/rest/api/2/issue/JIRA-5/comment") + allow_any_instance_of(JIRA::Resource::Issue).to receive(:remotelink).and_return(remotelink) + + sign_in(user) + + visit(merge_request_path(merge_request)) + + build_note + end + + it "creates a link to the referenced issue on the preview" do + find(".js-md-preview-button").click + + wait_for_requests + + page.within(".md-preview-holder") do + links_expectations + end + end + + it "creates a link to the referenced issue after submit" do + click_button("Comment") + + wait_for_requests + + page.within("#diff-notes-app") do + links_expectations + end + end + + it "creates a note on the referenced issues" do + click_button("Comment") + + wait_for_requests + + if referenced_issues.include?(issue_actual_project) + visit(issue_path(issue_actual_project)) + + page.within("#notes") do + expect(page).to have_content("#{user.to_reference} mentioned in merge request #{merge_request.to_reference}") + end + end + + if referenced_issues.include?(issue_other_project) + visit(issue_path(issue_other_project)) + + page.within("#notes") do + expect(page).to have_content("#{user.to_reference} mentioned in merge request #{merge_request.to_reference(other_project)}") + end + end + end + end + + context "when internal issues tracker is enabled for the other project" do + context "when only internal issues tracker is enabled for the actual project" do + include_examples "correct references" do + let(:referenced_issues) { [issue_actual_project, issue_other_project] } + let(:jira_referenced) { false } + end + end + + context "when both external and internal issues trackers are enabled for the actual project" do + before do + create(:jira_service, project: actual_project) + end + + include_examples "correct references" do + let(:referenced_issues) { [issue_actual_project, issue_other_project] } + let(:jira_referenced) { true } + end + end + + context "when only external issues tracker is enabled for the actual project" do + let(:actual_project) { create(:project, :public, :repository, :issues_disabled) } + + before do + create(:jira_service, project: actual_project) + end + + include_examples "correct references" do + let(:referenced_issues) { [issue_other_project] } + let(:jira_referenced) { true } + end + end + + context "when no tracker is enabled for the actual project" do + let(:actual_project) { create(:project, :public, :repository, :issues_disabled) } + + include_examples 'correct references' do + let(:referenced_issues) { [issue_other_project] } + let(:jira_referenced) { false } + end + end + end + + context "when internal issues tracker is disabled for the other project" do + let(:other_project) { create(:project, :public, :repository, :issues_disabled) } + + context "when only internal issues tracker is enabled for the actual project" do + include_examples "correct references" do + let(:referenced_issues) { [issue_actual_project] } + let(:jira_referenced) { false } + end + end + + context "when both external and internal issues trackers are enabled for the actual project" do + before do + create(:jira_service, project: actual_project) + end + + include_examples "correct references" do + let(:referenced_issues) { [issue_actual_project] } + let(:jira_referenced) { true } + end + end + + context "when only external issues tracker is enabled for the actual project" do + let(:actual_project) { create(:project, :public, :repository, :issues_disabled) } + + before do + create(:jira_service, project: actual_project) + end + + include_examples "correct references" do + let(:referenced_issues) { [] } + let(:jira_referenced) { true } + end + end + + context "when no issues tracker is enabled for the actual project" do + let(:actual_project) { create(:project, :public, :repository, :issues_disabled) } + + include_examples "correct references" do + let(:referenced_issues) { [] } + let(:jira_referenced) { false } + end + end + end + + private + + def build_note + markdown = <<~HEREDOC + Referencing internal issue #{issue_actual_project.to_reference}, + cross-project #{issue_other_project.to_reference(actual_project)} external JIRA-5 + and non existing #999 + HEREDOC + + page.within("#diff-notes-app") do + fill_in("note_note", with: markdown) + end + end + + def links_expectations + issues.each do |issue| + if referenced_issues.include?(issue) + expect(page).to have_link(issue.to_reference, href: issue_path(issue)) + else + expect(page).not_to have_link(issue.to_reference, href: issue_path(issue)) + end + end + + if jira_referenced + expect(page).to have_link("JIRA-5", href: "https://jira.example.com/browse/JIRA-5") + else + expect(page).not_to have_link("JIRA-5", href: "https://jira.example.com/browse/JIRA-5") + end + + expect(page).not_to have_link("#999") + end +end diff --git a/spec/features/issuables/markdown_references_spec.rb b/spec/features/issuables/markdown_references_spec.rb deleted file mode 100644 index dd4e10a9886..00000000000 --- a/spec/features/issuables/markdown_references_spec.rb +++ /dev/null @@ -1,193 +0,0 @@ -require 'rails_helper' - -describe 'Markdown References', :js do - let(:user) { create(:user) } - let(:actual_project) { create(:project, :public, :repository) } - let(:merge_request) { create(:merge_request, target_project: actual_project, source_project: actual_project)} - let(:issue_actual_project) { create(:issue, project: actual_project) } - let!(:other_project) { create(:project, :public) } - let!(:issue_other_project) { create(:issue, project: other_project) } - let(:issues) { [issue_actual_project, issue_other_project] } - - def build_note - markdown = "Referencing internal issue #{issue_actual_project.to_reference}, " + - "cross-project #{issue_other_project.to_reference(actual_project)} external JIRA-5 " + - "and non existing #999" - - page.within('#diff-notes-app') do - fill_in 'note_note', with: markdown - end - end - - shared_examples 'correct references' do - before do - remotelink = double(:remotelink, all: [], build: double(save!: true)) - - stub_request(:get, "https://jira.example.com/rest/api/2/issue/JIRA-5") - stub_request(:post, "https://jira.example.com/rest/api/2/issue/JIRA-5/comment") - allow_any_instance_of(JIRA::Resource::Issue).to receive(:remotelink).and_return(remotelink) - - sign_in(user) - visit merge_request_path(merge_request) - build_note - end - - def links_expectations - issues.each do |issue| - if referenced_issues.include?(issue) - expect(page).to have_link(issue.to_reference, href: issue_path(issue)) - else - expect(page).not_to have_link(issue.to_reference, href: issue_path(issue)) - end - end - - if jira_referenced - expect(page).to have_link('JIRA-5', href: 'https://jira.example.com/browse/JIRA-5') - else - expect(page).not_to have_link('JIRA-5', href: 'https://jira.example.com/browse/JIRA-5') - end - - expect(page).not_to have_link('#999') - end - - it 'creates a link to the referenced issue on the preview' do - find('.js-md-preview-button').click - wait_for_requests - - page.within('.md-preview-holder') do - links_expectations - end - end - - it 'creates a link to the referenced issue after submit' do - click_button 'Comment' - wait_for_requests - - page.within('#diff-notes-app') do - links_expectations - end - end - - it 'creates a note on the referenced issues' do - click_button 'Comment' - wait_for_requests - - if referenced_issues.include?(issue_actual_project) - visit issue_path(issue_actual_project) - - page.within('#notes') do - expect(page).to have_content( - "#{user.to_reference} mentioned in merge request #{merge_request.to_reference}" - ) - end - end - - if referenced_issues.include?(issue_other_project) - visit issue_path(issue_other_project) - - page.within('#notes') do - expect(page).to have_content( - "#{user.to_reference} mentioned in merge request #{merge_request.to_reference(other_project)}" - ) - end - end - end - end - - context 'when internal issues tracker is enabled for the other project' do - context 'when only internal issues tracker is enabled for the actual project' do - include_examples 'correct references' do - let(:referenced_issues) { [issue_actual_project, issue_other_project] } - let(:jira_referenced) { false } - end - end - - context 'when both external and internal issues trackers are enabled for the actual project' do - before do - create(:jira_service, project: actual_project) - end - - include_examples 'correct references' do - let(:referenced_issues) { [issue_actual_project, issue_other_project] } - let(:jira_referenced) { true } - end - end - - context 'when only external issues tracker is enabled for the actual project' do - before do - create(:jira_service, project: actual_project) - - actual_project.issues_enabled = false - actual_project.save! - end - - include_examples 'correct references' do - let(:referenced_issues) { [issue_other_project] } - let(:jira_referenced) { true } - end - end - - context 'when no tracker is enabled for the actual project' do - before do - actual_project.issues_enabled = false - actual_project.save! - end - - include_examples 'correct references' do - let(:referenced_issues) { [issue_other_project] } - let(:jira_referenced) { false } - end - end - end - - context 'when internal issues tracker is disabled for the other project' do - before do - other_project.issues_enabled = false - other_project.save! - end - - context 'when only internal issues tracker is enabled for the actual project' do - include_examples 'correct references' do - let(:referenced_issues) { [issue_actual_project] } - let(:jira_referenced) { false } - end - end - - context 'when both external and internal issues trackers are enabled for the actual project' do - before do - create(:jira_service, project: actual_project) - end - - include_examples 'correct references' do - let(:referenced_issues) { [issue_actual_project] } - let(:jira_referenced) { true } - end - end - - context 'when only external issues tracker is enabled for the actual project' do - before do - create(:jira_service, project: actual_project) - - actual_project.issues_enabled = false - actual_project.save! - end - - include_examples 'correct references' do - let(:referenced_issues) { [] } - let(:jira_referenced) { true } - end - end - - context 'when no issues tracker is enabled for the actual project' do - before do - actual_project.issues_enabled = false - actual_project.save! - end - - include_examples 'correct references' do - let(:referenced_issues) { [] } - let(:jira_referenced) { false } - end - end - end -end |