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-176 Rework formula editor #4827

Merged
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
4 changes: 2 additions & 2 deletions catroid/build.gradle
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-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -361,7 +361,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
testImplementation project(path: ':catroid')
androidTestImplementation project(path: ':catroid')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public void tobBarVisibleAfterSelectingBrickFieldTest() {
onView(withId(R.id.find)).perform(click());
BrickDataInteractionWrapper.onBrickAtPosition(1).onFormulaTextField(R.id.brick_set_x_edit_text).perform(click());
pressBack();
pressBack();
onView(withId(R.id.toolbar)).check(matches(isDisplayed()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public void testDoesFormulaFragmentReturnCorrectlyAfterVisualPlacement() {
onFormulaEditor()
.check(matches(isDisplayed()));
pressBack();
pressBack();
isBackInScriptFragment();
}

Expand All @@ -228,7 +227,6 @@ public void testNoRecursiveOpeningOfFormulaEditors() {
openFormulaEditorFragmentFromEditTextX();
openFormulaEditorFragmentFromEditTextX();
pressBack();
pressBack();
isBackInScriptFragment();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2023 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.formulaeditor

import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.doubleClick
import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.catrobat.catroid.ProjectManager
import org.catrobat.catroid.R
import org.catrobat.catroid.content.Project
import org.catrobat.catroid.content.Script
import org.catrobat.catroid.content.Sprite
import org.catrobat.catroid.content.StartScript
import org.catrobat.catroid.content.bricks.SetVariableBrick
import org.catrobat.catroid.formulaeditor.UserVariable
import org.catrobat.catroid.test.utils.TestUtils
import org.catrobat.catroid.ui.SpriteActivity
import org.catrobat.catroid.uiespresso.formulaeditor.utils.FormulaEditorWrapper
import org.catrobat.catroid.uiespresso.util.rules.FragmentActivityTestRule
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.koin.java.KoinJavaComponent.inject

@RunWith(AndroidJUnit4::class)
class ClipboardTest {

val projectManager: ProjectManager by inject(ProjectManager::class.java)

@JvmField
@Rule
var baseActivityTestRule = FragmentActivityTestRule(
SpriteActivity::class.java,
SpriteActivity.EXTRA_FRAGMENT_POSITION,
SpriteActivity.FRAGMENT_SCRIPTS
)

@Before
fun setUp() {
createProject()
baseActivityTestRule.launchActivity()
}

@Test
fun copyAndPasteTest() {
onView(withId(R.id.brick_set_variable_edit_text)).perform(click())
FormulaEditorWrapper.onFormulaEditor().performEnterNumber(12_345)
onView(withId(R.id.formula_editor_edit_field)).perform(doubleClick())
onView(withId(R.id.formula_editor_keyboard_copy)).perform(click())
FormulaEditorWrapper.onFormulaEditor().performBackspace()
onView(withId(R.id.formula_editor_edit_field)).perform(longClick())
onView(withId(R.id.formula_editor_keyboard_paste)).perform(click())
FormulaEditorWrapper.onFormulaEditor().checkShows("12345")
}

@After
fun tearDown() {
baseActivityTestRule.finishActivity()
TestUtils.deleteProjects(PROJECT_NAME)
}

private fun createProject(): Project {
val project = Project(ApplicationProvider.getApplicationContext(), PROJECT_NAME)
val sprite = Sprite("testSprite")
val script: Script = StartScript()
val setVariableBrick = SetVariableBrick()
val userVariable = UserVariable("testVariable")
project.addUserVariable(userVariable)
setVariableBrick.userVariable = userVariable
script.addBrick(setVariableBrick)
sprite.addScript(script)
project.defaultScene.addSprite(sprite)
projectManager.currentProject = project
projectManager.currentSprite = sprite
return project
}

companion object {
private const val PROJECT_NAME = "ClipboardTest"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public void testUndoFormulaWithNoChanges() {
.perform(click());

pressBack();
pressBack();

onView(withId(R.id.menu_undo))
.check(doesNotExist());
Expand Down Expand Up @@ -178,10 +177,8 @@ public void testUndoFormulaWithRevertedChanges() {

onView(withId(R.id.brick_place_at_edit_text_x))
.perform(click());
onView(withText(R.string.brick_context_dialog_formula_edit_brick))
.perform(click());
onFormulaEditor()
.performEnterFormula("0");
onView(withText(R.string.brick_context_dialog_formula_edit_brick)).perform(click());
onFormulaEditor().performEnterFormula("0");

pressBack();

Expand Down Expand Up @@ -290,26 +287,14 @@ public void testUndoFormulaDeleteVariable() {
@Test
public void testUndoFormulaRenameVariable() {
onBrickAtPosition(brickPosition).checkShowsText(R.string.brick_place_at);

onView(withId(R.id.brick_place_at_edit_text_x))
.perform(click());
onView(withText(R.string.brick_context_dialog_formula_edit_brick))
.perform(click());

onFormulaEditor()
.performOpenDataFragment();

onDataList().onVariableAtPosition(0)
.performRename(NEW_VARIABLE_NAME);

onDataList()
.performClose();

pressBack();
onView(withId(R.id.brick_place_at_edit_text_x)).perform(click());
onView(withText(R.string.brick_context_dialog_formula_edit_brick)).perform(click());
onFormulaEditor().performOpenDataFragment();
onDataList().onVariableAtPosition(0).performRename(NEW_VARIABLE_NAME);
onDataList().performClose();
pressBack();

onView(withId(R.id.menu_undo))
.check(matches(isDisplayed()));
onView(withId(R.id.menu_undo)).check(matches(isDisplayed()));

assertNull(ProjectManager.getInstance().getCurrentProject().getUserVariable(VARIABLE_NAME));
assertNotNull(ProjectManager.getInstance().getCurrentProject().getUserVariable(NEW_VARIABLE_NAME));
Expand Down
Loading