1
- package ch .epfl .sweng .hostme ;
1
+ package ch .epfl .sweng .hostme . account ;
2
2
3
3
import static androidx .test .espresso .Espresso .onView ;
4
4
import static androidx .test .espresso .action .ViewActions .clearText ;
5
5
import static androidx .test .espresso .action .ViewActions .click ;
6
6
import static androidx .test .espresso .action .ViewActions .closeSoftKeyboard ;
7
7
import static androidx .test .espresso .action .ViewActions .typeText ;
8
8
import static androidx .test .espresso .assertion .ViewAssertions .matches ;
9
+ import static androidx .test .espresso .intent .Intents .intended ;
9
10
import static androidx .test .espresso .intent .Intents .intending ;
10
11
import static androidx .test .espresso .intent .matcher .IntentMatchers .hasAction ;
11
12
import static androidx .test .espresso .matcher .ViewMatchers .isDisplayed ;
12
13
import static androidx .test .espresso .matcher .ViewMatchers .isEnabled ;
14
+ import static androidx .test .espresso .matcher .ViewMatchers .isNotEnabled ;
13
15
import static androidx .test .espresso .matcher .ViewMatchers .withId ;
14
16
import static androidx .test .espresso .matcher .ViewMatchers .withText ;
15
17
import static org .junit .Assert .assertNotNull ;
28
30
import androidx .test .core .app .ActivityScenario ;
29
31
import androidx .test .core .app .ApplicationProvider ;
30
32
import androidx .test .espresso .intent .Intents ;
33
+ import androidx .test .espresso .matcher .ViewMatchers ;
31
34
import androidx .test .ext .junit .runners .AndroidJUnit4 ;
32
35
import androidx .test .rule .GrantPermissionRule ;
33
36
42
45
import java .io .FileOutputStream ;
43
46
import java .io .IOException ;
44
47
48
+ import ch .epfl .sweng .hostme .R ;
45
49
import ch .epfl .sweng .hostme .activities .LogInActivity ;
46
50
import ch .epfl .sweng .hostme .activities .MenuActivity ;
47
51
import ch .epfl .sweng .hostme .database .Auth ;
@@ -63,7 +67,7 @@ public static void setUp() {
63
67
FirebaseApp .initializeApp (ApplicationProvider .getApplicationContext ());
64
68
}
65
69
66
- public static Bitmap drawableToBitmap (Drawable drawable ) {
70
+ private static Bitmap drawableToBitmap (Drawable drawable ) {
67
71
68
72
if (drawable instanceof BitmapDrawable ) {
69
73
return ((BitmapDrawable ) drawable ).getBitmap ();
@@ -88,15 +92,13 @@ public void ProfileInfoIsDisplayedTest() {
88
92
String lastName = "account" ;
89
93
String gender = "Male" ;
90
94
91
- onView (withId (R .id .user_name )).perform (typeText (mail ), closeSoftKeyboard ());
95
+ onView (ViewMatchers . withId (R .id .user_name )).perform (typeText (mail ), closeSoftKeyboard ());
92
96
onView (withId (R .id .pwd )).perform (typeText (password ), closeSoftKeyboard ());
93
97
onView (withId (R .id .log_in_button )).perform (click ());
94
98
Thread .sleep (1000 );
95
99
96
100
onView (withId (R .id .navigation_account )).check (matches (isDisplayed ()));
97
101
onView (withId (R .id .navigation_account )).perform (click ());
98
- Thread .sleep (1000 );
99
-
100
102
onView (withId (R .id .user_profile_first_name )).check (matches (withText (firstName )));
101
103
onView (withId (R .id .user_profile_last_name )).check (matches (withText (lastName )));
102
104
onView (withId (R .id .user_profile_email )).check (matches (withText (Auth .getCurrentUser ().getEmail ())));
@@ -120,13 +122,11 @@ public void logOut() {
120
122
Thread .sleep (1000 );
121
123
122
124
onView (withId (R .id .navigation_account )).perform (click ());
123
- Thread .sleep (1000 );
124
-
125
125
onView (withId (R .id .user_profile_log_out_button )).perform (click ());
126
- Thread .sleep (1000 );
127
-
128
126
Intent intent2 = new Intent (ApplicationProvider .getApplicationContext (), MenuActivity .class );
129
127
ActivityScenario <MenuActivity > scenario2 = ActivityScenario .launch (intent2 );
128
+
129
+ onView (withId (R .id .log_in_button )).check (matches (isDisplayed ()));
130
130
} catch (InterruptedException e ) {
131
131
e .printStackTrace ();
132
132
}
@@ -145,25 +145,20 @@ public void saveProfileButtonEnabledTest() {
145
145
onView (withId (R .id .pwd )).perform (typeText (password ), closeSoftKeyboard ());
146
146
onView (withId (R .id .log_in_button )).perform (click ());
147
147
Thread .sleep (1000 );
148
-
149
148
onView (withId (R .id .navigation_account )).perform (click ());
150
- Thread .sleep (1000 );
151
149
152
150
String firstname = "test modified" ;
153
- onView (withId (R .id .user_profile_first_name )).perform (clearText ())
154
- .perform (typeText (firstname ), closeSoftKeyboard ());
151
+ onView (withId (R .id .user_profile_first_name )).perform (clearText ()).perform (typeText (firstname ), closeSoftKeyboard ());
155
152
onView (withId (R .id .user_profile_save_button )).check (matches (isEnabled ()));
156
153
onView (withId (R .id .user_profile_save_button )).check (matches (isDisplayed ()));
157
154
onView (withId (R .id .user_profile_gender_f )).perform (click ());
158
155
onView (withId (R .id .user_profile_save_button )).perform (click ());
159
- Thread .sleep (1000 );
160
156
161
157
String firstnameOriginal = "test" ;
162
- onView (withId (R .id .user_profile_first_name )).perform (clearText ())
163
- .perform (typeText (firstnameOriginal ), closeSoftKeyboard ());
158
+ onView (withId (R .id .user_profile_first_name )).perform (clearText ()).perform (typeText (firstnameOriginal ), closeSoftKeyboard ());
164
159
onView (withId (R .id .user_profile_gender_m )).perform (click ());
165
160
onView (withId (R .id .user_profile_save_button )).perform (click ());
166
- Thread . sleep ( 1000 );
161
+ onView ( withId ( R . id . user_profile_save_button )). check ( matches ( isNotEnabled ()) );
167
162
168
163
} catch (InterruptedException e ) {
169
164
e .printStackTrace ();
@@ -185,11 +180,8 @@ public void saveProfileButtonDisabledTest() {
185
180
Thread .sleep (1000 );
186
181
187
182
onView (withId (R .id .navigation_account )).perform (click ());
188
- Thread .sleep (1000 );
189
-
190
183
String firstname = "test modified" ;
191
- onView (withId (R .id .user_profile_first_name )).perform (clearText ())
192
- .perform (typeText (firstname ), closeSoftKeyboard ());
184
+ onView (withId (R .id .user_profile_first_name )).perform (clearText ()).perform (typeText (firstname ), closeSoftKeyboard ());
193
185
onView (withId (R .id .user_profile_save_button )).check (matches (isEnabled ()));
194
186
onView (withId (R .id .user_profile_save_button )).check (matches (isDisplayed ()));
195
187
onView (withId (R .id .user_profile_gender_f )).perform (click ());
@@ -214,8 +206,6 @@ public void checkButtonWalletWorks() {
214
206
Thread .sleep (1000 );
215
207
216
208
onView (withId (R .id .navigation_account )).perform (click ());
217
- Thread .sleep (1000 );
218
-
219
209
onView (withId (R .id .wallet_button )).check (matches (isDisplayed ()));
220
210
onView (withId (R .id .wallet_button )).perform (click ());
221
211
@@ -241,25 +231,20 @@ public void changePasswordButtonTest() {
241
231
242
232
onView (withId (R .id .navigation_account )).check (matches (isDisplayed ()));
243
233
onView (withId (R .id .navigation_account )).perform (click ());
244
- Thread .sleep (1000 );
245
-
246
234
onView (withId (R .id .user_profile_change_password_button )).perform (click ());
247
235
onView (withId (R .id .user_profile_change_pwd_terminate )).perform (click ());
248
- Thread .sleep (1000 );
249
236
onView (withId (R .id .user_profile_old_password )).check (matches (isDisplayed ()));
250
237
onView (withId (R .id .user_profile_new_password )).check (matches (isDisplayed ()));
251
238
onView (withId (R .id .user_profile_confirm_new_password )).check (matches (isDisplayed ()));
252
239
onView (withId (R .id .user_profile_old_password )).perform (typeText (originalPassword ), closeSoftKeyboard ());
253
240
onView (withId (R .id .user_profile_new_password )).perform (typeText (newPassword ), closeSoftKeyboard ());
254
241
onView (withId (R .id .user_profile_confirm_new_password )).perform (typeText (newPassword ), closeSoftKeyboard ());
255
242
onView (withId (R .id .user_profile_change_pwd_terminate )).perform (click ());
256
- Thread .sleep (1000 );
257
243
258
244
onView (withId (R .id .user_profile_old_password )).perform (clearText ()).perform (typeText (newPassword ), closeSoftKeyboard ());
259
245
onView (withId (R .id .user_profile_new_password )).perform (clearText ()).perform (typeText (originalPassword ), closeSoftKeyboard ());
260
246
onView (withId (R .id .user_profile_confirm_new_password )).perform (clearText ()).perform (typeText (originalPassword ), closeSoftKeyboard ());
261
247
onView (withId (R .id .user_profile_change_pwd_terminate )).perform (click ());
262
- Thread .sleep (1000 );
263
248
} catch (InterruptedException e ) {
264
249
e .printStackTrace ();
265
250
}
@@ -271,6 +256,7 @@ public void uploadProfilePictureFromCamera() {
271
256
Intent intent = new Intent (ApplicationProvider .getApplicationContext (), LogInActivity .class );
272
257
Intents .init ();
273
258
try (ActivityScenario <LogInActivity > scenario = ActivityScenario .launch (intent )) {
259
+ savePickedImage ();
274
260
intending (hasAction (MediaStore .ACTION_IMAGE_CAPTURE )).respondWith (getImageResult ());
275
261
276
262
String mail =
"[email protected] " ;
@@ -282,10 +268,10 @@ public void uploadProfilePictureFromCamera() {
282
268
Thread .sleep (1000 );
283
269
284
270
onView (withId (R .id .navigation_account )).perform (click ());
285
- Thread .sleep (1000 );
286
271
287
272
onView (withId (R .id .user_profile_change_photo_button )).perform (click ());
288
273
onView (withText ("Pick from Camera" )).perform (click ());
274
+ intended (hasAction (MediaStore .ACTION_IMAGE_CAPTURE ));
289
275
Thread .sleep (1000 );
290
276
} catch (InterruptedException e ) {
291
277
e .printStackTrace ();
@@ -309,11 +295,11 @@ public void uploadProfilePictureFromGallery() {
309
295
Thread .sleep (1000 );
310
296
311
297
onView (withId (R .id .navigation_account )).perform (click ());
312
- Thread .sleep (1000 );
313
298
314
299
onView (withId (R .id .user_profile_change_photo_button )).perform (click ());
315
300
316
301
onView (withText ("Pick from Gallery" )).perform (click ());
302
+ intended (hasAction (Intent .ACTION_PICK ));
317
303
Thread .sleep (1000 );
318
304
onView (withId (R .id .user_profile_save_button )).perform (click ());
319
305
} catch (InterruptedException e ) {
@@ -338,21 +324,18 @@ public void updateProfilePictureFromGallery() {
338
324
Thread .sleep (1000 );
339
325
340
326
onView (withId (R .id .navigation_account )).perform (click ());
341
- Thread .sleep (1000 );
342
327
343
328
onView (withId (R .id .user_profile_change_photo_button )).perform (click ());
344
329
345
330
346
331
onView (withText ("Pick from Gallery" )).perform (click ());
332
+ intended (hasAction (Intent .ACTION_PICK ));
347
333
Thread .sleep (1000 );
348
334
onView (withId (R .id .user_profile_save_button )).perform (click ());
349
- Thread .sleep (1000 );
350
335
onView (withId (R .id .user_profile_change_photo_button )).perform (click ());
351
336
352
337
onView (withText ("Pick from Gallery" )).perform (click ());
353
- Thread .sleep (1000 );
354
338
onView (withId (R .id .user_profile_save_button )).perform (click ());
355
-
356
339
} catch (InterruptedException e ) {
357
340
e .printStackTrace ();
358
341
}
@@ -375,14 +358,13 @@ public void uploadProfilePictureAndDelete() {
375
358
Thread .sleep (1000 );
376
359
377
360
onView (withId (R .id .navigation_account )).perform (click ());
378
- Thread .sleep (1000 );
379
361
380
362
onView (withId (R .id .user_profile_change_photo_button )).perform (click ());
381
363
382
364
onView (withText ("Pick from Gallery" )).perform (click ());
365
+ intended (hasAction (Intent .ACTION_PICK ));
383
366
Thread .sleep (1000 );
384
367
onView (withId (R .id .user_profile_save_button )).perform (click ());
385
- Thread .sleep (1000 );
386
368
387
369
onView (withId (R .id .user_profile_change_photo_button )).perform (click ());
388
370
onView (withText ("Delete" )).perform (click ());
0 commit comments