Push notification styling improvements (#8818)

* Push notification styling improvements

* Fix unit tests
Этот коммит содержится в:
Elias Nahum
2018-05-30 13:11:19 -04:00
коммит произвёл Christopher Speller
родитель 2fe8878749
Коммит e39f5f46f3
3 изменённых файлов: 305 добавлений и 155 удалений

Просмотреть файл

@@ -1389,207 +1389,327 @@ func TestGetPushNotificationMessage(t *testing.T) {
for name, tc := range map[string]struct {
Message string
WasMentioned bool
explicitMention bool
channelWideMention bool
HasFiles bool
replyToThreadType string
Locale string
PushNotificationContents string
ChannelType string
ExpectedMessage string
ExpectedCategory string
ExpectedMessage string
}{
"full message, public channel, no mention": {
Message: "this is a message",
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, public channel, mention": {
Message: "this is a message",
WasMentioned: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
explicitMention: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, public channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, public channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, public channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user: this is a message",
},
"full message, private channel, no mention": {
Message: "this is a message",
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user: this is a message",
},
"full message, private channel, mention": {
Message: "this is a message",
WasMentioned: true,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
explicitMention: true,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user: this is a message",
},
"full message, private channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user: this is a message",
},
"full message, private channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user: this is a message",
},
"full message, group message channel, no mention": {
Message: "this is a message",
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user: this is a message",
},
"full message, group message channel, mention": {
Message: "this is a message",
WasMentioned: true,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user in channel: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
explicitMention: true,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user: this is a message",
},
"full message, group message channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user: this is a message",
},
"full message, group message channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user: this is a message",
},
"full message, direct message channel, no mention": {
Message: "this is a message",
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "this is a message",
},
"full message, direct message channel, mention": {
Message: "this is a message",
WasMentioned: true,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user: this is a message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
Message: "this is a message",
explicitMention: true,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "this is a message",
},
"full message, direct message channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "this is a message",
},
"full message, direct message channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "this is a message",
},
"generic message with channel, public channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user posted in channel",
ExpectedMessage: "@user posted a message.",
},
"generic message with channel, public channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user mentioned you in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "@user mentioned you.",
},
"generic message with channel, public channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user notified the channel.",
},
"generic message, public channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user commented on your post.",
},
"generic message, public channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user commented on a thread you participated in.",
},
"generic message with channel, private channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user posted in channel",
ExpectedMessage: "@user posted a message.",
},
"generic message with channel, private channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user mentioned you in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "@user mentioned you.",
},
"generic message with channel, private channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user notified the channel.",
},
"generic message, public private, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user commented on your post.",
},
"generic message, public private, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user commented on a thread you participated in.",
},
"generic message with channel, group message channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user posted in channel",
ExpectedMessage: "@user posted a message.",
},
"generic message with channel, group message channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user mentioned you in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "@user mentioned you.",
},
"generic message with channel, group message channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user notified the channel.",
},
"generic message, group message channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user commented on your post.",
},
"generic message, group message channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user commented on a thread you participated in.",
},
"generic message with channel, direct message channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "sent you a message.",
},
"generic message with channel, direct message channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "sent you a message.",
},
"generic message with channel, direct message channel, channel wide mention": {
Message: "this is a message",
channelWideMention: true,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "sent you a message.",
},
"generic message, direct message channel, commented on post": {
Message: "this is a message",
replyToThreadType: THREAD_ROOT,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "sent you a message.",
},
"generic message, direct message channel, commented on thread": {
Message: "this is a message",
replyToThreadType: THREAD_ANY,
PushNotificationContents: model.GENERIC_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "sent you a message.",
},
"generic message without channel, public channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user posted a message",
ExpectedMessage: "@user posted a message.",
},
"generic message without channel, public channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user mentioned you",
ExpectedMessage: "@user mentioned you.",
},
"generic message without channel, private channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user posted a message",
ExpectedMessage: "@user posted a message.",
},
"generic message without channel, private channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user mentioned you",
ExpectedMessage: "@user mentioned you.",
},
"generic message without channel, group message channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user posted a message",
ExpectedMessage: "@user posted a message.",
},
"generic message without channel, group message channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user mentioned you",
ExpectedMessage: "@user mentioned you.",
},
"generic message without channel, direct message channel, no mention": {
Message: "this is a message",
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "sent you a message.",
},
"generic message without channel, direct message channel, mention": {
Message: "this is a message",
WasMentioned: true,
explicitMention: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user sent you a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
ExpectedMessage: "sent you a message.",
},
"only files, public channel": {
HasFiles: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user uploaded one or more files in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
HasFiles: true,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "@user attached a file.",
},
"only files, private channel": {
HasFiles: true,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "user uploaded one or more files in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
HasFiles: true,
ChannelType: model.CHANNEL_PRIVATE,
ExpectedMessage: "@user attached a file.",
},
"only files, group message channel": {
HasFiles: true,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "user uploaded one or more files in channel",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
HasFiles: true,
ChannelType: model.CHANNEL_GROUP,
ExpectedMessage: "@user attached a file.",
},
"only files, direct message channel": {
HasFiles: true,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "user uploaded one or more files in a direct message",
ExpectedCategory: model.CATEGORY_CAN_REPLY,
HasFiles: true,
ChannelType: model.CHANNEL_DIRECT,
ExpectedMessage: "attached a file.",
},
"only files without channel, public channel": {
HasFiles: true,
PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION,
ChannelType: model.CHANNEL_OPEN,
ExpectedMessage: "user uploaded one or more files",
ExpectedMessage: "@user attached a file.",
},
} {
t.Run(name, func(t *testing.T) {
@@ -1607,18 +1727,18 @@ func TestGetPushNotificationMessage(t *testing.T) {
*cfg.EmailSettings.PushNotificationContents = pushNotificationContents
})
if actualMessage, actualCategory := th.App.getPushNotificationMessage(
if actualMessage := th.App.getPushNotificationMessage(
tc.Message,
tc.WasMentioned,
tc.explicitMention,
tc.channelWideMention,
tc.HasFiles,
"user",
"channel",
tc.ChannelType,
tc.replyToThreadType,
utils.GetUserTranslations(locale),
); actualMessage != tc.ExpectedMessage {
t.Fatalf("Received incorrect push notification message `%v`, expected `%v`", actualMessage, tc.ExpectedMessage)
} else if actualCategory != tc.ExpectedCategory {
t.Fatalf("Received incorrect push notification category `%v`, expected `%v`", actualCategory, tc.ExpectedCategory)
}
})
}