Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(837) Populate scheduled_at date/time using model values #9836

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -8,11 +8,6 @@
<% end %>

<%
year_param = params.dig("scheduled_at", "scheduled_publication(1i)")
month_param = params.dig("scheduled_at", "scheduled_publication(2i)")
day_param = params.dig("scheduled_at", "scheduled_publication(3i)")
hour_param = params.dig("scheduled_at", "scheduled_publication(4i)")
minute_param = params.dig("scheduled_at", "scheduled_publication(5i)")
is_scheduled_param = params["schedule_publishing"]
%>

Original file line number Diff line number Diff line change
@@ -11,4 +11,24 @@ def initialize(content_block_edition:, params:, context:, back_link:, form_url:,
private

attr_reader :is_rescheduling, :content_block_edition, :params, :context, :back_link, :form_url

def year_param
content_block_edition.scheduled_publication&.year || params.dig("scheduled_at", "scheduled_publication(1i)")
end

def month_param
content_block_edition.scheduled_publication&.month || params.dig("scheduled_at", "scheduled_publication(2i)")
end

def day_param
content_block_edition.scheduled_publication&.day || params.dig("scheduled_at", "scheduled_publication(3i)")
end

def hour_param
content_block_edition.scheduled_publication&.hour || params.dig("scheduled_at", "scheduled_publication(4i)")
end

def minute_param
content_block_edition.scheduled_publication&.min || params.dig("scheduled_at", "scheduled_publication(5i)")
end
end
Original file line number Diff line number Diff line change
@@ -52,4 +52,45 @@ class ContentBlockManager::Shared::SchedulePublishingComponentTest < ViewCompone
)}']"
end
end

describe "when the content_block_edition already has a publish date set" do
let(:params) do
{
"scheduled_at" => {
"scheduled_publication(1i)" => "2022",
"scheduled_publication(2i)" => "2",
"scheduled_publication(3i)" => "3",
"scheduled_publication(4i)" => "1",
"scheduled_publication(5i)" => "2",
},
}
end

it "prepopulates the date fields" do
render_inline(component)

assert_selector "input[name='scheduled_at[scheduled_publication(1i)]'][value='#{params['scheduled_at']['scheduled_publication(1i)']}']"
assert_selector "input[name='scheduled_at[scheduled_publication(2i)]'][value='#{params['scheduled_at']['scheduled_publication(2i)']}']"
assert_selector "input[name='scheduled_at[scheduled_publication(3i)]'][value='#{params['scheduled_at']['scheduled_publication(3i)']}']"

assert_selector "select[name='scheduled_at[scheduled_publication(4i)]'] option[value='0#{params['scheduled_at']['scheduled_publication(4i)']}'][selected='selected']"
assert_selector "select[name='scheduled_at[scheduled_publication(5i)]'] option[value='0#{params['scheduled_at']['scheduled_publication(5i)']}'][selected='selected']"
end
end

describe "when the params have date attributes set" do
let(:scheduled_publication) { Time.zone.now + 1.month }
let(:content_block_edition) { create(:content_block_edition, :email_address, document: content_block_document, scheduled_publication:) }

it "prepopulates the date fields" do
render_inline(component)

assert_selector "input[name='scheduled_at[scheduled_publication(1i)]'][value='#{scheduled_publication.year}']"
assert_selector "input[name='scheduled_at[scheduled_publication(2i)]'][value='#{scheduled_publication.month}']"
assert_selector "input[name='scheduled_at[scheduled_publication(3i)]'][value='#{scheduled_publication.day}']"

assert_selector "select[name='scheduled_at[scheduled_publication(4i)]'] option[value='#{scheduled_publication.hour}'][selected='selected']"
assert_selector "select[name='scheduled_at[scheduled_publication(5i)]'] option[value='#{scheduled_publication.min}'][selected='selected']"
end
end
end