notification.go 833 B

12345678910111213141516171819202122232425262728293031
  1. package test
  2. import (
  3. "testing"
  4. "fyne.io/fyne/v2"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. )
  8. // AssertNotificationSent allows an app developer to assert that a notification was sent.
  9. // After the content of f has executed this utility will check that the specified notification was sent.
  10. func AssertNotificationSent(t *testing.T, n *fyne.Notification, f func()) {
  11. require.NotNil(t, f, "function has to be specified")
  12. require.IsType(t, &testApp{}, fyne.CurrentApp())
  13. a := fyne.CurrentApp().(*testApp)
  14. a.lastNotification = nil
  15. f()
  16. if n == nil {
  17. assert.Nil(t, a.lastNotification)
  18. return
  19. } else if a.lastNotification == nil {
  20. t.Error("No notification sent")
  21. return
  22. }
  23. assert.Equal(t, n.Title, a.lastNotification.Title)
  24. assert.Equal(t, n.Content, a.lastNotification.Content)
  25. }