Skip to content

Commit

Permalink
Fixed last tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Mar 31, 2023
1 parent 518f21a commit 3e0057e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
13 changes: 11 additions & 2 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def new
end

def create
# TODO: We need to process files submitted by the user in this method.
# We currently do not and therefore there are not saved to the work.
# See https://github.com/pulibrary/pdc_describe/issues/1041
@work = Work.new(created_by_user_id: current_user.id, collection_id: params_collection_id, user_entered_doi: params["doi"].present?)
@work.resource = FormToResourceService.convert(params, @work)
if @work.valid?
Expand Down Expand Up @@ -81,8 +84,14 @@ def show
end

def file_list
@work = Work.find(params[:id])
render json: @work.uploads
if params[:id] == "NONE"
# This is a special case when we render the file list for a work being created
# (i.e. it does not have an id just yet)
render json: []
else
@work = Work.find(params[:id])
render json: @work.uploads
end
end

def resolve_doi
Expand Down
2 changes: 1 addition & 1 deletion app/views/works/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<h2 class="h2"><%= t('works.uploads.post_curation.heading') %></h2>
<%= render(partial: 'works/s3_resources', locals: { edit_mode: false }) %>
</section>
<% elsif @work.id.present? %>
<% else %>
<section class="uploads">
<h2 class="h2"><%= t('works.uploads.post_curation.heading') %></h2>
<%= render(partial: 'works/s3_resources', locals: { edit_mode: true, form: form }) %>
Expand Down
5 changes: 2 additions & 3 deletions app/views/works/_s3_resources.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@

<script type="text/javascript">
$(function() {
// This is needed so that we can swap the URL during testing
// (for more info see external_identifier_specs.rb)
var fileListUrl = '<%= work_file_list_path(@work) %>';
// work.id is nil when the form is rendered during work creation and the work has not been saved
var fileListUrl = '<%= work_file_list_path(@work.id || "NONE") %>';
var isEditMode = <%= edit_mode %>;

// Wire DataTable for the file list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
select "Research Data", from: "collection_id"
fill_in "doi", with: doi
fill_in "ark", with: ark
page.attach_file("work[pre_curation_uploads][]", [file_upload], make_visible: true)
page.attach_file("work[pre_curation_uploads_added][]", [file_upload], make_visible: true)
click_on "Create"
expect(page).to have_content "marked as Draft"
expect(page).to have_content "Creative Commons Attribution 4.0 International"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
fill_in "family_name_7", with: "Ramsay"
fill_in "description", with: description
select "Creative Commons Attribution 4.0 International", from: "rights_identifier"
page.attach_file("work[pre_curation_uploads][]", [file1, file2], make_visible: true)
# TODO: We should also test that the files are saved
# See https://github.com/pulibrary/pdc_describe/issues/1041
page.attach_file("work[pre_curation_uploads_added][]", [file1, file2], make_visible: true)
click_on "Additional Metadata"
click_on "Curator Controlled"
fill_in "ark", with: ark
Expand Down
11 changes: 8 additions & 3 deletions spec/system/work_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@

it "allows users to delete one of the uploads" do
allow(ActiveStorage::PurgeJob).to receive(:new).and_call_original
allow(fake_s3_service).to receive(:client_s3_files).and_return([contents1, contents2], [contents2])

expect(page).to have_content "Filename"
expect(page).to have_content "Last Modified"
expect(page).to have_content "Size"
expect(page).to have_content("us_covid_2019.csv")
expect(page).to have_content("us_covid_2020.csv")

click_on "delete-file-#{work.doi}/#{work.id}/us_covid_2019.csv"
allow(fake_s3_service).to receive(:client_s3_files).and_return(s3_hash_after_delete)
click_on "Save Work"

expect(fake_s3_service).to have_received(:delete_s3_object)
within(".files.card-body") do
expect(page).to have_content("us_covid_2020.csv")
expect(page).not_to have_content("us_covid_2019.csv")
end
expect(fake_s3_service).to have_received(:delete_s3_object)
end

it "allows users to replace one of the uploads" do
Expand Down Expand Up @@ -267,7 +270,9 @@
expect(collection_tags_element["readonly"]).to eq("true")

expect(page.all("input[type=text][readonly]").count).to eq(page.all("input[type=text]").count) # all inputs on curator controlled metadata should be readonly
expect(page.all("select[disabled]").count).to eq(page.all("select").count) # all selects inputs on curator controlled metadata should be disabled

# The +1 in here is to account for the control for file list page size that DataTables adds to the file list
expect(page.all("select[disabled]").count + 1).to eq(page.all("select").count) # all selects inputs on curator controlled metadata should be disabled
end
end
end

0 comments on commit 3e0057e

Please sign in to comment.