|
| 1 | +/* |
| 2 | + * Catroid: An on-device visual programming system for Android devices |
| 3 | + * Copyright (C) 2010-2020 The Catrobat Team |
| 4 | + * (<http://developer.catrobat.org/credits>) |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Affero General Public License as |
| 8 | + * published by the Free Software Foundation, either version 3 of the |
| 9 | + * License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * An additional term exception under section 7 of the GNU Affero |
| 12 | + * General Public License, version 3, is available at |
| 13 | + * http://developer.catrobat.org/license_additional_term |
| 14 | + * |
| 15 | + * This program is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU Affero General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU Affero General Public License |
| 21 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | + */ |
| 23 | + |
| 24 | +package org.catrobat.catroid.uiespresso.ui.dialog; |
| 25 | + |
| 26 | +import org.catrobat.catroid.R; |
| 27 | +import org.catrobat.catroid.content.Script; |
| 28 | +import org.catrobat.catroid.content.bricks.ChangeSizeByNBrick; |
| 29 | +import org.catrobat.catroid.ui.SpriteActivity; |
| 30 | +import org.catrobat.catroid.uiespresso.content.brick.utils.BrickTestUtils; |
| 31 | +import org.catrobat.catroid.uiespresso.formulaeditor.utils.FormulaEditorWrapper; |
| 32 | +import org.catrobat.catroid.uiespresso.util.UiTestUtils; |
| 33 | +import org.catrobat.catroid.uiespresso.util.rules.FragmentActivityTestRule; |
| 34 | +import org.junit.Before; |
| 35 | +import org.junit.Rule; |
| 36 | +import org.junit.Test; |
| 37 | +import org.junit.runner.RunWith; |
| 38 | + |
| 39 | +import androidx.test.ext.junit.runners.AndroidJUnit4; |
| 40 | + |
| 41 | +import static org.catrobat.catroid.uiespresso.content.brick.utils.BrickDataInteractionWrapper.onBrickAtPosition; |
| 42 | +import static org.catrobat.catroid.uiespresso.formulaeditor.utils.FormulaEditorWrapper.onFormulaEditor; |
| 43 | + |
| 44 | +import static androidx.test.espresso.Espresso.onView; |
| 45 | +import static androidx.test.espresso.action.ViewActions.click; |
| 46 | +import static androidx.test.espresso.assertion.ViewAssertions.matches; |
| 47 | +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; |
| 48 | +import static androidx.test.espresso.matcher.ViewMatchers.withHint; |
| 49 | +import static androidx.test.espresso.matcher.ViewMatchers.withId; |
| 50 | +import static androidx.test.espresso.matcher.ViewMatchers.withText; |
| 51 | + |
| 52 | +@RunWith(AndroidJUnit4.class) |
| 53 | +public class JsonExtractorDialogTest { |
| 54 | + @Rule |
| 55 | + public FragmentActivityTestRule<SpriteActivity> baseActivityTestRule = new |
| 56 | + FragmentActivityTestRule<>(SpriteActivity.class, SpriteActivity.EXTRA_FRAGMENT_POSITION, SpriteActivity.FRAGMENT_SCRIPTS); |
| 57 | + @Before |
| 58 | + public void setUp() { |
| 59 | + Script script = BrickTestUtils.createProjectAndGetStartScript("HtmlExtractorDialogTest"); |
| 60 | + script.addBrick(new ChangeSizeByNBrick(0)); |
| 61 | + baseActivityTestRule.launchActivity(); |
| 62 | + |
| 63 | + onBrickAtPosition(1).onChildView(withId(R.id.brick_change_size_by_edit_text)) |
| 64 | + .perform(click()); |
| 65 | + openJsonExtractor(); |
| 66 | + } |
| 67 | + |
| 68 | + private void openJsonExtractor() { |
| 69 | + String regularExpressionAssistant = |
| 70 | + "\t\t\t\t\t" + UiTestUtils.getResourcesString(R.string.formula_editor_function_regex_assistant); |
| 71 | + onFormulaEditor().performOpenCategory(FormulaEditorWrapper.Category.FUNCTIONS).performSelect(regularExpressionAssistant); |
| 72 | + onView(withText(R.string.formula_editor_function_regex_json_extractor_title)).perform(click()); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testHtmlExtractorDialogTitle() { |
| 77 | + onView(withText(R.string.formula_editor_function_regex_json_extractor_title)).check(matches(isDisplayed())); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testHtmlExtractorDialogKeywordHint() { |
| 82 | + onView(withHint(R.string.keyword_label)).check(matches(isDisplayed())); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + public void testHtmlExtractorDialogOkButton() { |
| 87 | + onView(withText(R.string.ok)).check(matches(isDisplayed())); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testHtmlExtractorDialogCancelButton() { |
| 92 | + onView(withText(R.string.cancel)).check(matches(isDisplayed())); |
| 93 | + } |
| 94 | +} |
0 commit comments