Skip to content

Commit

Permalink
Adding Save, Next and Previois buttons to the wizard form
Browse files Browse the repository at this point in the history
  • Loading branch information
carolyncole committed Apr 2, 2024
1 parent 1f4e14e commit 838fabf
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 11 deletions.
11 changes: 11 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ th {
background-color: #666666ff;
}

.actions .btn-previous {
background-color: #666666ff;
color: white;
margin-right: 0.5em;
}

.actions .btn-save {
margin-right: 0.5em;
border-color: black;
}

.actions .btn-primary {
background-color: #467dd1ff;
margin-right: 0.5em;
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/works_wizard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class WorksWizardController < ApplicationController
# get Renders the "step 0" information page before creating a new dataset
# GET /works/new_submission
def new_submission
group = Group.find_by(code: params[:group_code]) || current_user.default_group
group_id = group.id
@work = Work.new(created_by_user_id: current_user.id, group_id:)
@work = WorkMetadataService.new(params:, current_user:).work_for_new_submission
prepare_decorators_for_work_form(@work)
end

Expand Down
14 changes: 12 additions & 2 deletions app/services/work_metadata_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ def initialize(params:, current_user:)
@current_user = current_user
end

# generates or load the work for a new submission based on the parameters
#
# creates or finds the work for the new submission form based on the parameters
#
# @returns the new or updated work
def work_for_new_submission
if params[:id].present?
Work.find(params[:id])
else
group = Group.find_by(code: params[:group_code]) || current_user.default_group
Work.new(created_by_user_id: current_user.id, group_id: group.id)
end
end

# generates or load the work for a new submission based on the parameters
#
# @returns the new or updated work
def new_submission
if params[:id].present?
update_work
Expand Down
9 changes: 4 additions & 5 deletions app/views/works_wizard/_form_wizard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
<hr />
<div class="actions">
<%= link_to 'Cancel', @work, class: "btn btn-secondary" %>
<% if @work.persisted? %>
<%= form.submit "Save Work", class: "btn btn-primary wizard-next-button", id: "btn-submit" %>
<% else %>
<%= form.submit "Create", class: "btn btn-primary wizard-next-button", id: "btn-submit", name: "submit" %>
<% end %>
<%= form.submit "Next", class: "btn btn-primary wizard-next-button", id: "btn-submit" %>
<%= form.button 'Save', type: 'submit', name: 'save_only', value: 'true', class: "btn btn-save wizard-next-button" %>
<%= link_to 'Previous', work_new_submission_path(@work), class: "btn btn-previous wizard-next-button" %>
</div>

<%= render '/works/form_hidden_fields' %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/works_wizard/readme_select.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<div class="actions">
<%= link_to t('works.form.readme_upload.go_back'), edit_work_wizard_path(@work), class: "btn btn-secondary" %>
<%= f.submit(t('works.form.readme_upload.continue'), class: "btn btn-primary wizard-next-button", id: 'readme-upload', disabled: @readme.blank?) %>
<%= f.button 'Save', type: 'submit', name: 'save_only', value: 'true', class: "btn btn-save wizard-next-button" %>
<%= link_to 'Previous', edit_work_wizard_path(@work), class: "btn btn-previous wizard-next-button" %>
</div>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
get "how-to-submit", to: "welcome#how_to_submit", as: :welcome_how_to_submit

# The work wizard
get "works/new-submission", to: "works_wizard#new_submission", as: :work_create_new_submission
get "works/new-submission/(:id)", to: "works_wizard#new_submission", as: :work_create_new_submission
post "works/new-submission/(:id)", to: "works_wizard#new_submission_save", as: :work_new_submission
patch "works/new-submission/:id", to: "works_wizard#new_submission_save"
get "works/:id/readme-select", to: "works_wizard#readme_select", as: :work_readme_select
Expand Down
58 changes: 58 additions & 0 deletions spec/system/work_wizard_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true
require "rails_helper"

describe "walk the wizard hitting all the buttons", type: :system, js: true do
let(:user) { FactoryBot.create :princeton_submitter }
it "allows me to stay on each page and then move forward" do
sign_in user

visit work_create_new_submission_path
expect(page).to have_css("form[action='/works/new-submission']")
fill_in "title_main", with: "title"
click_on "Add me as a Creator"
expect(find("tr:last-child input[name='creators[][given_name]']").value).to eq(user.given_name)
expect(find("tr:last-child input[name='creators[][family_name]']").value).to eq(user.family_name)
click_on "Save"

work = Work.last
new_submission_form_css = "form[action='/works/new-submission/#{work.id}']"
edit_form_css = "form[action='/works/#{work.id}/update-wizard']"
readme_form_css = "form[action='/works/#{work.id}/readme-uploaded']"
upload_form_css = "form[action='/works/#{work.id}/attachment-select']"

expect(page).to have_css(new_submission_form_css)
click_on "Next"

expect(page).to have_css(edit_form_css)

click_on "Previous"
expect(page).to have_css(new_submission_form_css)

click_on "Next"
expect(page).to have_css(edit_form_css)

fill_in "description", with: "description"

expect{ click_on "Save" }.to change { work.work_activity.count}.by(1)
expect(page).to have_css(edit_form_css)

click_on "Next"
expect(page).to have_css(readme_form_css)
expect(page).not_to have_content("previously uploaded")

click_on "Previous"
expect(page).to have_css(edit_form_css)

click_on "Next"
expect(page).to have_css(readme_form_css)

stub_s3 data: [FactoryBot.build(:s3_readme, work:)]
click_on "Save"
expect(page).to have_css(readme_form_css)
expect(page).to have_content("previously uploaded")

click_on "Next"
expect(page).to have_css(upload_form_css)

end
end

0 comments on commit 838fabf

Please sign in to comment.