1
1
package com .burhanrashid52 .photoeditor ;
2
2
3
- import android .support .test .filters .LargeTest ;
4
- import android .support .test .rule .ActivityTestRule ;
5
- import android .support .test .runner .AndroidJUnit4 ;
3
+ import android .content .Context ;
6
4
5
+ import androidx .test .espresso .contrib .RecyclerViewActions ;
6
+ import androidx .test .filters .LargeTest ;
7
+ import androidx .test .rule .ActivityTestRule ;
8
+ import androidx .test .runner .AndroidJUnit4 ;
9
+
10
+ import org .junit .Ignore ;
7
11
import org .junit .Rule ;
8
12
import org .junit .Test ;
9
13
import org .junit .runner .RunWith ;
10
14
11
- import static android .support .test .espresso .Espresso .onView ;
12
- import static android .support .test .espresso .assertion .ViewAssertions .matches ;
13
- import static android .support .test .espresso .matcher .ViewMatchers .isDisplayed ;
14
- import static android .support .test .espresso .matcher .ViewMatchers .withText ;
15
+ import java .util .ArrayList ;
16
+
17
+ import ja .burhanrashid52 .photoeditor .PhotoEditor ;
18
+
19
+ import static androidx .test .espresso .Espresso .onView ;
20
+ import static androidx .test .espresso .action .ViewActions .click ;
21
+ import static androidx .test .espresso .assertion .ViewAssertions .doesNotExist ;
22
+ import static androidx .test .espresso .assertion .ViewAssertions .matches ;
23
+ import static androidx .test .espresso .matcher .ViewMatchers .isDisplayed ;
24
+ import static androidx .test .espresso .matcher .ViewMatchers .withId ;
25
+ import static androidx .test .espresso .matcher .ViewMatchers .withText ;
26
+ import static junit .framework .TestCase .assertTrue ;
27
+ import static org .junit .Assert .assertFalse ;
15
28
16
29
17
30
@ RunWith (AndroidJUnit4 .class )
18
31
@ LargeTest
19
32
public class EditImageActivityTest {
20
33
21
34
@ Rule
22
- public ActivityTestRule <EditImageActivity > mActivityRule = new ActivityTestRule <>(EditImageActivity .class );
35
+ public ActivityTestRule <EditImageActivity > mActivityRule = new ActivityTestRule <>(EditImageActivity .class , false , false );
23
36
24
37
@ Test
25
38
public void checkIfActivityIsLaunched () {
39
+ mActivityRule .launchActivity (null );
26
40
onView (withText (R .string .app_name )).check (matches (isDisplayed ()));
27
41
}
42
+
43
+ @ Test
44
+ public void checkIfBrushIsEnabledWhenClickedOnBrushTool () {
45
+ EditImageActivity editImageActivity = mActivityRule .launchActivity (null );
46
+ assertFalse (editImageActivity .mPhotoEditor .getBrushDrawableMode ());
47
+ onView (withText (R .string .label_brush )).perform (click ());
48
+ assertTrue (editImageActivity .mPhotoEditor .getBrushDrawableMode ());
49
+ }
50
+
51
+ @ Test
52
+ public void checkIfEraserIsEnabledWhenClickedOnEraserTool () {
53
+ mActivityRule .launchActivity (null );
54
+ onView (withText (R .string .label_eraser )).perform (click ());
55
+ onView (withText (R .string .label_eraser_mode )).check (matches (isDisplayed ()));
56
+ }
57
+
58
+ @ Test
59
+ public void checkIfEmojiIsDisplayedWhenEmojiIsSelected () {
60
+ Context context = mActivityRule .launchActivity (null );
61
+ ArrayList <String > emojis = PhotoEditor .getEmojis (context );
62
+ int emojiPosition = 1 ;
63
+ String emojiUnicode = emojis .get (emojiPosition );
64
+ onView (withText (R .string .label_emoji )).perform (click ());
65
+ onView (withId (R .id .rvEmoji ))
66
+ .perform (RecyclerViewActions .actionOnItemAtPosition (emojiPosition , click ()));
67
+ onView (withText (emojiUnicode )).check (matches (isDisplayed ()));
68
+ }
69
+
70
+ @ Ignore ("Flacky test. Need to optimize" )
71
+ public void checkIfDiscardDialogIsNotDisplayedWhenCacheIsEmpty () {
72
+ EditImageActivity editImageActivity = mActivityRule .launchActivity (null );
73
+ assertTrue (editImageActivity .mPhotoEditor .isCacheEmpty ());
74
+ onView (withId (R .id .imgClose )).perform (click ());
75
+ assertTrue (editImageActivity .isDestroyed ());
76
+ }
77
+
78
+ @ Test
79
+ public void checkIfDiscardDialogIsDisplayedWhenCacheIsNotEmpty () {
80
+ EditImageActivity editImageActivity = mActivityRule .launchActivity (null );
81
+ assertTrue (editImageActivity .mPhotoEditor .isCacheEmpty ());
82
+ onView (withText (R .string .label_emoji )).perform (click ());
83
+ onView (withId (R .id .rvEmoji ))
84
+ .perform (RecyclerViewActions .actionOnItemAtPosition (0 , click ()));
85
+ onView (withId (R .id .imgClose )).perform (click ());
86
+ onView (withText (R .string .msg_save_image )).check (matches (isDisplayed ()));
87
+ }
88
+
89
+ @ Test
90
+ public void checkIfUndoRedoIsWorkingCorrectWhenClickedOnUndoRedo () throws InterruptedException {
91
+ EditImageActivity editImageActivity = mActivityRule .launchActivity (null );
92
+ ArrayList <String > emojisUnicodes = PhotoEditor .getEmojis (editImageActivity );
93
+
94
+ //Add Emoji
95
+ onView (withText (R .string .label_emoji )).perform (click ());
96
+ onView (withId (R .id .rvEmoji )).perform (RecyclerViewActions .actionOnItemAtPosition (0 , click ()));
97
+ onView (withText (emojisUnicodes .get (0 ))).check (matches (isDisplayed ()));
98
+
99
+ // Undo the Emoji
100
+ onView (withId (R .id .imgUndo )).perform (click ());
101
+ onView (withText (emojisUnicodes .get (0 ))).check (doesNotExist ());
102
+
103
+ // Redo the Emoji
104
+ onView (withId (R .id .imgRedo )).perform (click ());
105
+ onView (withText (emojisUnicodes .get (0 ))).check (matches (isDisplayed ()));
106
+ }
28
107
}
0 commit comments