4444import static android .content .pm .ActivityInfo .SCREEN_ORIENTATION_LANDSCAPE ;
4545import static android .content .pm .ActivityInfo .SCREEN_ORIENTATION_PORTRAIT ;
4646
47- import static org .catrobat .paintroid .test .espresso .util .EspressoUtils .getMainActivity ;
4847import static org .catrobat .paintroid .test .espresso .util .UiMatcher .withBackground ;
4948import static org .catrobat .paintroid .test .espresso .util .UiMatcher .withBackgroundColor ;
5049import static org .catrobat .paintroid .test .espresso .util .wrappers .BottomNavigationViewInteraction .onBottomNavigationView ;
6160import static androidx .test .espresso .Espresso .pressBack ;
6261import static androidx .test .espresso .action .ViewActions .click ;
6362import static androidx .test .espresso .action .ViewActions .scrollTo ;
64- import static androidx .test .espresso .action .ViewActions .swipeDown ;
6563import static androidx .test .espresso .assertion .ViewAssertions .matches ;
6664import static androidx .test .espresso .matcher .ViewMatchers .isDisplayed ;
6765import static androidx .test .espresso .matcher .ViewMatchers .withClassName ;
7169@ RunWith (AndroidJUnit4 .class )
7270public class LandscapeIntegrationTest {
7371
72+ private MainActivity mainActivity ;
73+
7474 @ Rule
7575 public ActivityTestRule <MainActivity > activityTestRule = new ActivityTestRule <>(MainActivity .class );
7676
77- @ Before
78- public void setUp () {
79- onToolBarView ()
80- .performSelectTool (ToolType .BRUSH );
81-
82- setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
83- }
84-
8577 private Tool getCurrentTool () {
86- return getMainActivity () .toolReference .get ();
78+ return mainActivity .toolReference .get ();
8779 }
8880
8981 private ToolOptionsViewController getToolOptionsViewController () {
90- return getMainActivity ().toolOptionsViewController ;
82+ return mainActivity .toolOptionsViewController ;
83+ }
84+
85+ @ Before
86+ public void setUp () {
87+ mainActivity = activityTestRule .getActivity ();
9188 }
9289
9390 @ Test
9491 public void testLandscapeMode () {
95- setOrientation (SCREEN_ORIENTATION_PORTRAIT );
9692 setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
93+ setOrientation (SCREEN_ORIENTATION_PORTRAIT );
9794 }
9895
9996 @ Test
10097 public void testTools () {
98+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
10199 for (ToolType toolType : ToolType .values ()) {
102100 if (toolType == ToolType .IMPORTPNG
103101 || toolType == ToolType .COLORCHOOSER
@@ -130,27 +128,130 @@ public void testTools() {
130128 }
131129
132130 @ Test
133- public void testCorrectSelectionInBothOrientations () {
134- for (ToolType toolType : ToolType .values ()) {
135- if (toolType == ToolType .IMPORTPNG
136- || toolType == ToolType .COLORCHOOSER
137- || toolType == ToolType .REDO
138- || toolType == ToolType .UNDO
139- || toolType == ToolType .LAYER ) {
140- continue ;
141- }
131+ public void testCorrectSelectionInBothOrientationsBrushTool () {
132+ ToolType toolType = ToolType .BRUSH ;
142133
143- onToolBarView ()
144- .performSelectTool (toolType );
134+ onToolBarView ()
135+ .performSelectTool (toolType );
136+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
145137
146- setOrientation (SCREEN_ORIENTATION_PORTRAIT );
147- assertEquals (toolType , getCurrentTool ().getToolType ());
148- setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
149- }
138+ assertEquals (toolType , getCurrentTool ().getToolType ());
139+ }
140+
141+ @ Test
142+ public void testCorrectSelectionInBothOrientationsCursorTool () {
143+ ToolType toolType = ToolType .CURSOR ;
144+
145+ onToolBarView ()
146+ .performSelectTool (toolType );
147+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
148+
149+ assertEquals (toolType , getCurrentTool ().getToolType ());
150+ }
151+
152+ @ Test
153+ public void testCorrectSelectionInBothOrientationsTransformTool () {
154+ ToolType toolType = ToolType .TRANSFORM ;
155+
156+ onToolBarView ()
157+ .performSelectTool (toolType );
158+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
159+
160+ assertEquals (toolType , getCurrentTool ().getToolType ());
161+ }
162+
163+ @ Test
164+ public void testCorrectSelectionInBothOrientationsFillTool () {
165+ ToolType toolType = ToolType .FILL ;
166+
167+ onToolBarView ()
168+ .performSelectTool (toolType );
169+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
170+
171+ assertEquals (toolType , getCurrentTool ().getToolType ());
172+ }
173+
174+ @ Test
175+ public void testCorrectSelectionInBothOrientationsHandTool () {
176+ ToolType toolType = ToolType .HAND ;
177+
178+ onToolBarView ()
179+ .performSelectTool (toolType );
180+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
181+
182+ assertEquals (toolType , getCurrentTool ().getToolType ());
183+ }
184+
185+ @ Test
186+ public void testCorrectSelectionInBothOrientationsEraserTool () {
187+ ToolType toolType = ToolType .ERASER ;
188+
189+ onToolBarView ()
190+ .performSelectTool (toolType );
191+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
192+
193+ assertEquals (toolType , getCurrentTool ().getToolType ());
194+ }
195+
196+ @ Test
197+ public void testCorrectSelectionInBothOrientationsLineTool () {
198+ ToolType toolType = ToolType .LINE ;
199+
200+ onToolBarView ()
201+ .performSelectTool (toolType );
202+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
203+
204+ assertEquals (toolType , getCurrentTool ().getToolType ());
205+ }
206+
207+ @ Test
208+ public void testCorrectSelectionInBothOrientationsPipetteTool () {
209+ ToolType toolType = ToolType .PIPETTE ;
210+
211+ onToolBarView ()
212+ .performSelectTool (toolType );
213+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
214+
215+ assertEquals (toolType , getCurrentTool ().getToolType ());
216+ }
217+
218+ @ Test
219+ public void testCorrectSelectionInBothOrientationsShapeTool () {
220+ ToolType toolType = ToolType .SHAPE ;
221+
222+ onToolBarView ()
223+ .performSelectTool (toolType );
224+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
225+
226+ assertEquals (toolType , getCurrentTool ().getToolType ());
227+ }
228+
229+ @ Test
230+ public void testCorrectSelectionInBothOrientationsStampTool () {
231+ ToolType toolType = ToolType .STAMP ;
232+
233+ onToolBarView ()
234+ .performSelectTool (toolType );
235+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
236+
237+ assertEquals (toolType , getCurrentTool ().getToolType ());
238+ }
239+
240+ @ Test
241+ public void testCorrectSelectionInBothOrientationsTextTool () {
242+ ToolType toolType = ToolType .TEXT ;
243+
244+ onToolBarView ()
245+ .performSelectTool (toolType );
246+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
247+
248+ assertEquals (toolType , getCurrentTool ().getToolType ());
150249 }
151250
152251 @ Test
153252 public void testMoreOptionsDrawerAppearsAndAllItemsExist () {
253+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
254+
154255 onTopBarView ()
155256 .performOpenMoreOptions ();
156257
@@ -163,13 +264,15 @@ public void testMoreOptionsDrawerAppearsAndAllItemsExist() {
163264 .checkItemExists (R .string .menu_save_image )
164265 .checkItemExists (R .string .menu_save_copy )
165266 .checkItemExists (R .string .menu_new_image )
267+ .checkItemExists (R .string .share_image_menu )
166268
167269 .checkItemDoesNotExist (R .string .menu_discard_image )
168270 .checkItemDoesNotExist (R .string .menu_export );
169271 }
170272
171273 @ Test
172274 public void testOpenColorPickerDialogInLandscape () {
275+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
173276 onColorPickerView ()
174277 .performOpenColorPicker ();
175278
@@ -179,6 +282,7 @@ public void testOpenColorPickerDialogInLandscape() {
179282
180283 @ Test
181284 public void testOpenColorPickerDialogChooseColorInLandscape () {
285+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
182286 onColorPickerView ()
183287 .performOpenColorPicker ();
184288
@@ -198,6 +302,7 @@ public void testOpenColorPickerDialogChooseColorInLandscape() {
198302
199303 @ Test
200304 public void testOpenColorPickerDialogApplyColorInLandscape () {
305+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
201306 int [] colors = getColorArrayFromResource (activityTestRule .getActivity (), R .array .pocketpaint_color_picker_preset_colors );
202307
203308 for (int i = 0 ; i < colors .length ; i ++) {
@@ -239,6 +344,7 @@ public void testColorPickerCancelButtonKeepsColorInLandscape() {
239344
240345 @ Test
241346 public void testScrollToColorChooserOk () {
347+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
242348 onColorPickerView ()
243349 .performOpenColorPicker ();
244350
@@ -248,6 +354,7 @@ public void testScrollToColorChooserOk() {
248354
249355 @ Test
250356 public void testColorPickerDialogSwitchTabsInLandscape () {
357+ setOrientation (SCREEN_ORIENTATION_LANDSCAPE );
251358 onColorPickerView ()
252359 .performOpenColorPicker ();
253360
@@ -263,18 +370,11 @@ public void testColorPickerDialogSwitchTabsInLandscape() {
263370 .perform (click ());
264371 onView (withClassName (is (RgbSelectorView .class .getName ())))
265372 .check (matches (isDisplayed ()));
266-
267- onView (withId (R .id .color_picker_rgb_base_layout )).perform (swipeDown ());
268-
269- onView (allOf (withId (R .id .color_picker_tab_icon ), withBackground (R .drawable .ic_color_picker_tab_preset )))
270- .perform (click ());
271- onView (withClassName (is (PresetSelectorView .class .getName ())))
272- .check (matches (isDisplayed ()));
373+ pressBack ();
273374 }
274375
275376 @ Test
276377 public void testFullscreenPortraitOrientationChangeWithBrush () {
277- setOrientation (SCREEN_ORIENTATION_PORTRAIT );
278378
279379 onTopBarView ()
280380 .performOpenMoreOptions ();
@@ -302,19 +402,13 @@ public void testFullscreenLandscapeOrientationChangeWithBrush() {
302402 setOrientation (SCREEN_ORIENTATION_PORTRAIT );
303403
304404 pressBack ();
305-
306- onToolBarView ()
307- .performOpenToolOptionsView ()
308- .performCloseToolOptionsView ();
309405 }
310406
311407 @ Test
312408 public void testFullscreenPortraitOrientationChangeWithShape () {
313409 onToolBarView ()
314410 .performSelectTool (ToolType .SHAPE );
315411
316- setOrientation (SCREEN_ORIENTATION_PORTRAIT );
317-
318412 onTopBarView ()
319413 .performOpenMoreOptions ();
320414
@@ -352,7 +446,7 @@ public void testFullscreenLandscapeOrientationChangeWithShape() {
352446
353447 @ Test
354448 public void testIfCurrentToolIsShownInBottomNavigation () {
355-
449+ setOrientation ( SCREEN_ORIENTATION_LANDSCAPE );
356450 for (ToolType toolType : ToolType .values ()) {
357451 if (toolType == ToolType .IMPORTPNG
358452 || toolType == ToolType .COLORCHOOSER
0 commit comments