From 94ee183139ef83cb56937c3c24fb17af2b0b8323 Mon Sep 17 00:00:00 2001 From: MohitMali Date: Mon, 5 Sep 2022 15:13:50 +0530 Subject: [PATCH] Convert StandardActions.java into kotlin --- .../kiwixmobile/utils/StandardActions.java | 60 ------------------ .../kiwixmobile/utils/StandardActions.kt | 63 +++++++++++++++++++ 2 files changed, 63 insertions(+), 60 deletions(-) delete mode 100644 app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.java create mode 100644 app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.java b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.java deleted file mode 100644 index 40758c3a5..000000000 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package org.kiwix.kiwixmobile.utils; - -import android.util.Log; -import com.adevinta.android.barista.interaction.BaristaClickInteractions; -import com.adevinta.android.barista.interaction.BaristaDrawerInteractions; -import com.adevinta.android.barista.interaction.BaristaSleepInteractions; -import org.kiwix.kiwixmobile.R; - -import static androidx.test.espresso.Espresso.onData; -import static androidx.test.espresso.action.ViewActions.longClick; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static com.adevinta.android.barista.interaction.BaristaDialogInteractions.clickDialogPositiveButton; -import static org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS; -import static org.kiwix.kiwixmobile.testutils.TestUtils.getResourceString; -import static org.kiwix.kiwixmobile.testutils.TestUtils.withContent; - -/** - * Created by mhutti1 on 27/04/17. - */ - -public class StandardActions { - - public static void enterSettings() { - BaristaSleepInteractions.sleep(TEST_PAUSE_MS); - BaristaClickInteractions.clickOn(getResourceString(R.string.menu_settings)); - } - - public static void openDrawer() { - BaristaDrawerInteractions.openDrawer(); - } - - public static void deleteZimIfExists(String zimName, Integer adapterId) { - try { - onData(withContent(zimName)).inAdapterView(withId(adapterId)).perform(longClick()); - clickDialogPositiveButton(); - Log.i("TEST_DELETE_ZIM", "Successfully deleted ZIM file [" + zimName + "]"); - } catch (RuntimeException e) { - Log.i("TEST_DELETE_ZIM", "Failed to delete ZIM file [" + zimName + "]... " + - "Probably because it doesn't exist"); - } - } -} - diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt new file mode 100644 index 000000000..cb437cded --- /dev/null +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt @@ -0,0 +1,63 @@ +/* + * Kiwix Android + * Copyright (c) 2019 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package org.kiwix.kiwixmobile.utils + +import android.util.Log +import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn +import com.adevinta.android.barista.interaction.BaristaSleepInteractions +import org.kiwix.kiwixmobile.R +import androidx.test.espresso.Espresso +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.matcher.ViewMatchers +import com.adevinta.android.barista.interaction.BaristaDialogInteractions +import com.adevinta.android.barista.interaction.BaristaDrawerInteractions +import org.kiwix.kiwixmobile.testutils.TestUtils +import java.lang.RuntimeException + +/** + * Created by mhutti1 on 27/04/17. + */ +object StandardActions { + fun enterSettings() { + BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong()) + clickOn(TestUtils.getResourceString(R.string.menu_settings)) + } + + fun openDrawer() { + BaristaDrawerInteractions.openDrawer() + } + + @JvmStatic + fun deleteZimIfExists(zimName: String, adapterId: Int) { + try { + Espresso.onData(TestUtils.withContent(zimName)).inAdapterView( + ViewMatchers.withId( + adapterId + ) + ).perform(ViewActions.longClick()) + BaristaDialogInteractions.clickDialogPositiveButton() + Log.i("TEST_DELETE_ZIM", "Successfully deleted ZIM file [$zimName]") + } catch (e: RuntimeException) { + Log.i( + "TEST_DELETE_ZIM", + "Failed to delete ZIM file [" + zimName + "]... " + + "Probably because it doesn't exist" + ) + } + } +}