Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-142 Fix testHtmlExtractorDialogNotFoundMessage #5017

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -37,15 +37,13 @@

import androidx.test.ext.junit.runners.AndroidJUnit4;

import static org.hamcrest.Matchers.not;
import static org.catrobat.catroid.uiespresso.content.brick.utils.BrickDataInteractionWrapper.onBrickAtPosition;
import static org.catrobat.catroid.uiespresso.formulaeditor.utils.FormulaEditorWrapper.onFormulaEditor;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.withDecorView;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withHint;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
Expand Down Expand Up @@ -93,15 +91,6 @@ public void testHtmlExtractorDialogCancelButton() {
onView(withText(R.string.cancel)).check(matches(isDisplayed()));
}

@Test
public void testHtmlExtractorDialogNotFoundMessage() {
onView(withHint(R.string.keyword_label)).perform(typeText("Not"));
onView(withHint(R.string.html_label)).perform(typeText("Found"));
onView(withText(R.string.ok)).perform(click());

onView(withText(R.string.formula_editor_function_regex_html_extractor_not_found)).inRoot(withDecorView(not(baseActivityTestRule.getActivity().getWindow().getDecorView()))).check(matches(isDisplayed()));
}

private void openHtmlExtractor() {
String regularExpressionAssistant =
"\t\t\t\t\t" + UiTestUtils.getResourcesString(R.string.formula_editor_function_regex_assistant);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2024 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.test.ui.regexassistant

import android.app.Activity
import org.catrobat.catroid.R
import org.catrobat.catroid.utils.HtmlRegexExtractor
import org.catrobat.catroid.utils.ToastUtil
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito.times
import org.powermock.api.mockito.PowerMockito.mockStatic
import org.powermock.api.mockito.PowerMockito.verifyStatic
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner

@RunWith(PowerMockRunner::class)
@PrepareForTest(ToastUtil::class)
class HtmlExtractorErrorHandlingTest {
private lateinit var htmlExtractor: HtmlRegexExtractor
private lateinit var context: Activity

@Before
fun setUp() {
context = Activity()
htmlExtractor = HtmlRegexExtractor(context)
}

@Test
fun testHtmlExtractorDialogNotFoundMessage() {
mockStatic(ToastUtil::class.java)
htmlExtractor.searchKeyword("Not", "Found")
verifyStatic(ToastUtil::class.java, times(1))
ToastUtil.showError(
eq(context),
eq(R.string.formula_editor_function_regex_html_extractor_not_found)
)
}
}