2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'Issues csv', :js, feature_category: :team_planning do
|
2020-04-22 19:07:51 +05:30
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
|
|
|
def request_csv(params = {})
|
|
|
|
visit project_issues_path(project, params)
|
2023-07-09 08:55:56 +05:30
|
|
|
click_button 'Actions'
|
2021-09-04 01:27:46 +05:30
|
|
|
click_button 'Export as CSV'
|
2020-04-22 19:07:51 +05:30
|
|
|
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
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(IssuableExportCsvWorker).to receive(:perform_async).with(:issue, user.id, project.id, hash_including("project_id" => project.id))
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
request_csv
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't send request params to ExportCsvWorker" do
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(IssuableExportCsvWorker).to receive(:perform_async).with(:issue, anything, anything, hash_excluding("controller" => anything, "action" => anything))
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
request_csv
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays flash message' do
|
|
|
|
request_csv
|
|
|
|
|
|
|
|
expect(page).to have_content 'CSV export has started'
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(page).to have_content "emailed to #{user.notification_email_or_default}"
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it 'includes a csv attachment', :sidekiq_inline do
|
2020-04-22 19:07:51 +05:30
|
|
|
request_csv
|
|
|
|
|
|
|
|
expect(attachment.content_type).to include('text/csv')
|
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it 'ignores pagination', :sidekiq_inline do
|
2020-04-22 19:07:51 +05:30
|
|
|
create_list(:issue, 30, project: project, author: user)
|
|
|
|
|
|
|
|
request_csv
|
|
|
|
|
|
|
|
expect(csv.count).to eq 31
|
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it 'uses filters from issue index', :sidekiq_inline do
|
2020-04-22 19:07:51 +05:30
|
|
|
request_csv(state: :closed)
|
|
|
|
|
|
|
|
expect(csv.count).to eq 0
|
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it 'ignores sorting from issue index', :sidekiq_inline do
|
2020-04-22 19:07:51 +05:30
|
|
|
issue2 = create(:labeled_issue, project: project, author: user, labels: [feature_label])
|
|
|
|
|
|
|
|
request_csv(sort: :label_priority)
|
|
|
|
|
|
|
|
expected = [issue.iid.to_s, issue2.iid.to_s]
|
|
|
|
expect(csv.map { |row| row['Issue ID'] }).to eq expected
|
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it 'uses array filters, such as label_name', :sidekiq_inline do
|
2020-04-22 19:07:51 +05:30
|
|
|
issue.update!(labels: [idea_label])
|
|
|
|
|
|
|
|
request_csv("label_name[]" => 'Bug')
|
|
|
|
|
|
|
|
expect(csv.count).to eq 0
|
|
|
|
end
|
|
|
|
end
|