From 5a47caab33719ac5bdb0676c1a375b4975f71e7c Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Mon, 6 Sep 2021 17:43:29 +0200 Subject: [PATCH] Fixes #2931 - Pending reminder notifications are not sent if ticket is opened in tab --- .../app/controllers/ticket_zoom.coffee | 12 ++++ .../widget/online_notification.coffee | 6 +- .../ticket/resets_pending_time_seconds.rb | 3 +- spec/system/online_notification_spec.rb | 63 +++++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 spec/system/online_notification_spec.rb diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index 1f578c209..8a8f8d931 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -432,7 +432,19 @@ class App.TicketZoom extends App.Controller @scrollHeaderPos = scroll + pendingTimeReminderReached: => + App.TaskManager.touch(@taskKey) + + setPendingTimeReminderDelay: => + stateType = App.TicketStateType.find @ticket?.state?.state_type_id + return if stateType?.name != 'pending reminder' + + delay = new Date(@ticket.pending_time) - new Date() + + @delay @pendingTimeReminderReached, delay, 'pendingTimeReminderDelay' + render: (local) => + @setPendingTimeReminderDelay() # update taskbar with new meta data App.TaskManager.touch(@taskKey) diff --git a/app/assets/javascripts/app/controllers/widget/online_notification.coffee b/app/assets/javascripts/app/controllers/widget/online_notification.coffee index 154bf0e4c..d41337d8d 100644 --- a/app/assets/javascripts/app/controllers/widget/online_notification.coffee +++ b/app/assets/javascripts/app/controllers/widget/online_notification.coffee @@ -152,8 +152,12 @@ class App.OnlineNotificationWidget extends App.Controller ) fetch: => - load = => + load = (objects) => + for elem in objects + App.TaskManager.touch "#{elem.object}-#{elem.o_id}" + @fetchedData = true + App.OnlineNotification.fetchFull(load, clear: true, force: true) toggle: => diff --git a/app/models/ticket/resets_pending_time_seconds.rb b/app/models/ticket/resets_pending_time_seconds.rb index b4ac30616..e903ca7e9 100644 --- a/app/models/ticket/resets_pending_time_seconds.rb +++ b/app/models/ticket/resets_pending_time_seconds.rb @@ -5,8 +5,7 @@ module Ticket::ResetsPendingTimeSeconds extend ActiveSupport::Concern included do - before_create :ticket_reset_pending_time_seconds - before_update :ticket_reset_pending_time_seconds + before_save :ticket_reset_pending_time_seconds end private diff --git a/spec/system/online_notification_spec.rb b/spec/system/online_notification_spec.rb new file mode 100644 index 000000000..ca65801f6 --- /dev/null +++ b/spec/system/online_notification_spec.rb @@ -0,0 +1,63 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe 'Online notification', type: :system do + let(:session_user) { User.find_by(login: 'admin@example.com') } + + describe 'circle after pending reached' do + around do |example| + Ticket.without_callback :save, :before, :ticket_reset_pending_time_seconds do + example.run + end + end + + context 'when pending time is reached soon' do + before do + visit "ticket/zoom/#{ticket.id}" + end + + let(:ticket) { create(:ticket, owner: session_user, group: Group.first, state_name: 'pending reminder', pending_time: 4.seconds.from_now) } + + it 'loads as pending ticket' do + expect(page).to have_css('.icon.pending') + end + + it 'switches to open ticket' do + expect(page).to have_css('.icon.open') + end + + context 'when time is reached in non-active tab' do + before { visit 'dashboard' } + + it 'loads as pending ticket' do + expect(page).to have_css('.icon.pending') + end + + it 'switches to open ticket' do + expect(page).to have_css('.icon.open') + end + end + end + + context 'when pending time is set to reached soon to an open ticket' do + before do + ensure_websocket do + visit "ticket/zoom/#{ticket.id}" + end + + ticket.update! state: Ticket::State.lookup(name: 'pending reminder'), pending_time: 5.seconds.from_now + end + + let(:ticket) { create(:ticket, owner: session_user, group: Group.first) } + + it 'loads as pending ticket' do + expect(page).to have_css('.icon.pending') + end + + it 'switches to open ticket' do + expect(page).to have_css('.icon.open') + end + end + end +end