From fb32746c81c2c67a27908c77bbeb4832b77460ca Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 15 Sep 2020 16:15:51 +0300 Subject: [PATCH 1/6] add notice when matching is completed --- app/assets/javascripts/channels/projects.coffee | 4 ++++ app/channels/projects_channel.rb | 11 +++++++++++ app/jobs/match_appearance_releases_job.rb | 12 +++++++++++- app/views/application/_flash.html.erb | 5 ++--- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ .../user_managing_appearance_releases_spec.rb | 16 ++++++++++++++++ spec/jobs/match_appearance_releases_job_spec.rb | 7 +++++++ 8 files changed, 55 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/channels/projects.coffee b/app/assets/javascripts/channels/projects.coffee index 8f6dad1..9840f32 100644 --- a/app/assets/javascripts/channels/projects.coffee +++ b/app/assets/javascripts/channels/projects.coffee @@ -17,6 +17,7 @@ $(document).on "turbolinks:load", -> when "video_status_update" then @showVideoStatusUpdate(data.content) when "download_status_update" then @showDownloadStatusUpdate(data.content) when "conference_recording_ready" then @showDownloadStatusUpdate(data.content) + when "appearance_matching_flash_message" then @showMatchingStatusUpdate(data.content) showVideoStatusUpdate: (content) -> $("[data-ujs-target='video-analysis-msg']").replaceWith content @@ -24,3 +25,6 @@ $(document).on "turbolinks:load", -> showDownloadStatusUpdate: (content) -> $(".flash-message").html content $(".toast").toast('show') + + showMatchingStatusUpdate: (content) -> + $("#flash-message").replaceWith content diff --git a/app/channels/projects_channel.rb b/app/channels/projects_channel.rb index 68ee885..bc5b9c1 100644 --- a/app/channels/projects_channel.rb +++ b/app/channels/projects_channel.rb @@ -33,4 +33,15 @@ class ProjectsChannel < ApplicationCable::Channel content = ApplicationController.render partial: 'application/flash', locals: { flash: flash } broadcast_to project, event: :conference_recording_ready, content: content end + + def self.appearance_matching_flash_message(project, message, flash_type = :notice) + if (flash_type == :notice) + flash = OpenStruct.new notice: message + else + flash = OpenStruct.new alert: message + end + content = ApplicationController.render partial: 'application/flash', locals: { flash: flash } + + broadcast_to project, event: :appearance_matching_flash_message, content: content + end end diff --git a/app/jobs/match_appearance_releases_job.rb b/app/jobs/match_appearance_releases_job.rb index 66c7ee0..87c5b26 100644 --- a/app/jobs/match_appearance_releases_job.rb +++ b/app/jobs/match_appearance_releases_job.rb @@ -6,7 +6,11 @@ class MatchAppearanceReleasesJob < ApplicationJob def perform(project, attachments) filtered_attachments_object = filter_attachments attachments - return if filtered_attachments_object[:keys].blank? + if filtered_attachments_object[:keys].blank? + notification = I18n.t 'appearance_releases.create.matching_failed' + ProjectsChannel.appearance_matching_flash_message project, notification, :alert + return + end matching_request = MatchingRequest.create project: project, attachments: filtered_attachments_object[:signed_ids] @@ -17,6 +21,8 @@ class MatchAppearanceReleasesJob < ApplicationJob handle_matches matches, project, key_signed_id_hash handle_unmatches matches, project, key_signed_id_hash matching_request.destroy + + ProjectsChannel.appearance_matching_flash_message project, success_message end private @@ -113,4 +119,8 @@ class MatchAppearanceReleasesJob < ApplicationJob signed_ids: filtered_attachments_signed_ids } end + + def success_message + I18n.t 'appearance_releases.create.matching_completed' + end end diff --git a/app/views/application/_flash.html.erb b/app/views/application/_flash.html.erb index afba291..5eb926c 100644 --- a/app/views/application/_flash.html.erb +++ b/app/views/application/_flash.html.erb @@ -3,14 +3,14 @@
<% if flash.alert.present? %> -
+

<%= flash.alert.html_safe %>

<% elsif flash.notice.present? %> -
+

<%= flash.notice.html_safe %>

@@ -19,4 +19,3 @@ <% end %>
- diff --git a/config/locales/en.yml b/config/locales/en.yml index d390728..7f3654b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -151,6 +151,8 @@ en: failed_import: Failed to create appearance release for files listed below matching_started: Matching started no_attachments: Failed to import - no attachments + matching_completed: Matching completed. Reload page to see new releases + matching_failed: Matching failed edit: heading: Edit Appearance Release form: diff --git a/config/locales/es.yml b/config/locales/es.yml index 78f4ccc..6bb9e2b 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -58,6 +58,8 @@ es: failed_import: Failed to create appearance release for files listed below (ES) matching_started: Matching started (ES) no_attachments: Failed to import - no attachments (ES) + matching_completed: Matching completed (ES) + matching_failed: Matching failed (ES) form: guardian_2_info: heading: Second Guardian Information (if company requires) (ES) diff --git a/spec/features/user_managing_appearance_releases_spec.rb b/spec/features/user_managing_appearance_releases_spec.rb index ee71aae..34fd25f 100644 --- a/spec/features/user_managing_appearance_releases_spec.rb +++ b/spec/features/user_managing_appearance_releases_spec.rb @@ -324,6 +324,18 @@ feature 'User managing appearance releases' do expect(page).to have_content no_appearance_releases end + scenario 'Message is shown when matching job is completed', js: true do + visit project_appearance_releases_path(project) + + attach_file import_appearance_release_field, Rails.root.join(file_fixture('person_photo.png')), visible: false + allow(MatchAppearanceReleasesJob).to receive(:perform_later).with(project, anything) + click_button submit_create_button + expect(page).to have_content matching_started + expect(page).to have_content no_appearance_releases + expect(page).not_to have_content matching_started + expect(page).to have_content matching_completed + end + scenario 'user leaving the page is presented with the warning if file upload is in progress', js: true do skip "Test is inconsistently failing in CI" @@ -847,6 +859,10 @@ feature 'User managing appearance releases' do t 'appearance_releases.create.matching_started' end + def matching_completed + t 'appearance_releases.create.matching_completed' + end + def filter_type_all t 'appearance_releases.type_filter_actions.all_releases' end diff --git a/spec/jobs/match_appearance_releases_job_spec.rb b/spec/jobs/match_appearance_releases_job_spec.rb index 84ba636..659c15e 100644 --- a/spec/jobs/match_appearance_releases_job_spec.rb +++ b/spec/jobs/match_appearance_releases_job_spec.rb @@ -10,6 +10,11 @@ describe MatchAppearanceReleasesJob do end describe ".perform_now" do + # before do + # allow(ProjectsChannel).to receive(:appearance_matching_flash_message).with(be_kind_of(Project), I18n.t("appearance_releases.create.matching_completed")) + # end + + it "returns if no attachment is sent" do expect(MatchingRequest).not_to receive(:create) attachments = [] @@ -50,6 +55,8 @@ describe MatchAppearanceReleasesJob do expect(AppearanceRelease.last.contract).not_to be_attached expect(AppearanceRelease.last.person_photo).to be_attached + + # expect(ProjectsChannel).to receive(:appearance_matching_flash_message) end it "creates a new incomplete appearance release for contracts which cannot be matched by BrayniacAI" do -- 2.47.3 From 8f83943ac2c13f01143530c0bd7a0938086f31d1 Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 15 Sep 2020 16:17:58 +0300 Subject: [PATCH 2/6] update --- app/jobs/match_appearance_releases_job.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/jobs/match_appearance_releases_job.rb b/app/jobs/match_appearance_releases_job.rb index 87c5b26..381b60e 100644 --- a/app/jobs/match_appearance_releases_job.rb +++ b/app/jobs/match_appearance_releases_job.rb @@ -7,8 +7,7 @@ class MatchAppearanceReleasesJob < ApplicationJob filtered_attachments_object = filter_attachments attachments if filtered_attachments_object[:keys].blank? - notification = I18n.t 'appearance_releases.create.matching_failed' - ProjectsChannel.appearance_matching_flash_message project, notification, :alert + ProjectsChannel.appearance_matching_flash_message project, failed_message, :alert return end @@ -123,4 +122,8 @@ class MatchAppearanceReleasesJob < ApplicationJob def success_message I18n.t 'appearance_releases.create.matching_completed' end + + def failed_message + I18n.t 'appearance_releases.create.matching_failed' + end end -- 2.47.3 From 9ce7d97c51c5becc485f9f7c7a25773c878def7b Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 15 Sep 2020 16:25:38 +0300 Subject: [PATCH 3/6] update specs --- .../match_appearance_releases_job_spec.rb | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/spec/jobs/match_appearance_releases_job_spec.rb b/spec/jobs/match_appearance_releases_job_spec.rb index 659c15e..6795c1b 100644 --- a/spec/jobs/match_appearance_releases_job_spec.rb +++ b/spec/jobs/match_appearance_releases_job_spec.rb @@ -10,14 +10,10 @@ describe MatchAppearanceReleasesJob do end describe ".perform_now" do - # before do - # allow(ProjectsChannel).to receive(:appearance_matching_flash_message).with(be_kind_of(Project), I18n.t("appearance_releases.create.matching_completed")) - # end - - it "returns if no attachment is sent" do expect(MatchingRequest).not_to receive(:create) attachments = [] + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), failure_flash_message, :alert) MatchAppearanceReleasesJob.perform_now project, attachments end @@ -25,6 +21,7 @@ describe MatchAppearanceReleasesJob do expect(MatchingRequest).not_to receive(:create) dummy_video = create(:video) attachments = [dummy_video.file.blob.signed_id] + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), failure_flash_message, :alert) MatchAppearanceReleasesJob.perform_now project, attachments end @@ -49,14 +46,14 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + expect { MatchAppearanceReleasesJob.perform_now project, signed_ids }.to change{AppearanceRelease.count}.by(1) expect(AppearanceRelease.last.contract).not_to be_attached expect(AppearanceRelease.last.person_photo).to be_attached - - # expect(ProjectsChannel).to receive(:appearance_matching_flash_message) end it "creates a new incomplete appearance release for contracts which cannot be matched by BrayniacAI" do @@ -80,6 +77,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + expect { MatchAppearanceReleasesJob.perform_now project, signed_ids }.to change{AppearanceRelease.count}.by(1) @@ -116,6 +115,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + MatchAppearanceReleasesJob.perform_now project, signed_ids expect(AppearanceRelease.last.identifier).to eq mock_match.identifier @@ -151,6 +152,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + expect { MatchAppearanceReleasesJob.perform_now project, signed_ids }.to change{AppearanceRelease.count}.by(2) @@ -194,6 +197,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + MatchAppearanceReleasesJob.perform_now project, signed_ids expect(AppearanceRelease.last.identifier).to eq mock_match.identifier @@ -235,6 +240,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + MatchAppearanceReleasesJob.perform_now project, signed_ids expect(AppearanceRelease.last.identifier).to eq mock_match.identifier @@ -282,6 +289,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + MatchAppearanceReleasesJob.perform_now project, signed_ids releases = AppearanceRelease.last(2) @@ -295,4 +304,14 @@ describe MatchAppearanceReleasesJob do expect(releases[1].contract.attached?).to eq true end end + + private + + def success_flash_message + I18n.t 'appearance_releases.create.matching_completed' + end + + def failure_flash_message + I18n.t 'appearance_releases.create.matching_failed' + end end -- 2.47.3 From 43e996299a117b48b2d082158ffa7a9a032bfd4c Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 15 Sep 2020 16:38:16 +0300 Subject: [PATCH 4/6] update specs --- .../user_managing_appearance_releases_spec.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/spec/features/user_managing_appearance_releases_spec.rb b/spec/features/user_managing_appearance_releases_spec.rb index 34fd25f..b795411 100644 --- a/spec/features/user_managing_appearance_releases_spec.rb +++ b/spec/features/user_managing_appearance_releases_spec.rb @@ -324,18 +324,6 @@ feature 'User managing appearance releases' do expect(page).to have_content no_appearance_releases end - scenario 'Message is shown when matching job is completed', js: true do - visit project_appearance_releases_path(project) - - attach_file import_appearance_release_field, Rails.root.join(file_fixture('person_photo.png')), visible: false - allow(MatchAppearanceReleasesJob).to receive(:perform_later).with(project, anything) - click_button submit_create_button - expect(page).to have_content matching_started - expect(page).to have_content no_appearance_releases - expect(page).not_to have_content matching_started - expect(page).to have_content matching_completed - end - scenario 'user leaving the page is presented with the warning if file upload is in progress', js: true do skip "Test is inconsistently failing in CI" -- 2.47.3 From afbde109d24e8d19684a3078fcf115e16364d054 Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 15 Sep 2020 16:38:59 +0300 Subject: [PATCH 5/6] update specs --- spec/features/user_managing_appearance_releases_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/features/user_managing_appearance_releases_spec.rb b/spec/features/user_managing_appearance_releases_spec.rb index b795411..ee71aae 100644 --- a/spec/features/user_managing_appearance_releases_spec.rb +++ b/spec/features/user_managing_appearance_releases_spec.rb @@ -847,10 +847,6 @@ feature 'User managing appearance releases' do t 'appearance_releases.create.matching_started' end - def matching_completed - t 'appearance_releases.create.matching_completed' - end - def filter_type_all t 'appearance_releases.type_filter_actions.all_releases' end -- 2.47.3 From a4204e2fa3c7609c42bbdb17a259ff14d407bbf2 Mon Sep 17 00:00:00 2001 From: Bilal Date: Wed, 16 Sep 2020 12:01:47 +0300 Subject: [PATCH 6/6] fix after rebase --- app/assets/javascripts/channels/projects.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/channels/projects.coffee b/app/assets/javascripts/channels/projects.coffee index 9840f32..bf2d375 100644 --- a/app/assets/javascripts/channels/projects.coffee +++ b/app/assets/javascripts/channels/projects.coffee @@ -27,4 +27,5 @@ $(document).on "turbolinks:load", -> $(".toast").toast('show') showMatchingStatusUpdate: (content) -> - $("#flash-message").replaceWith content + $(".flash-message").html content + $(".toast").toast('show') -- 2.47.3