Skip to content

Commit

Permalink
Formatting improvements (#273)
Browse files Browse the repository at this point in the history
* Formatting improvements

* fix tests
  • Loading branch information
CubicrootXYZ authored Jun 5, 2024
1 parent 54c9282 commit ac3dd7f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
10 changes: 6 additions & 4 deletions internal/connectors/matrix/actions/message/list_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ func TestListEventsAction_HandleEvent(t *testing.T) {
)).Return(nil, nil)

msngr.EXPECT().SendMessage(&messenger.Message{
Body: `JANUARY
Body: `
JANUARY
➡️ TEST EVENT
at 08:04 02.01.2006 (UTC) (ID: 2824)
`,
BodyHTML: `<b>January</b><br>
BodyHTML: `<br><b>January</b><br>
➡️ <b>test event</b><br>at 08:04 02.01.2006 (UTC) (ID: 2824) <br>`,
ChannelExternalIdentifier: "!room123",
}).Return(&messenger.MessageResponse{
Expand All @@ -88,11 +89,12 @@ at 08:04 02.01.2006 (UTC) (ID: 2824)
matrixDB.EXPECT().NewMessage(&matrixdb.MatrixMessage{
ID: "!234",
UserID: toP("@user:example.com"),
Body: `JANUARY
Body: `
JANUARY
➡️ TEST EVENT
at 08:04 02.01.2006 (UTC) (ID: 2824)
`,
BodyFormatted: `<b>January</b><br>
BodyFormatted: `<br><b>January</b><br>
➡️ <b>test event</b><br>at 08:04 02.01.2006 (UTC) (ID: 2824) <br>`,
Type: matrixdb.MessageTypeEventList,
RoomID: 0,
Expand Down
3 changes: 2 additions & 1 deletion internal/connectors/matrix/format/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ func InfoFromEvents(events []database.Event, timeZone string) (string, string) {
for i := range events {
newHeader := headerFromEvent(&events[i], loc)
if newHeader != currentHeader {
str.WriteString("\n")
str.WriteString(strings.ToUpper(newHeader))
str.WriteString("\n")
strFormatted.WriteString("<b>")
strFormatted.WriteString("<br><b>")
strFormatted.WriteString(newHeader)
strFormatted.WriteString("</b><br>\n")
currentHeader = newHeader
Expand Down
4 changes: 2 additions & 2 deletions internal/connectors/matrix/format/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ func TestInfoFromEvents(t *testing.T) {

assert.Equal(
t,
"NOVEMBER\n➡️ MY EVENT 3\nat 11:43 12.11.2014 (UTC) (ID: 1) \n➡️ MY EVENT 1\nat 11:45 12.11.2014 (UTC) (ID: 1) \n➡️ MY EVENT 2\nat 11:47 12.11.2014 (UTC) (ID: 1) \n",
"\nNOVEMBER\n➡️ MY EVENT 3\nat 11:43 12.11.2014 (UTC) (ID: 1) \n➡️ MY EVENT 1\nat 11:45 12.11.2014 (UTC) (ID: 1) \n➡️ MY EVENT 2\nat 11:47 12.11.2014 (UTC) (ID: 1) \n",
msg,
)
assert.Equal(
t,
"<b>November</b><br>\n➡️ <b>my event 3</b><br>at 11:43 12.11.2014 (UTC) (ID: 1) <br>➡️ <b>my event 1</b><br>at 11:45 12.11.2014 (UTC) (ID: 1) <br>➡️ <b>my event 2</b><br>at 11:47 12.11.2014 (UTC) (ID: 1) <br>",
"<br><b>November</b><br>\n➡️ <b>my event 3</b><br>at 11:43 12.11.2014 (UTC) (ID: 1) <br>➡️ <b>my event 1</b><br>at 11:45 12.11.2014 (UTC) (ID: 1) <br>➡️ <b>my event 2</b><br>at 11:47 12.11.2014 (UTC) (ID: 1) <br>",
msgF,
)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/connectors/matrix/send_reminders.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (service *service) SendDailyReminder(reminder *daemon.DailyReminder, output

msg, msgFormatted := format.InfoFromDaemonEvents(reminder.Events, room.TimeZone)
msg = "Your Events for Today\n\n" + msg
msgFormatted = "<h2>Your Events for Today</h2>\n" + msgFormatted
msgFormatted = "<h2>Your Events for Today</h2><br>\n" + msgFormatted

resp, err := service.messenger.SendMessage(messenger.HTMLMessage(
msg,
Expand Down
6 changes: 3 additions & 3 deletions internal/connectors/matrix/send_reminders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestService_SendDailyReminder(t *testing.T) {
➡️ TEST EVENT
at 11:45 12.11.2014 (UTC) (ID: 56)
`,
`<h2>Your Events for Today</h2>
`<h2>Your Events for Today</h2><br>
➡️ <b>test event</b><br>at 11:45 12.11.2014 (UTC) (ID: 56) <br>`,
"!1234",
)).Return(
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestService_SendDailyReminderWithNewMessageError(t *testing.T) {
➡️ TEST EVENT
at 11:45 12.11.2014 (UTC) (ID: 56)
`,
`<h2>Your Events for Today</h2>
`<h2>Your Events for Today</h2><br>
➡️ <b>test event</b><br>at 11:45 12.11.2014 (UTC) (ID: 56) <br>`,
"!1234",
)).Return(
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestService_SendDailyReminderWithSendMessageError(t *testing.T) {
➡️ TEST EVENT
at 11:45 12.11.2014 (UTC) (ID: 56)
`,
`<h2>Your Events for Today</h2>
`<h2>Your Events for Today</h2><br>
➡️ <b>test event</b><br>at 11:45 12.11.2014 (UTC) (ID: 56) <br>`,
"!1234",
)).Return(
Expand Down

0 comments on commit ac3dd7f

Please sign in to comment.