-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathUserFeedbackUiTest.kt
More file actions
695 lines (603 loc) · 27.7 KB
/
UserFeedbackUiTest.kt
File metadata and controls
695 lines (603 loc) · 27.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
package io.sentry.uitest.android
import android.graphics.Color
import android.util.TypedValue
import android.view.View
import android.widget.EditText
import android.widget.LinearLayout
import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.BoundedMatcher
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withHint
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.sentry.Sentry
import io.sentry.SentryEvent
import io.sentry.SentryFeedbackOptions.SentryFeedbackCallback
import io.sentry.SentryOptions
import io.sentry.android.core.AndroidLogger
import io.sentry.android.core.R
import io.sentry.android.core.SentryUserFeedbackButton
import io.sentry.android.core.SentryUserFeedbackDialog
import io.sentry.assertEnvelopeFeedback
import io.sentry.protocol.User
import io.sentry.test.getProperty
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.junit.runner.RunWith
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
@RunWith(AndroidJUnit4::class)
class UserFeedbackUiTest : BaseUiTest() {
@Test
fun userFeedbackNotShownWhenSdkDisabled() {
launchActivity<EmptyActivity>().onActivity {
SentryUserFeedbackDialog.Builder(it).create().show()
}
onView(withId(R.id.sentry_dialog_user_feedback_title))
.check(doesNotExist())
}
@Test
fun userFeedbackTextCustomizations() {
initSentry {
it.feedbackOptions.formTitle = "Test Form Title"
it.feedbackOptions.submitButtonLabel = "Test Send Bug Report"
it.feedbackOptions.cancelButtonLabel = "Test Cancel"
it.feedbackOptions.nameLabel = "Test Name"
it.feedbackOptions.namePlaceholder = "Test Your Name"
it.feedbackOptions.emailLabel = "Test Email"
it.feedbackOptions.emailPlaceholder = "Test your.email@example.org"
it.feedbackOptions.messageLabel = "Test Description"
it.feedbackOptions.messagePlaceholder = "Test What's the bug? What did you expect?"
it.feedbackOptions.successMessageText = "Test Thank you for your report!"
it.feedbackOptions.isRequiredLabel = " Test (Required)"
}
showDialogAndCheck {
onView(withId(R.id.sentry_dialog_user_feedback_title))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Test Form Title")))
onView(withId(R.id.sentry_dialog_user_feedback_btn_send))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Test Send Bug Report")))
onView(withId(R.id.sentry_dialog_user_feedback_btn_cancel))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Test Cancel")))
onView(withId(R.id.sentry_dialog_user_feedback_txt_name))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Test Name")))
onView(withId(R.id.sentry_dialog_user_feedback_edt_name))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(
matches(
allOf(
withHint("Test Your Name"),
withText("")
)
)
)
onView(withId(R.id.sentry_dialog_user_feedback_txt_email))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Test Email")))
onView(withId(R.id.sentry_dialog_user_feedback_edt_email))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(
matches(
allOf(
withHint("Test your.email@example.org"),
withText("")
)
)
)
onView(withId(R.id.sentry_dialog_user_feedback_txt_description))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Test Description Test (Required)")))
onView(withId(R.id.sentry_dialog_user_feedback_edt_description))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(
matches(
allOf(
withHint("Test What's the bug? What did you expect?"),
withText("")
)
)
)
}
}
@Test
fun userFeedbackShowNameFalse() {
initSentry {
it.feedbackOptions.isShowName = false
}
showDialogAndCheck {
checkViewVisibility(R.id.sentry_dialog_user_feedback_txt_name, true)
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_name, true)
// Ensure no other views are affected
checkViewVisibility(R.id.sentry_dialog_user_feedback_title)
checkViewVisibility(R.id.sentry_dialog_user_feedback_btn_send)
checkViewVisibility(R.id.sentry_dialog_user_feedback_btn_cancel)
checkViewVisibility(R.id.sentry_dialog_user_feedback_txt_email)
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_email)
checkViewVisibility(R.id.sentry_dialog_user_feedback_txt_description)
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_description)
checkViewVisibility(R.id.sentry_dialog_user_feedback_logo)
}
}
@Test
fun userFeedbackShowEmailFalse() {
initSentry {
it.feedbackOptions.isShowEmail = false
}
showDialogAndCheck {
checkViewVisibility(R.id.sentry_dialog_user_feedback_txt_email, true)
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_email, true)
// Ensure no other views are affected
checkViewVisibility(R.id.sentry_dialog_user_feedback_title)
checkViewVisibility(R.id.sentry_dialog_user_feedback_btn_send)
checkViewVisibility(R.id.sentry_dialog_user_feedback_btn_cancel)
checkViewVisibility(R.id.sentry_dialog_user_feedback_txt_name)
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_name)
checkViewVisibility(R.id.sentry_dialog_user_feedback_txt_description)
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_description)
checkViewVisibility(R.id.sentry_dialog_user_feedback_logo)
}
}
@Test
fun userFeedbackShowBrandingFalse() {
initSentry {
it.feedbackOptions.isShowBranding = false
}
showDialogAndCheck {
checkViewVisibility(R.id.sentry_dialog_user_feedback_logo, true)
// Ensure no other views are affected
checkViewVisibility(R.id.sentry_dialog_user_feedback_title)
checkViewVisibility(R.id.sentry_dialog_user_feedback_btn_send)
checkViewVisibility(R.id.sentry_dialog_user_feedback_btn_cancel)
checkViewVisibility(R.id.sentry_dialog_user_feedback_txt_name)
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_name)
checkViewVisibility(R.id.sentry_dialog_user_feedback_txt_email)
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_email)
checkViewVisibility(R.id.sentry_dialog_user_feedback_txt_description)
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_description)
}
}
@Test
fun userFeedbackNameRequired() {
var anyCallbackCalled = false
initSentry {
it.feedbackOptions.isRequiredLabel = " Test (Required)"
it.feedbackOptions.isNameRequired = true
it.feedbackOptions.nameLabel = "Label of Name"
// Requiring name should show the name field
it.feedbackOptions.isShowName = false
it.feedbackOptions.onSubmitError = SentryFeedbackCallback { anyCallbackCalled = true }
it.feedbackOptions.onSubmitSuccess = SentryFeedbackCallback { anyCallbackCalled = true }
it.feedbackOptions.onFormClose = Runnable { anyCallbackCalled = true }
}
// Name is required
showDialogAndCheck {
// So it shows the required label and force its visibility to VISIBLE
onView(withId(R.id.sentry_dialog_user_feedback_txt_name))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Label of Name Test (Required)")))
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_name)
// And if not filled
fillFormAndSend(fillName = false)
// No callbacks should be called (onSubmitError, onSubmitSuccess, onFormClose)
assertFalse(anyCallbackCalled)
// And EditText shows the required label
onView(withId(R.id.sentry_dialog_user_feedback_edt_name))
.check(matches(withError("Label of Name Test (Required)")))
}
}
@Test
fun userFeedbackEmailRequired() {
var anyCallbackCalled = false
initSentry {
it.feedbackOptions.isRequiredLabel = " Test (Required)"
it.feedbackOptions.isEmailRequired = true
it.feedbackOptions.emailLabel = "Label of Email"
// Requiring name should show the name field
it.feedbackOptions.isShowEmail = false
it.feedbackOptions.onSubmitError = SentryFeedbackCallback { anyCallbackCalled = true }
it.feedbackOptions.onSubmitSuccess = SentryFeedbackCallback { anyCallbackCalled = true }
it.feedbackOptions.onFormClose = Runnable { anyCallbackCalled = true }
}
// Email is required
showDialogAndCheck {
// So it shows the required label and force its visibility to VISIBLE
onView(withId(R.id.sentry_dialog_user_feedback_txt_email))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Label of Email Test (Required)")))
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_email)
// And if not filled
fillFormAndSend(fillEmail = false)
// No callbacks should be called (onSubmitError, onSubmitSuccess, onFormClose)
assertFalse(anyCallbackCalled)
// And EditText shows the required label
onView(withId(R.id.sentry_dialog_user_feedback_edt_email))
.check(matches(withError("Label of Email Test (Required)")))
}
}
@Test
fun userFeedbackMessageRequired() {
var anyCallbackCalled = false
initSentry {
it.feedbackOptions.isRequiredLabel = " Test (Required)"
it.feedbackOptions.messageLabel = "Label of Description"
it.feedbackOptions.onSubmitError = SentryFeedbackCallback { anyCallbackCalled = true }
it.feedbackOptions.onSubmitSuccess = SentryFeedbackCallback { anyCallbackCalled = true }
it.feedbackOptions.onFormClose = Runnable { anyCallbackCalled = true }
}
// message is required
showDialogAndCheck {
// So it shows the required label and force its visibility to VISIBLE
onView(withId(R.id.sentry_dialog_user_feedback_txt_description))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Label of Description Test (Required)")))
checkViewVisibility(R.id.sentry_dialog_user_feedback_edt_description)
// And if not filled
fillFormAndSend(fillDescription = false)
// No callbacks should be called (onSubmitError, onSubmitSuccess, onFormClose)
assertFalse(anyCallbackCalled)
// And EditText shows the required label
onView(withId(R.id.sentry_dialog_user_feedback_edt_description))
.check(matches(withError("Label of Description Test (Required)")))
}
}
@Test
fun userFeedbackSetOnDismissListenerNotOverwriteFormClose() {
var customListenerCalled = false
var formClose = false
initSentry {
it.feedbackOptions.onFormClose = Runnable { formClose = true }
it.beforeSendFeedback = SentryOptions.BeforeSendCallback { _, _ -> null }
}
showDialogAndCheck { dialog ->
// Set a custom listener. This should not overwrite the form close callback
dialog.setOnDismissListener { customListenerCalled = true }
assertFalse(formClose)
assertFalse(customListenerCalled)
// When the dialog is dismissed
fillFormAndSend()
// The form close callback should be called
assertTrue(formClose)
// The custom listener should be called too
assertTrue(customListenerCalled)
}
}
@Test
fun userFeedbackCancel() {
var formOpen = false
var submitError = false
var submitSuccess = false
var formClose = false
initSentry {
it.feedbackOptions.onFormOpen = Runnable { formOpen = true }
it.feedbackOptions.onSubmitError = SentryFeedbackCallback { submitError = true }
it.feedbackOptions.onSubmitSuccess = SentryFeedbackCallback { submitSuccess = true }
it.feedbackOptions.onFormClose = Runnable { formClose = true }
// Let's drop the feedback to test the submit error callback
it.beforeSendFeedback = SentryOptions.BeforeSendCallback { _, _ -> null }
}
assertFalse(formOpen)
// Open the dialog, and call the onFormOpen callback
showDialogAndCheck {
assertTrue(formOpen)
assertFalse(formClose)
assertFalse(submitError)
assertFalse(submitSuccess)
// Let's click on the cancel button
onView(withId(R.id.sentry_dialog_user_feedback_btn_cancel))
.perform(click())
// The form close callback should be called
assertTrue(formClose)
// But the submit callbacks should not
assertFalse(submitError)
assertFalse(submitSuccess)
// And the dialog should be dismissed
onView(withId(R.id.sentry_dialog_user_feedback_layout))
.check(doesNotExist())
}
}
@Test
fun userFeedbackSendError() {
var formOpen = false
var submitError = false
var submitSuccess = false
var formClose = false
initSentry {
it.feedbackOptions.onFormOpen = Runnable { formOpen = true }
it.feedbackOptions.onSubmitError = SentryFeedbackCallback { submitError = true }
it.feedbackOptions.onSubmitSuccess = SentryFeedbackCallback { submitSuccess = true }
it.feedbackOptions.onFormClose = Runnable { formClose = true }
// Let's drop the feedback to test the submit error callback
it.beforeSendFeedback = SentryOptions.BeforeSendCallback { _, _ -> null }
}
assertFalse(formOpen)
// Open the dialog, and call the onFormOpen callback
showDialogAndCheck {
assertTrue(formOpen)
assertFalse(formClose)
assertFalse(submitError)
assertFalse(submitSuccess)
// Sending the feedback will close the dialog, regardless of success
fillFormAndSend()
assertTrue(formClose)
// Sending the feedback failed because of beforeSendFeedback
assertTrue(submitError)
assertFalse(submitSuccess)
}
}
@Test
fun userFeedbackSendSuccess() {
var formOpen = false
var submitError = false
var submitSuccess = false
var formClose = false
initSentry {
it.feedbackOptions.onFormOpen = Runnable { formOpen = true }
it.feedbackOptions.onSubmitError = SentryFeedbackCallback { submitError = true }
it.feedbackOptions.onSubmitSuccess = SentryFeedbackCallback { submitSuccess = true }
it.feedbackOptions.onFormClose = Runnable { formClose = true }
it.feedbackOptions.successMessageText = "Test Thank you for your report!"
}
assertFalse(formOpen)
// Open the dialog, and call the onFormOpen callback
showDialogAndCheck {
assertTrue(formOpen)
assertFalse(formClose)
assertFalse(submitError)
assertFalse(submitSuccess)
// Sending the feedback will close the dialog, regardless of success
fillFormAndSend()
assertTrue(formClose)
assertFalse(submitError)
// Sending the feedback succeeded
assertTrue(submitSuccess)
// Toasts are too much of an hassle to test
}
}
@Test
fun userFeedbackUseSentryUser() {
initSentry {
it.feedbackOptions.isUseSentryUser = true
it.feedbackOptions.isShowEmail = false
}
// When a user is set in Sentry
Sentry.setUser(
User().apply {
name = "Test User"
username = "Test UserName"
email = "Test User Email"
}
)
showDialogAndCheck {
// Name and email are filled with Sentry user properties
onView(withId(R.id.sentry_dialog_user_feedback_edt_name))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
.check(matches(withText("Test UserName")))
// Even if the field is hidden
onView(withId(R.id.sentry_dialog_user_feedback_edt_email))
.check(matches(withEffectiveVisibility(Visibility.GONE)))
.check(matches(withText("Test User Email")))
}
}
@Test
fun userFeedbackUseSentryUserFalse() {
initSentry {
it.feedbackOptions.isUseSentryUser = false
}
// When a user is set in Sentry
Sentry.setUser(
User().apply {
name = "Test User"
username = "Test UserName"
email = "Test User Email"
}
)
showDialogAndCheck {
// Name and email are not filled
onView(withId(R.id.sentry_dialog_user_feedback_edt_name))
.check(matches(withText("")))
onView(withId(R.id.sentry_dialog_user_feedback_edt_email))
.check(matches(withText("")))
}
}
@Ignore("Flaky test")
@Test
fun userFeedbackSendEnvelope() {
// GH actions emulator don't allow capturing screenshots properly
val enableReplay = BuildConfig.ENVIRONMENT != "github"
initSentry(true) {
// When sending the feedback we want to wait for relay to receive it.
// We can't simply increment the idling resource,
// because it would block the espresso interactions (button click)
it.feedbackOptions.onSubmitSuccess = SentryFeedbackCallback { relayIdlingResource.increment() }
// Let's capture a replay, so we can check the replayId in the feedback
if (enableReplay) {
it.sessionReplay.sessionSampleRate = 1.0
}
}
showDialogAndCheck {
// Send the feedback
fillFormAndSend()
}
relay.assert {
findEnvelope {
assertEnvelopeFeedback(
it.items.toList(),
AndroidLogger()
).contexts.feedback!!.message == "Description filled"
}.assert {
val event: SentryEvent = it.assertItem()
val feedback = event.contexts.feedback!!
it.assertNoOtherItems()
assertEquals("Description filled", feedback.message)
assertEquals("Name filled", feedback.name)
assertEquals("Email filled", feedback.contactEmail)
assertEquals("Description filled", feedback.message)
// The screen name should be set in the url
assertEquals("io.sentry.uitest.android.EmptyActivity", feedback.url)
if (enableReplay) {
// The current replay should be set in the replayId
assertNotNull(feedback.replayId)
assertEquals(Sentry.getCurrentScopes().options.replayController.replayId, feedback.replayId)
}
}
}
}
@Test
fun userFeedbackWidgetDefaults() {
initSentry()
var widgetId = 0
showWidgetAndCheck { widget ->
widgetId = widget.id
val densityScale = context.resources.displayMetrics.density
assertEquals((densityScale * 4).toInt(), widget.compoundDrawablePadding)
assertNotNull(widget.compoundDrawables[0]) // Drawable left
assertNull(widget.compoundDrawables[1]) // Drawable top
assertNull(widget.compoundDrawables[2]) // Drawable right
assertNull(widget.compoundDrawables[3]) // Drawable bottom
// Couldn't find a reliable way to check the drawable, so i'll skip it
assertFalse(widget.isAllCaps)
assertEquals(R.drawable.sentry_oval_button_ripple_background, widget.getProperty<Int>("mBackgroundResource"))
assertEquals((densityScale * 12).toInt(), widget.paddingStart)
assertEquals((densityScale * 12).toInt(), widget.paddingEnd)
assertEquals((densityScale * 12).toInt(), widget.paddingTop)
assertEquals((densityScale * 12).toInt(), widget.paddingBottom)
val typedValue = TypedValue()
widget.context.theme.resolveAttribute(android.R.attr.colorForeground, typedValue, true)
assertEquals(typedValue.data, widget.currentTextColor)
assertEquals("Report a Bug", widget.text)
}
onView(withId(widgetId)).perform(click())
// Check that the user feedback dialog is shown
checkViewVisibility(R.id.sentry_dialog_user_feedback_layout)
}
@Test
fun userFeedbackWidgetDefaultsOverridden() {
initSentry()
showWidgetAndCheck({ widget ->
widget.compoundDrawablePadding = 1
widget.setCompoundDrawables(null, null, null, null)
widget.isAllCaps = true
widget.setBackgroundResource(R.drawable.sentry_edit_text_border)
widget.setTextColor(Color.RED)
widget.text = "My custom text"
widget.setPadding(0, 0, 0, 0)
}) { widget ->
val densityScale = context.resources.displayMetrics.density
assertEquals(1, widget.compoundDrawablePadding)
assertNull(widget.compoundDrawables[0]) // Drawable left
assertNull(widget.compoundDrawables[1]) // Drawable top
assertNull(widget.compoundDrawables[2]) // Drawable right
assertNull(widget.compoundDrawables[3]) // Drawable bottom
assertTrue(widget.isAllCaps)
assertEquals(R.drawable.sentry_edit_text_border, widget.getProperty<Int>("mBackgroundResource"))
assertEquals((densityScale * 0).toInt(), widget.paddingStart)
assertEquals((densityScale * 0).toInt(), widget.paddingEnd)
assertEquals((densityScale * 0).toInt(), widget.paddingTop)
assertEquals((densityScale * 0).toInt(), widget.paddingBottom)
assertEquals(Color.RED, widget.currentTextColor)
assertEquals("My custom text", widget.text)
}
}
@Test
fun userFeedbackWidgetShowsDialogOnClickOverridden() {
initSentry()
var widgetId = 0
var customListenerCalled = false
showWidgetAndCheck { widget ->
widgetId = widget.id
widget.setOnClickListener { customListenerCalled = true }
}
onView(withId(widgetId)).perform(click())
// Check that the user feedback dialog is shown
checkViewVisibility(R.id.sentry_dialog_user_feedback_layout)
// And the custom listener is called, too
assertTrue(customListenerCalled)
}
private fun checkViewVisibility(viewId: Int, isGone: Boolean = false) {
onView(withId(viewId))
.check(matches(withEffectiveVisibility(if (isGone) Visibility.GONE else Visibility.VISIBLE)))
}
private fun fillFormAndSend(
fillName: Boolean = true,
fillEmail: Boolean = true,
fillDescription: Boolean = true
) {
if (fillName) {
onView(withId(R.id.sentry_dialog_user_feedback_edt_name))
.perform(replaceText("Name filled"))
}
if (fillEmail) {
onView(withId(R.id.sentry_dialog_user_feedback_edt_email))
.perform(replaceText("Email filled"))
}
if (fillDescription) {
onView(withId(R.id.sentry_dialog_user_feedback_edt_description))
.perform(replaceText("Description filled"))
}
onView(withId(R.id.sentry_dialog_user_feedback_btn_send))
.perform(click())
}
private fun showDialogAndCheck(checker: (dialog: SentryUserFeedbackDialog) -> Unit = {}) {
lateinit var dialog: SentryUserFeedbackDialog
val feedbackScenario = launchActivity<EmptyActivity>()
feedbackScenario.onActivity {
dialog = SentryUserFeedbackDialog.Builder(it).create()
dialog.show()
}
onView(withId(R.id.sentry_dialog_user_feedback_layout))
.inRoot(isDialog())
.check(matches(isDisplayed()))
checker(dialog)
}
private fun showWidgetAndCheck(widgetConfig: ((widget: SentryUserFeedbackButton) -> Unit)? = null, checker: (widget: SentryUserFeedbackButton) -> Unit = {}) {
val buttonId = Int.MAX_VALUE - 1
val feedbackScenario = launchActivity<EmptyActivity>()
feedbackScenario.onActivity {
val view = LinearLayout(it).apply {
orientation = LinearLayout.VERTICAL
addView(
SentryUserFeedbackButton(it).apply {
id = buttonId
widgetConfig?.invoke(this)
}
)
}
it.setContentView(view)
}
checkViewVisibility(buttonId)
onView(withId(buttonId))
.check(matches(isDisplayed()))
.check { view, _ ->
checker(view as SentryUserFeedbackButton)
}
}
fun withError(expectedError: String): Matcher<View> {
return object : BoundedMatcher<View, EditText>(EditText::class.java) {
override fun describeTo(description: Description) {
description.appendText("with error: $expectedError")
}
override fun matchesSafely(editText: EditText): Boolean {
val error = editText.error?.toString()
return expectedError == error
}
}
}
}