1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Issues csv', :js, feature_category: :team_planning do
include FilteredSearchHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:milestone) { create(:milestone, title: 'v1.0', project: project) }
let(:idea_label) { create(:label, project: project, title: 'Idea') }
let(:feature_label) { create(:label, project: project, title: 'Feature', priority: 10) }
let!(:issue) { create(:issue, project: project, author: user) }
before do
sign_in(user)
visit project_issues_path(project)
end
def request_csv
click_button 'Actions'
click_button 'Export as CSV'
click_on 'Export issues'
end
def attachment
ActionMailer::Base.deliveries.last.attachments.first
end
def csv
CSV.parse(attachment.decode_body, headers: true)
end
it 'triggers an email export' do
expect(IssuableExportCsvWorker).to receive(:perform_async).with(:issue, user.id, project.id, hash_including("project_id" => project.id))
request_csv
end
it "doesn't send request params to ExportCsvWorker" do
expect(IssuableExportCsvWorker).to receive(:perform_async).with(:issue, anything, anything, hash_excluding("controller" => anything, "action" => anything))
request_csv
end
it 'displays flash message' do
request_csv
expect(page).to have_content 'CSV export has started'
expect(page).to have_content "emailed to #{user.notification_email_or_default}"
end
it 'includes a csv attachment', :sidekiq_inline do
request_csv
expect(attachment.content_type).to include('text/csv')
end
it 'ignores pagination', :sidekiq_inline do
create_list(:issue, 30, project: project, author: user)
request_csv
expect(csv.count).to eq 31
end
it 'uses filters from issue index', :sidekiq_inline do
click_link 'Closed'
request_csv
expect(csv.count).to eq 0
end
it 'ignores sorting from issue index', :sidekiq_inline do
issue2 = create(:labeled_issue, project: project, author: user, labels: [feature_label])
change_sort_by("Label priority")
request_csv
expected = [issue.iid.to_s, issue2.iid.to_s]
expect(csv.map { |row| row['Issue ID'] }).to eq expected
end
it 'uses array filters, such as label_name', :sidekiq_inline do
issue.update!(labels: [idea_label])
select_tokens 'Label', '||', feature_label.title, idea_label.title, submit: true
request_csv
expect(csv.count).to eq 1
end
context "with multiple issue authors" do
let(:user2) { create(:user, developer_of: project) }
let!(:issue2) { create(:issue, project: project, author: user2) }
it 'exports issues by selected author', :sidekiq_inline do
select_tokens 'Author', '=', user2.username, submit: true
request_csv
expect(csv.count).to eq 1
end
it 'exports issues by selected multiple authors', :sidekiq_inline do
select_tokens 'Author', '||', user2.username, user.username, submit: true
request_csv
expect(csv.count).to eq 2
end
it 'does not export issues by excluded multiple authors', :sidekiq_inline do
select_tokens 'Author', '!=', user.username, user2.username, submit: true
request_csv
expect(csv.count).to eq 0
end
end
end
|