Skip to content

Commit

Permalink
CATROID-1130 Refactor TermsOfUseDialogTest and AboutDialogTest to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal1707 authored and blindguardian50 committed Jun 30, 2021
1 parent b2695f8 commit c9310d9
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 236 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2021 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.catrobat.catroid.uiespresso.ui.dialog

import android.preference.PreferenceManager
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.catrobat.catroid.BuildConfig
import org.catrobat.catroid.R
import org.catrobat.catroid.common.Constants
import org.catrobat.catroid.common.SharedPreferenceKeys
import org.catrobat.catroid.testsuites.annotations.Cat.AppUi
import org.catrobat.catroid.testsuites.annotations.Level.Smoke
import org.catrobat.catroid.ui.MainMenuActivity
import org.catrobat.catroid.uiespresso.util.rules.DontGenerateDefaultProjectActivityTestRule
import org.catrobat.catroid.utils.Utils
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.experimental.categories.Category
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class AboutDialogTest {
@get:Rule
var baseActivityTestRule = DontGenerateDefaultProjectActivityTestRule(
MainMenuActivity::class.java, true, false
)

private var bufferedPrivacyPolicyPreferenceSetting = 0

@Before
@Throws(Exception::class)
fun setUp() {
val sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(ApplicationProvider.getApplicationContext())
bufferedPrivacyPolicyPreferenceSetting = sharedPreferences
.getInt(SharedPreferenceKeys.AGREED_TO_PRIVACY_POLICY_VERSION, 0)
sharedPreferences
.edit()
.putInt(
SharedPreferenceKeys.AGREED_TO_PRIVACY_POLICY_VERSION,
Constants.CATROBAT_TERMS_OF_USE_ACCEPTED
)
.commit()
baseActivityTestRule.launchActivity(null)
}

@After
fun tearDown() {
PreferenceManager.getDefaultSharedPreferences(ApplicationProvider.getApplicationContext())
.edit()
.putInt(
SharedPreferenceKeys.AGREED_TO_PRIVACY_POLICY_VERSION,
bufferedPrivacyPolicyPreferenceSetting
)
.commit()
}

@Category(AppUi::class, Smoke::class)
@Test
fun aboutDialogTest() {
Espresso.openActionBarOverflowOrOptionsMenu(baseActivityTestRule.activity)

Espresso.onView(ViewMatchers.withText(R.string.main_menu_about))
.perform(ViewActions.click())

Espresso.onView(ViewMatchers.withText(R.string.dialog_about_title))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

Espresso.onView(ViewMatchers.withText(R.string.dialog_about_license_info))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

Espresso.onView(ViewMatchers.withText(R.string.dialog_about_license_link_text))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

Espresso.onView(ViewMatchers.withText(R.string.dialog_about_catrobat_link_text))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

Espresso.onView(ViewMatchers.withId(R.id.dialog_about_text_view_catrobat_version_name))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

Assert.assertNotNull(Utils.getVersionName(ApplicationProvider.getApplicationContext()))

Assert.assertNotEquals("", BuildConfig.VERSION_NAME)

Espresso.onView(ViewMatchers.withText(R.string.ok))
.perform(ViewActions.click())

Espresso.onView(ViewMatchers.withText(R.string.dialog_about_title))
.check(ViewAssertions.doesNotExist())
}
}

This file was deleted.

Loading

0 comments on commit c9310d9

Please sign in to comment.