chore: Update notification Message Copy (#1685)

This commit is contained in:
Sojan Jose 2021-02-12 22:56:12 +05:30 committed by GitHub
parent 5defe648b5
commit 8d45849d0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 12 deletions

View file

@ -59,21 +59,26 @@ class Notification < ApplicationRecord
end end
# TODO: move to a data presenter # TODO: move to a data presenter
# rubocop:disable Metrics/CyclomaticComplexity
def push_message_title def push_message_title
if notification_type == 'conversation_creation' case notification_type
return "A new conversation [ID -#{primary_actor.display_id}] has been created in #{primary_actor.inbox.name}" when 'conversation_creation'
I18n.t('notifications.notification_title.conversation_creation', display_id: primary_actor.display_id, inbox_name: primary_actor.inbox.name)
when 'conversation_assignment'
I18n.t('notifications.notification_title.conversation_assignment', display_id: primary_actor.display_id)
when 'assigned_conversation_new_message'
I18n.t(
'notifications.notification_title.assigned_conversation_new_message',
display_id: primary_actor.display_id,
content: primary_actor&.messages&.incoming&.last&.content
)
when 'conversation_mention'
I18n.t('notifications.notification_title.conversation_mention', display_id: primary_actor.conversation.display_id, name: secondary_actor.name)
else
''
end end
return "A new conversation [ID -#{primary_actor.display_id}] has been assigned to you." if notification_type == 'conversation_assignment'
return "New message in your assigned conversation [ID -#{primary_actor.display_id}]." if notification_type == 'assigned_conversation_new_message'
if notification_type == 'conversation_mention'
return "You have been mentioned in conversation [ID -#{primary_actor.conversation.display_id}] by #{secondary_actor.name}"
end
''
end end
# rubocop:enable Metrics/CyclomaticComplexity
private private

View file

@ -45,6 +45,12 @@ en:
reports: reports:
period: Reporting period %{since} to %{until} period: Reporting period %{since} to %{until}
notifications:
notification_title:
conversation_creation: "[New conversation] - #%{display_id} has been created in %{inbox_name}"
conversation_assignment: "[Assigned to you] - #%{display_id} has been assigned to you"
assigned_conversation_new_message: "[New message] - #%{display_id} %{content}"
conversation_mention: "You have been mentioned in conversation [ID - %{display_id}] by %{name}"
conversations: conversations:
messages: messages:
deleted: This message was deleted deleted: This message was deleted

View file

@ -18,4 +18,33 @@ RSpec.describe Notification do
expect(described_class.all.last).to eq notification1 expect(described_class.all.last).to eq notification1
end end
end end
context 'when push_title is called' do
it 'returns appropriate title suited for the notification type conversation_creation' do
notification = create(:notification, notification_type: 'conversation_creation')
expect(notification.push_message_title).to eq "[New conversation] - ##{notification.primary_actor.display_id} has\
been created in #{notification.primary_actor.inbox.name}"
end
it 'returns appropriate title suited for the notification type conversation_assignment' do
notification = create(:notification, notification_type: 'conversation_assignment')
expect(notification.push_message_title).to eq "[Assigned to you] - ##{notification.primary_actor.display_id} has been assigned to you"
end
it 'returns appropriate title suited for the notification type assigned_conversation_new_message' do
notification = create(:notification, notification_type: 'assigned_conversation_new_message')
expect(notification.push_message_title).to eq "[New message] - ##{notification.primary_actor.display_id} "
end
it 'returns appropriate title suited for the notification type conversation_mention' do
message = create(:message, sender: create(:user))
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message, secondary_actor: message.sender)
expect(notification.push_message_title).to eq "You have been mentioned in conversation [ID - #{message.conversation.display_id}] \
by #{message.sender.name}"
end
end
end end