Skip to content

Commit

Permalink
Fix reply test and check sending job
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-rl committed Dec 6, 2023
1 parent 4ccb981 commit 8427cd3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
},
"[markdown]": {
"editor.defaultFormatter": null
},
"[ruby]": {
"editor.defaultFormatter": "Shopify.ruby-lsp"
}
}
4 changes: 2 additions & 2 deletions app/controllers/message_drafts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def update
authorize @message

permitted_params = message_params

@was_submittable = @message.submittable?
@message.update_content(title: permitted_params["message_title"], body: permitted_params["message_text"])
end

Expand Down Expand Up @@ -100,6 +100,6 @@ def load_message_draft
end

def message_params
params.permit(:message_title, :message_text)
params.permit(:message_title, :message_text, :format)
end
end
5 changes: 3 additions & 2 deletions app/javascript/controllers/message_drafts_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class extends Controller {
body: JSON.stringify({
authenticity_token: authenticityToken,
message_title: document.getElementById(messageDraftTitleId).value,
message_text: document.getElementById(messageDraftTextId).value
message_text: document.getElementById(messageDraftTextId).value,
format: "TURBO_STREAM"
})
})
}
Expand All @@ -31,7 +32,7 @@ export default class extends Controller {
const messageDraftsTexts = document.querySelectorAll('textarea[id^="text_message_draft_"]');
const length = messageDraftsTexts.length;
if (messageDraftsTexts.length > 1) {
messageDraftsTexts[length - 2].setAttribute('autofocus', false);
messageDraftsTexts[length - 2].setAttribute("autofocus", false);
}
messageDraftsTexts[length - 1].focus();

Expand Down
5 changes: 5 additions & 0 deletions app/views/message_drafts/update.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% if !@was_submittable && @message.submittable? %>
<%= turbo_stream.prepend dom_id(@message) do %>
<%= tag.turbo_frame id: dom_id(@message, :submittable) %>
<% end %>
<% end %>
4 changes: 4 additions & 0 deletions test/helpers/page_parts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ def within_message_in_thread(message)
yield
end
end

def unfocus_input
page.document.find("body").click
end
end
21 changes: 10 additions & 11 deletions test/system/message_threads_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,25 @@ class MessageThreadsTest < ApplicationSystemTestCase
end

test "a user can go to a thread detail and reply to message" do
visit message_threads_path

thread_issue = message_threads(:ssd_main_issue)
message_one = messages(:ssd_main_issue_one)
job_count_previous = GoodJob::Job.count

within_thread_in_listing(thread_issue) do
click_link
end
assert_not GoodJob::Job.where(job_class: 'Govbox::SubmitMessageDraftJob').order(scheduled_at: :desc).first

visit message_thread_path(thread_issue)
within_message_in_thread(message_one) do
find_button("Odpovedať").click
click_on("Odpovedať")
end

within '#new_drafts' do
find_field("Predmet").fill_in(with: "Testovaci predmet")
find_field("Text").fill_in(with: "Testovacie telo")
find_button("Odoslať").click
fill_in("Predmet", with: "Testovaci predmet")
fill_in("Text", with: "Testovacie telo")
unfocus_input
find("turbo-frame", id: /submittable/, visible: false)
click_button("Odoslať")
end

assert GoodJob::Job.count, job_count_previous + 1
GoodJob.perform_inline
assert GoodJob::Job.where(job_class: 'Govbox::SubmitMessageDraftJob').order(scheduled_at: :desc).first
end
end

0 comments on commit 8427cd3

Please sign in to comment.