Skip to content

Commit

Permalink
IDE-130 Fix spriteEqualBackgroundTest
Browse files Browse the repository at this point in the history
Remove spriteEqualBackgroundTest as an uiespresso test, instead implement as an Unit Test.
  • Loading branch information
dorianpercic committed Jul 30, 2023
1 parent 498a07f commit 37a2601
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@
import org.catrobat.catroid.formulaeditor.UserVariable;
import org.catrobat.catroid.test.utils.TestUtils;
import org.catrobat.catroid.utils.ShowTextUtils.AndroidStringProvider;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Locale;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import static org.catrobat.catroid.ui.settingsfragments.SettingsFragment.setLanguageSharedPreference;
import static org.catrobat.catroid.ui.settingsfragments.SettingsFragment.updateLocale;

@RunWith(AndroidJUnit4.class)
public class SpriteTest {

Expand Down Expand Up @@ -114,4 +120,16 @@ public void testUserVariableVisibilityOfLocalVariablesInDifferentScenes() {
userVariable = sprite2.getUserVariable(variableName);
assertTrue(userVariable.getVisible());
}

@Test
public void spriteEqualBackgroundTest() {
sprite.setName("Hintergrund");
updateLocale(ApplicationProvider.getApplicationContext(), new Locale("de"));
setLanguageSharedPreference(ApplicationProvider.getApplicationContext(), "de");
project.checkIfSpriteNameEqualBackground(ApplicationProvider.getApplicationContext());
Assert.assertNotEquals(sprite.getName(), "Hintergrund");
Assert.assertEquals(sprite.getName(), "Hintergrund (1)");
updateLocale(ApplicationProvider.getApplicationContext(), new Locale("en-gb"));
setLanguageSharedPreference(ApplicationProvider.getApplicationContext(), "en-gb");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@ import org.catrobat.catroid.runner.Flaky
import org.catrobat.catroid.test.utils.TestUtils
import org.catrobat.catroid.testsuites.annotations.Cat.AppUi
import org.catrobat.catroid.testsuites.annotations.Level.Smoke
import org.catrobat.catroid.ui.MainMenuActivity
import org.catrobat.catroid.ui.ProjectActivity
import org.catrobat.catroid.ui.settingsfragments.SettingsFragment.setLanguageSharedPreference
import org.catrobat.catroid.uiespresso.ui.fragment.rvutils.RecyclerViewInteractionWrapper
import org.catrobat.catroid.uiespresso.ui.fragment.rvutils.RecyclerViewInteractionWrapper.onRecyclerView
import org.catrobat.catroid.uiespresso.util.UiTestUtils
import org.catrobat.catroid.uiespresso.util.rules.BaseActivityTestRule
import org.catrobat.catroid.uiespresso.util.rules.FragmentActivityTestRule
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.instanceOf
Expand Down Expand Up @@ -224,38 +221,6 @@ class RenameSpriteTest {
.check(doesNotExist())
}

@Test
fun spriteEqualBackgroundTest() {
UiTestUtils.openActionBarMenu()
onView(withText(R.string.rename)).perform(click())
onRecyclerView().atPosition(0)
.check(matches(not(isDisplayed())))
onRecyclerView().atPosition(2)
.perform(click())
onView(withText(R.string.rename_sprite_dialog))
.inRoot(isDialog())
.check(matches(isDisplayed()))
setLanguageSharedPreference(ApplicationProvider.getApplicationContext(), "de")
val backgroundString = "Hintergrund"
onView(allOf(withText(secondSpriteName), isDisplayed()))
.perform(replaceText(backgroundString))
closeSoftKeyboard()
onView(allOf(withId(android.R.id.button1), withText(R.string.ok)))
.perform(click())
val mainMenu_ = BaseActivityTestRule(
MainMenuActivity::class.java, false, false
)
mainMenu_.launchActivity(null)
onView(withId(R.id.myProjectsTextView))
.check(matches(isDisplayed()))
.perform(click())
onView(withText(RenameSpriteTest::class.java.simpleName))
.check(matches(isDisplayed()))
.perform(click())
onView(withText("$backgroundString (1)"))
.check(matches(isDisplayed()))
}

private fun createProject(projectName: String) {
val project = Project(ApplicationProvider.getApplicationContext(), projectName)
project.defaultScene.addSprite(Sprite(firstSpriteName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
package org.catrobat.catroid.content;

import android.app.Activity;
import android.content.Context;
import android.os.Build;

Expand Down Expand Up @@ -537,15 +536,15 @@ public List<String> getSpriteNames(List<Sprite> spriteList) {
return spriteNames;
}

public void checkIfSpriteNameEqualBackground(Activity activity) {
public void checkIfSpriteNameEqualBackground(Context context) {
List<Sprite> spriteList =
new ArrayList<>(this.getSpriteListWithClones());
List<String> spriteNames = getSpriteNames(spriteList);
for (int sprite = 1; sprite < spriteList.size(); ++sprite) {
if (spriteList.get(sprite).getName().matches("[\\s]*" + activity.getString(R.string.background)
if (spriteList.get(sprite).getName().matches("[\\s]*" + context.getString(R.string.background)
+ "[\\s]*")) {
UniqueNameProvider name = new UniqueNameProvider();
String newSpriteName = name.getUniqueName(activity.getString(R.string.background), spriteNames);
String newSpriteName = name.getUniqueName(context.getString(R.string.background), spriteNames);
spriteList.get(sprite).setName(newSpriteName);
return;
}
Expand Down

0 comments on commit 37a2601

Please sign in to comment.