Send notifications for events that are not announced when window is out of focus.
This commit is contained in:
+50
-6
@@ -191,13 +191,21 @@ func TestUnlockWarningTimes(t *testing.T) {
|
||||
}
|
||||
|
||||
func latestHallInfo(messages []clientMessage) string {
|
||||
message, ok := latestHallInfoMessage(messages)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
text, _ := message.Value.(string)
|
||||
return text
|
||||
}
|
||||
|
||||
func latestHallInfoMessage(messages []clientMessage) (clientMessage, bool) {
|
||||
for i := len(messages) - 1; i >= 0; i-- {
|
||||
if messages[i].Type == "usermessage" && messages[i].Kind == "info" {
|
||||
message, _ := messages[i].Value.(string)
|
||||
return message
|
||||
return messages[i], true
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return clientMessage{}, false
|
||||
}
|
||||
|
||||
func scheduledUnlockEntry(g *hall.Hall) *scheduledHallUnlock {
|
||||
@@ -225,9 +233,28 @@ func TestScheduledUnlockRequiresIssuingOperator(t *testing.T) {
|
||||
if got := len(entry.timers); got != 4 {
|
||||
t.Fatalf("30-minute schedule has %d timers, want 4", got)
|
||||
}
|
||||
if got := latestHallInfo(drainMessages(participant)); !strings.Contains(got, "30 minutes") {
|
||||
scheduleMessage, ok := latestHallInfoMessage(drainMessages(participant))
|
||||
if !ok {
|
||||
t.Fatal("schedule announcement was not sent")
|
||||
}
|
||||
if got, _ := scheduleMessage.Value.(string); !strings.Contains(got, "30 minutes") {
|
||||
t.Fatalf("schedule announcement = %q", got)
|
||||
}
|
||||
if !scheduleMessage.Notify {
|
||||
t.Fatal("schedule announcement did not request a browser notification")
|
||||
}
|
||||
|
||||
announceScheduledUnlock(entry, 20*time.Minute)
|
||||
warningMessage, ok := latestHallInfoMessage(drainMessages(participant))
|
||||
if !ok {
|
||||
t.Fatal("countdown announcement was not sent")
|
||||
}
|
||||
if got, _ := warningMessage.Value.(string); got != "Hall will unlock in 20 minutes." {
|
||||
t.Fatalf("countdown announcement = %q", got)
|
||||
}
|
||||
if !warningMessage.Notify {
|
||||
t.Fatal("countdown announcement did not request a browser notification")
|
||||
}
|
||||
|
||||
hall.DelClient(operator)
|
||||
drainMessages(participant)
|
||||
@@ -257,9 +284,16 @@ func TestScheduledUnlockCompletesWhileIssuerIsOperator(t *testing.T) {
|
||||
if locked, _ := g.Locked(); locked {
|
||||
t.Fatal("hall remained locked while issuing operator was present")
|
||||
}
|
||||
if got := latestHallInfo(drainMessages(operator)); got != "Hall unlocked" {
|
||||
unlockMessage, ok := latestHallInfoMessage(drainMessages(operator))
|
||||
if !ok {
|
||||
t.Fatal("unlock announcement was not sent")
|
||||
}
|
||||
if got, _ := unlockMessage.Value.(string); got != "Hall unlocked" {
|
||||
t.Fatalf("unlock announcement = %q", got)
|
||||
}
|
||||
if !unlockMessage.Notify {
|
||||
t.Fatal("scheduled unlock completion did not request a browser notification")
|
||||
}
|
||||
}
|
||||
|
||||
func TestScheduledUnlockRequiresOperatorPermissionAtDeadline(t *testing.T) {
|
||||
@@ -386,9 +420,16 @@ func TestImmediateUnlockCommandCancelsScheduledUnlock(t *testing.T) {
|
||||
if locked, _ := g.Locked(); locked {
|
||||
t.Fatal("immediate unlock left hall locked")
|
||||
}
|
||||
if got := latestHallInfo(drainMessages(operator)); got != "Hall unlocked" {
|
||||
unlockMessage, ok := latestHallInfoMessage(drainMessages(operator))
|
||||
if !ok {
|
||||
t.Fatal("immediate unlock announcement was not sent")
|
||||
}
|
||||
if got, _ := unlockMessage.Value.(string); got != "Hall unlocked" {
|
||||
t.Fatalf("immediate unlock announcement = %q", got)
|
||||
}
|
||||
if unlockMessage.Notify {
|
||||
t.Fatal("immediate unlock requested a scheduled-unlock browser notification")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLockCommandCancelsScheduledUnlock(t *testing.T) {
|
||||
@@ -426,6 +467,9 @@ func TestLockCommandCancelsScheduledUnlock(t *testing.T) {
|
||||
for _, message := range messages {
|
||||
if message.Kind == "info" && strings.Contains(message.Value.(string), "locked again") {
|
||||
foundCancellation = true
|
||||
if !message.Notify {
|
||||
t.Fatal("scheduled-unlock cancellation did not request a browser notification")
|
||||
}
|
||||
}
|
||||
}
|
||||
if !foundCancellation {
|
||||
|
||||
Reference in New Issue
Block a user