Skip to content

Commit

Permalink
Merge pull request Catrobat#4862 from becothas/IDE-199_fix_FormulaEdi…
Browse files Browse the repository at this point in the history
…torComputeDialogUserDefinedBrickInputTest

IDE-199 fix FormulaEditorComputeDialogUserDefinedBrickInputTest
  • Loading branch information
dorianpercic authored Aug 23, 2023
2 parents 8154ab3 + da3c3bc commit 67b5f59
Showing 1 changed file with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import org.catrobat.catroid.ProjectManager
import org.catrobat.catroid.R
import org.catrobat.catroid.content.Project
import org.catrobat.catroid.content.UserDefinedScript
import org.catrobat.catroid.content.bricks.ChangeSizeByNBrick
import org.catrobat.catroid.content.bricks.UserDefinedBrick
Expand All @@ -55,15 +54,16 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.koin.java.KoinJavaComponent.inject

@RunWith(Parameterized::class)
class FormulaEditorComputeDialogUserDefinedBrickInputTest(
private val name: String,
private val formula: Formula,
private val expectedString: String
) {
private lateinit var userDefinedBrick: UserDefinedBrick
private val label = UserDefinedBrickLabel("Label")
private var input = UserDefinedBrickInput("Input")
private val projectManager by inject(ProjectManager::class.java)

@Rule
@JvmField
Expand All @@ -73,56 +73,49 @@ class FormulaEditorComputeDialogUserDefinedBrickInputTest(
)

@Before
@kotlin.jvm.Throws(Exception::class)
fun setUp() {
UiTestUtils.createProjectAndGetStartScript(projectName)

val input = UserDefinedBrickInput("Input")
input.value = formula
val userDefinedScript = UserDefinedScript()
val label = UserDefinedBrickLabel("Label")
userDefinedBrick = UserDefinedBrick(mutableListOf<UserDefinedBrickData>(label, input))
userDefinedBrick.setCallingBrick(true)
userDefinedBrick.formulaMap.putIfAbsent(
input.inputFormulaField,
formula
)
userDefinedBrick.formulaMap.putIfAbsent(input.inputFormulaField, formula)
userDefinedScript.setUserDefinedBrickInputs(listOf(input))
userDefinedScript.scriptBrick = UserDefinedReceiverBrick(userDefinedBrick)
userDefinedScript.addBrick(
ChangeSizeByNBrick(Formula(FormulaElement(USER_DEFINED_BRICK_INPUT, input.name, null)))
)
ProjectManager.getInstance().currentSprite.addScript(userDefinedScript)
project = ProjectManager.getInstance().currentProject
projectManager.currentSprite.addScript(userDefinedScript)
baseActivityTestRule.launchActivity()
}

@After
@Throws(Exception::class)
fun tearDown() {
TestUtils.deleteProjects(projectName)
}

@Test
fun userDefinedBrickInputTest() {
openComputeDialog()
onView(withId(R.id.formula_editor_compute_dialog_textview))
.check(matches(ViewMatchers.withText(expectedString)))
onView(withId(R.id.formula_editor_compute_dialog_textview)).check(
matches(ViewMatchers.withText(expectedString))
)
}

private fun openComputeDialog() {
onView(withId(R.id.brick_change_size_by_edit_text))
.perform(click())
onFormulaEditor()
.performCompute()
onView(withId(R.id.brick_change_size_by_edit_text)).perform(click())
onFormulaEditor().performCompute()
}

companion object {
private val applicationContext: Context =
ApplicationProvider.getApplicationContext<Context>()
private val applicationContext: Context = ApplicationProvider.getApplicationContext()

private val trueString = applicationContext.getString(R.string.formula_editor_true)
private val falseString = applicationContext.getString(R.string.formula_editor_false)

private lateinit var project: Project
private const val projectName = "DataListFragmentBooleanUserVariablesTest"

@JvmStatic
Expand Down

0 comments on commit 67b5f59

Please sign in to comment.