From 4002d04a324d5396cf6d4f993bab1eec830482e8 Mon Sep 17 00:00:00 2001 From: Emsad Salkic Date: Thu, 10 Jun 2021 00:34:29 +0200 Subject: [PATCH] TL-010 Fixed all tests and added small fixes --- .../java/com/example/tutorly/DatabaseTest.kt | 41 ----------- .../com/example/tutorly/FilterActivityTest.kt | 11 +-- .../com/example/tutorly/LoginRegisterTest.kt | 10 ++- .../example/tutorly/NewTutorActivityTest.kt | 32 +++++++++ .../com/example/tutorly/TownSelectionTest.kt | 51 ++++++++------ .../com/example/tutorly/TutorProfileTest.kt | 13 ++-- .../java/com/example/tutorly/TutorlistTest.kt | 68 +++++++------------ .../java/com/example/tutorly/TutorProfile.kt | 12 ++-- .../res/layout/activity_town_selection.xml | 2 +- .../example/tutorly/database/DatabaseTest.kt | 1 + 10 files changed, 124 insertions(+), 117 deletions(-) delete mode 100644 Tutorly/app/src/androidTest/java/com/example/tutorly/DatabaseTest.kt diff --git a/Tutorly/app/src/androidTest/java/com/example/tutorly/DatabaseTest.kt b/Tutorly/app/src/androidTest/java/com/example/tutorly/DatabaseTest.kt deleted file mode 100644 index e302300..0000000 --- a/Tutorly/app/src/androidTest/java/com/example/tutorly/DatabaseTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.example.tutorly -import androidx.test.ext.junit.rules.ActivityScenarioRule -import com.example.tutorly.database.User -import com.example.tutorly.database.UserAutheniticator -import kotlinx.coroutines.* - - -import org.junit.Test - - -import org.junit.Assert.* - -class DatabaseTest -{ - - @Test - fun checkUserSignedInTest() - { - var testUser = User("Mustermann", "Mustermann", "mustermann@tugraz.at", "1234") - val testDataVar = UserAutheniticator().createUserAccount(testUser) - assertTrue(UserAutheniticator().isUserSignedIn()) - } - - @Test - fun getUserTest() - { - var testUser = User("Mustermann", "Mustermann", "mustermann@tugraz.at", "1234") - val testDataVar = UserAutheniticator().createUserAccount(testUser) - - var currentUser = UserAutheniticator().getCurrentUser() - - if (currentUser != null) { - assertEquals(currentUser.email, "mustermann@tugraz.at") - } - else - { - assert(false) - } - } - -} \ No newline at end of file diff --git a/Tutorly/app/src/androidTest/java/com/example/tutorly/FilterActivityTest.kt b/Tutorly/app/src/androidTest/java/com/example/tutorly/FilterActivityTest.kt index 72216ad..3aaf600 100644 --- a/Tutorly/app/src/androidTest/java/com/example/tutorly/FilterActivityTest.kt +++ b/Tutorly/app/src/androidTest/java/com/example/tutorly/FilterActivityTest.kt @@ -75,15 +75,18 @@ class FilterActivityTest : TestCase() { // check if the recycler view is visible onView(withId(R.id.filterRecyclerView)).check(matches(isDisplayed())) + Thread.sleep(1500); + assertTrue(activityFilter.activity.subjectAdapter.getSubjects().size > 0) + // test select subject - onView(withId(R.id.filterRecyclerView)).perform(actionOnItemAtPosition(4, click())) + onView(withId(R.id.filterRecyclerView)).perform(actionOnItemAtPosition(0, click())) - assertTrue(activityFilter.activity.subjectAdapter.getSubjects()[4].isSelected) + assertTrue(activityFilter.activity.subjectAdapter.getSubjects()[0].isSelected) //test unselect subject - onView(withId(R.id.filterRecyclerView)).perform(actionOnItemAtPosition(4, click())) + onView(withId(R.id.filterRecyclerView)).perform(actionOnItemAtPosition(0, click())) - assertFalse(activityFilter.activity.subjectAdapter.getSubjects()[4].isSelected) + assertFalse(activityFilter.activity.subjectAdapter.getSubjects()[0].isSelected) } diff --git a/Tutorly/app/src/androidTest/java/com/example/tutorly/LoginRegisterTest.kt b/Tutorly/app/src/androidTest/java/com/example/tutorly/LoginRegisterTest.kt index 015cab3..048f432 100644 --- a/Tutorly/app/src/androidTest/java/com/example/tutorly/LoginRegisterTest.kt +++ b/Tutorly/app/src/androidTest/java/com/example/tutorly/LoginRegisterTest.kt @@ -93,6 +93,7 @@ class LoginRegisterTest { @Test fun validLogin() { + activityLogin.launchActivity(Intent()) // Type text and then press the button. onView(withId(R.id.input_username_login)) .perform(typeText(validEmailToBetyped), closeSoftKeyboard()) @@ -107,6 +108,7 @@ class LoginRegisterTest { @Test fun invalidEmailLogin() { + activityLogin.launchActivity(Intent()) // Type text and then press the button. onView(withId(R.id.input_username_login)) .perform(typeText(invalidEmailToBetyped), closeSoftKeyboard()) @@ -121,6 +123,7 @@ class LoginRegisterTest { @Test fun invalidPWLogin() { + activityLogin.launchActivity(Intent()) // Type text and then press the button. onView(withId(R.id.input_username_login)) .perform(typeText(validEmailToBetyped), closeSoftKeyboard()) @@ -136,7 +139,7 @@ class LoginRegisterTest { @Test fun gotoRegisterclick() { - activityRegister.launchActivity(Intent()) + activityLogin.launchActivity(Intent()) onView(withId(R.id.txt_gotoRegister)).perform(click()) // check @@ -188,6 +191,7 @@ class LoginRegisterTest { @Test fun validRegister() { + activityLogin.launchActivity(Intent()) onView(withId(R.id.txt_gotoRegister)).perform(click()) // Type text and then press the button. onView(withId(R.id.username_reg)) @@ -211,7 +215,10 @@ class LoginRegisterTest { @Test fun invalidRegister() { + activityLogin.launchActivity(Intent()) onView(withId(R.id.txt_gotoRegister)).perform(click()) + + // Type text and then press the button. onView(withId(R.id.username_reg)) .perform(typeText(validEmailToBeregistered), closeSoftKeyboard()) @@ -234,6 +241,7 @@ class LoginRegisterTest { @Test fun invalidRegisterOnInvalidEmail() { + activityLogin.launchActivity(Intent()) onView(withId(R.id.txt_gotoRegister)).perform(click()) // Type text and then press the button. onView(withId(R.id.username_reg)) diff --git a/Tutorly/app/src/androidTest/java/com/example/tutorly/NewTutorActivityTest.kt b/Tutorly/app/src/androidTest/java/com/example/tutorly/NewTutorActivityTest.kt index b4ea3c7..274776c 100644 --- a/Tutorly/app/src/androidTest/java/com/example/tutorly/NewTutorActivityTest.kt +++ b/Tutorly/app/src/androidTest/java/com/example/tutorly/NewTutorActivityTest.kt @@ -26,6 +26,14 @@ class NewTutorActivityTest : TestCase(){ true, false) + var activityMain: ActivityTestRule = ActivityTestRule( + MainActivity::class.java, + true, + false) + + var ruleSwitchToNewTutor = + ActivityTestRule(NewTutor::class.java, true, false) + @Before fun initIntent() { Intents.init() @@ -38,6 +46,30 @@ class NewTutorActivityTest : TestCase(){ @Test fun uiTest() { + activityNewTutor.launchActivity(Intent()) + Espresso.onView(ViewMatchers.withId(R.id.newTutorRecyclerView)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.btnApply)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.phoneNum)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.btn_change_lang_new_tutor)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.townAutocomplete_fragment)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + + @Test + fun toNewTutorActivity() + { + activityMain.launchActivity(Intent()) + Espresso.onView(ViewMatchers.withId(R.id.btn_new_tutor)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.btn_new_tutor)).perform(ViewActions.click()) + + // Check that only once run + ruleSwitchToNewTutor.launchActivity(Intent()) + Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name)) } } \ No newline at end of file diff --git a/Tutorly/app/src/androidTest/java/com/example/tutorly/TownSelectionTest.kt b/Tutorly/app/src/androidTest/java/com/example/tutorly/TownSelectionTest.kt index 98b5922..2cbf763 100644 --- a/Tutorly/app/src/androidTest/java/com/example/tutorly/TownSelectionTest.kt +++ b/Tutorly/app/src/androidTest/java/com/example/tutorly/TownSelectionTest.kt @@ -36,11 +36,18 @@ class TownSelectionTest { private lateinit var validCity: String - @get:Rule - var townSelection: ActivityScenarioRule - = ActivityScenarioRule(TownSelection::class.java) - var ruleFromMainTownSelection = - ActivityTestRule(MainActivity::class.java, true, false) + var activityMain: ActivityTestRule = ActivityTestRule( + MainActivity::class.java, + true, + false) + + var activityTownSelection: ActivityTestRule = ActivityTestRule( + TownSelection::class.java, + true, + false) + + var ruleSwitchToTownSel = + ActivityTestRule(TownSelection::class.java, true, false) @Before fun init() { @@ -50,12 +57,19 @@ class TownSelectionTest { validCity = "Graz" } + @After + fun tearDown() { + Intents.release() + } + @Test - /*fun getToTownSelection(){ + fun getToTownSelection(){ + activityMain.launchActivity(Intent()) onView(withId(R.id.btnTownSelection)).perform(click()) - ruleFromMainTownSelection.launchActivity(Intent()) + // check + ruleSwitchToTownSel.launchActivity(Intent()) intended(hasComponent(TownSelection::class.java.name), times(2)) - }*/ + } fun checkIfPopUpAppears() { @@ -64,9 +78,12 @@ class TownSelectionTest { java.util.concurrent.TimeUnit.SECONDS.sleep(2) } - /*@Test + @Test fun typeCity(){ //some problem with the test // Type text + activityTownSelection.launchActivity(Intent()) + /* + onView(withId(R.id.autocomplete_fragment)).perform(typeText("Salzburg"), closeSoftKeyboard()) onView(withId(R.id.autocomplete_fragment)) .perform(click()) java.util.concurrent.TimeUnit.SECONDS.sleep(2) @@ -77,14 +94,10 @@ class TownSelectionTest { // Check that the text was changed. onView(withId(R.id.autocomplete_fragment)) .check(matches(withText(validCity))) - - }*/ - /*@Test - fun cityTest() - { - onPlaceSelected() - }*/ - - - + */ + onView(withId(R.id.autocomplete_fragment)).check(matches(isDisplayed())) + onView(withId(R.id.textView3)).check(matches(isDisplayed())) + onView(withId(R.id.btn_change_lang_town_selection)).check(matches(isDisplayed())) + onView(withId(R.id.btnTownDone)).check(matches(isDisplayed())) + } } \ No newline at end of file diff --git a/Tutorly/app/src/androidTest/java/com/example/tutorly/TutorProfileTest.kt b/Tutorly/app/src/androidTest/java/com/example/tutorly/TutorProfileTest.kt index 7eb5d47..2c987f1 100644 --- a/Tutorly/app/src/androidTest/java/com/example/tutorly/TutorProfileTest.kt +++ b/Tutorly/app/src/androidTest/java/com/example/tutorly/TutorProfileTest.kt @@ -8,6 +8,8 @@ import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import androidx.test.rule.ActivityTestRule +import com.example.tutorly.database.LvlOfKnowledge +import com.example.tutorly.database.Tutor import junit.framework.TestCase import org.junit.After import org.junit.Before @@ -30,7 +32,10 @@ class TutorProfileTest : TestCase() { Intents.init() // change activity - val intent = Intent() + val tempTutor = Tutor("testId", "testName", "testLastname", "testEmail", hashMapOf( + "German" to LvlOfKnowledge.University, "Physics" to LvlOfKnowledge.School), "12345", "Graz") + + val intent = Intent().putExtra("Tutor", tempTutor) tutorProfileActivity.launchActivity(intent) } @@ -80,11 +85,11 @@ class TutorProfileTest : TestCase() { Espresso.onView(ViewMatchers.withId(R.id.txtTutorName)) .check(ViewAssertions.matches(ViewMatchers.withText("Name: ${TutorProfile.tutorName}"))) Espresso.onView(ViewMatchers.withId(R.id.txtTutorAge)) - .check(ViewAssertions.matches(ViewMatchers.withText("Age: ${TutorProfile.tutorAge}"))) + .check(ViewAssertions.matches(ViewMatchers.withText("Surname: ${TutorProfile.tutorSurnamne}"))) Espresso.onView(ViewMatchers.withId(R.id.txtTutorGender)) - .check(ViewAssertions.matches(ViewMatchers.withText("Gender: ${TutorProfile.tutorGender}"))) + .check(ViewAssertions.matches(ViewMatchers.withText("Phone: ${TutorProfile.tutorPhone}"))) Espresso.onView(ViewMatchers.withId(R.id.txtTutorMail)) - .check(ViewAssertions.matches(ViewMatchers.withText("E-Mail: ${TutorProfile.tutorMail}"))) + .check(ViewAssertions.matches(ViewMatchers.withText("Email: ${TutorProfile.tutorMail}"))) } @Test diff --git a/Tutorly/app/src/androidTest/java/com/example/tutorly/TutorlistTest.kt b/Tutorly/app/src/androidTest/java/com/example/tutorly/TutorlistTest.kt index 7dbcb70..6e2e7f8 100644 --- a/Tutorly/app/src/androidTest/java/com/example/tutorly/TutorlistTest.kt +++ b/Tutorly/app/src/androidTest/java/com/example/tutorly/TutorlistTest.kt @@ -2,8 +2,10 @@ package com.example.android.testing.espresso.BasicSample import android.app.Activity import android.content.Intent +import androidx.test.espresso.Espresso import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.* +import androidx.test.espresso.assertion.ViewAssertions import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.RecyclerViewActions import androidx.test.espresso.intent.Intents @@ -11,12 +13,15 @@ import androidx.test.espresso.intent.Intents.intended import androidx.test.espresso.intent.Intents.times import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent import androidx.test.espresso.matcher.RootMatchers.withDecorView +import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.* import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import androidx.test.rule.ActivityTestRule import com.example.tutorly.* +import com.example.tutorly.database.LvlOfKnowledge +import com.example.tutorly.database.Tutor import org.hamcrest.Matchers.not import org.junit.After import org.junit.Before @@ -36,16 +41,10 @@ class TutorlistTest { MainActivity::class.java, true, false) - - var activityTutorList: ActivityTestRule = ActivityTestRule( - TutorListActivity::class.java, - true, - false) - - /*var activityTutorProfile: ActivityTestRule = ActivityTestRule( + var activityTutorProfile: ActivityTestRule = ActivityTestRule( TutorProfile::class.java, true, - false)*/ + false) @@ -59,53 +58,38 @@ class TutorlistTest { Intents.release() } - /*@Test - fun tutorlistbuttonclick() { - - activityMain.launchActivity(Intent()) - onView(withId(R.id.btnTutorlist)).perform(click()) - - activityTutorList.launchActivity(Intent()) - intended(hasComponent(TutorListActivity::class.java.name), times(2)) - - } - @Test - fun tutorlistbuttonshown() { - + fun mainActivityDisplayed() + { activityMain.launchActivity(Intent()) - - onView(withId(R.id.btnTutorlist)).check(matches(isDisplayed())) - + // check if buttons visible + onView(withId(R.id.btnFilter)) + .check(matches(isDisplayed())) + onView(withId(R.id.btnTownSelection)) + .check(matches(isDisplayed())) + onView(withId(R.id.btn_new_tutor)) + .check(matches(isDisplayed())) + onView(withId(R.id.btn_change_lang_main_activity)) + .check(matches(isDisplayed())) } @Test - fun tutorlistbuttontext() { - - activityMain.launchActivity(Intent()) - - onView(withId(R.id.btnTutorlist)).check(matches(withText(R.string.show_tutors))) - - }*/ - - /*@Test fun tutorbuttonclick() { - activityTutorList.launchActivity(Intent()) + activityMain.launchActivity(Intent()) // Position 4 tests scrolling too - onView(withId(R.id.tutorsRecyclerView)).perform(RecyclerViewActions.actionOnItemAtPosition(4, click())) - - activityTutorProfile.launchActivity(Intent()) + onView(withId(R.id.tutorsRecyclerView)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click())) + val tempTutor = Tutor("testId", "testName", "testLastname", "testEmail", hashMapOf( + "German" to LvlOfKnowledge.University, "Physics" to LvlOfKnowledge.School), "12345", "Graz") + activityTutorProfile.launchActivity(Intent().putExtra("Tutor", tempTutor)) intended(hasComponent(TutorProfile::class.java.name), times(2)) - - }*/ + } @Test - fun tutorbuttonshown() { - - activityTutorList.launchActivity(Intent()) + fun tutorListShown() { + activityMain.launchActivity(Intent()) onView(withId(R.id.tutorsRecyclerView)).check(matches(isDisplayed())) } diff --git a/Tutorly/app/src/main/java/com/example/tutorly/TutorProfile.kt b/Tutorly/app/src/main/java/com/example/tutorly/TutorProfile.kt index 194268d..c7d9b54 100644 --- a/Tutorly/app/src/main/java/com/example/tutorly/TutorProfile.kt +++ b/Tutorly/app/src/main/java/com/example/tutorly/TutorProfile.kt @@ -26,11 +26,13 @@ class TutorProfile : AppCompatActivity() { setContentView(R.layout.activity_tutor_profile) val tutorInfo = intent.getSerializableExtra("Tutor") as Tutor - - tutorName = tutorInfo.firstName - tutorSurnamne = tutorInfo.lastName - tutorMail = tutorInfo.email - tutorPhone = tutorInfo.phoneNumber + if(tutorInfo != null) + { + tutorName = tutorInfo.firstName + tutorSurnamne = tutorInfo.lastName + tutorMail = tutorInfo.email + tutorPhone = tutorInfo.phoneNumber + } diff --git a/Tutorly/app/src/main/res/layout/activity_town_selection.xml b/Tutorly/app/src/main/res/layout/activity_town_selection.xml index 518ba2a..b0ebd1b 100644 --- a/Tutorly/app/src/main/res/layout/activity_town_selection.xml +++ b/Tutorly/app/src/main/res/layout/activity_town_selection.xml @@ -110,7 +110,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/btnNext" + app:layout_constraintTop_toBottomOf="@+id/btnTownDone" app:layout_constraintVertical_bias="0.617" />