Skip to content

Commit

Permalink
CATROID-986 Apply single choice operations immediately (#4650)
Browse files Browse the repository at this point in the history
  • Loading branch information
l-ilma authored Sep 11, 2024
1 parent 6f3d084 commit 376122e
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@

import androidx.test.core.app.ApplicationProvider;

import static org.koin.java.KoinJavaComponent.inject;

public final class BrickTestUtils {
private BrickTestUtils() {
throw new AssertionError();
}

public static Script createEmptyCastProjectAndGetStartScript(String projectName) {
ProjectManager projectManager = inject(ProjectManager.class).getValue();
Project project = new Project(ApplicationProvider.getApplicationContext(), projectName, false, true);
Sprite sprite = new Sprite("testSprite");
Script script = new StartScript();
sprite.addScript(script);
project.getDefaultScene().addSprite(sprite);
ProjectManager.getInstance().setCurrentProject(project);
ProjectManager.getInstance().setCurrentSprite(sprite);
ProjectManager.getInstance().setCurrentlyEditedScene(project.getDefaultScene());
projectManager.setCurrentProject(project);
projectManager.setCurrentSprite(sprite);
projectManager.setCurrentlyEditedScene(project.getDefaultScene());
return script;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,29 @@

import org.catrobat.catroid.ProjectManager;
import org.catrobat.catroid.R;
import org.catrobat.catroid.common.LookData;
import org.catrobat.catroid.content.Project;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.io.ResourceImporter;
import org.catrobat.catroid.io.XstreamSerializer;
import org.catrobat.catroid.testsuites.annotations.Cat;
import org.catrobat.catroid.testsuites.annotations.Level;
import org.catrobat.catroid.ui.SpriteActivity;
import org.catrobat.catroid.uiespresso.ui.fragment.actionutils.ActionUtils;
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.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.IOException;
import java.util.List;

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

import static org.catrobat.catroid.common.Constants.IMAGE_DIRECTORY_NAME;
import static org.catrobat.catroid.uiespresso.ui.fragment.rvutils.RecyclerViewInteractionWrapper.onRecyclerView;
import static org.koin.java.KoinJavaComponent.inject;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
Expand All @@ -62,34 +60,56 @@
@RunWith(AndroidJUnit4.class)
public class CopyLookTest {

final ProjectManager projectManager = inject(ProjectManager.class).getValue();

@Rule
public FragmentActivityTestRule<SpriteActivity> baseActivityTestRule = new
FragmentActivityTestRule<>(SpriteActivity.class, SpriteActivity.EXTRA_FRAGMENT_POSITION,
SpriteActivity.FRAGMENT_LOOKS);

private String toBeCopiedLookName = "testLook";
private String testLookName1 = "testLook";
private String testLookName2 = "testLook2";
private String toBeCopiedLookName1 = "testLook (1)";

@Before
public void setUp() throws Exception {
public void setUp() {
createProject();
baseActivityTestRule.launchActivity();
}

@After
public void tearDown() {
baseActivityTestRule.getActivity().finish();
}

@Category({Cat.AppUi.class, Level.Smoke.class})
@Test
public void copyLookTest() {
public void copyLookOneElementListTest() throws IOException {
ActionUtils.addLook(projectManager, testLookName1);
baseActivityTestRule.launchActivity();

openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getInstrumentation().getTargetContext());
onView(withText(R.string.copy)).perform(click());

onView(withText(toBeCopiedLookName1))
.check(matches(isDisplayed()));
}

@Category({Cat.AppUi.class, Level.Smoke.class})
@Test
public void copyLookMultipleElementsListTest() throws IOException {
ActionUtils.addLook(projectManager, testLookName1);
ActionUtils.addLook(projectManager, testLookName2);
baseActivityTestRule.launchActivity();

openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext());
onView(withText(R.string.copy)).perform(click());

onRecyclerView().atPosition(0)
.performCheckItemClick();
.performCheckItemClick();

onView(withId(R.id.confirm)).perform(click());

onView(withText(toBeCopiedLookName))
.check(matches(isDisplayed()));

onView(withText(toBeCopiedLookName + " (1)"))
onView(withText(toBeCopiedLookName1))
.check(matches(isDisplayed()));
}

Expand All @@ -103,28 +123,15 @@ public void selectFragmentToCopyTest() {
onRecyclerView().atPosition(0).performCheckItemCheck();
}

private void createProject() throws IOException {
private void createProject() {
String projectName = "copyLookFragmentTest";
Project project = new Project(ApplicationProvider.getApplicationContext(), projectName);

Sprite sprite = new Sprite("testSprite");
project.getDefaultScene().addSprite(sprite);

ProjectManager.getInstance().setCurrentProject(project);
ProjectManager.getInstance().setCurrentSprite(sprite);
projectManager.setCurrentProject(project);
projectManager.setCurrentSprite(sprite);
XstreamSerializer.getInstance().saveProject(project);

File imageFile = ResourceImporter.createImageFileFromResourcesInDirectory(
InstrumentationRegistry.getInstrumentation().getContext().getResources(),
org.catrobat.catroid.test.R.drawable.catroid_banzai,
new File(project.getDefaultScene().getDirectory(), IMAGE_DIRECTORY_NAME),
"catroid_sunglasses.png",
1);

List<LookData> lookDataList = ProjectManager.getInstance().getCurrentSprite().getLookList();
LookData lookData = new LookData();
lookData.setFile(imageFile);
lookData.setName(toBeCopiedLookName);
lookDataList.add(lookData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,29 @@

import org.catrobat.catroid.ProjectManager;
import org.catrobat.catroid.R;
import org.catrobat.catroid.common.SoundInfo;
import org.catrobat.catroid.content.Project;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.io.ResourceImporter;
import org.catrobat.catroid.io.XstreamSerializer;
import org.catrobat.catroid.testsuites.annotations.Cat;
import org.catrobat.catroid.testsuites.annotations.Level;
import org.catrobat.catroid.ui.SpriteActivity;
import org.catrobat.catroid.uiespresso.ui.fragment.actionutils.ActionUtils;
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.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.IOException;
import java.util.List;

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

import static org.catrobat.catroid.common.Constants.SOUND_DIRECTORY_NAME;
import static org.catrobat.catroid.uiespresso.ui.fragment.rvutils.RecyclerViewInteractionWrapper.onRecyclerView;
import static org.koin.java.KoinJavaComponent.inject;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
Expand All @@ -62,22 +60,47 @@
@RunWith(AndroidJUnit4.class)
public class CopySoundTest {

final ProjectManager projectManager = inject(ProjectManager.class).getValue();

@Rule
public FragmentActivityTestRule<SpriteActivity> baseActivityTestRule = new
FragmentActivityTestRule<>(SpriteActivity.class, SpriteActivity.EXTRA_FRAGMENT_POSITION,
SpriteActivity.FRAGMENT_SOUNDS);

private String toBeCopiedSoundName = "testSound";
private String testSoundName1 = "testSound";
private String testSoundName2 = "testSound2";
private String toBeCopiedSoundName1 = "testSound (1)";

@Before
public void setUp() throws Exception {
public void setUp() {
createProject();
}

@After
public void tearDown() {
baseActivityTestRule.getActivity().finish();
}

@Category({Cat.AppUi.class, Level.Smoke.class})
@Test
public void copyLookOneElementListTest() throws IOException {
ActionUtils.addSound(projectManager, testSoundName1);
baseActivityTestRule.launchActivity();

openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getInstrumentation().getTargetContext());
onView(withText(R.string.copy)).perform(click());

onView(withText(toBeCopiedSoundName1))
.check(matches(isDisplayed()));
}

@Category({Cat.AppUi.class, Level.Smoke.class})
@Test
public void copySoundTest() {
public void copySoundMultipleElementsListTest() throws IOException {
ActionUtils.addSound(projectManager, testSoundName1);
ActionUtils.addSound(projectManager, testSoundName2);
baseActivityTestRule.launchActivity();

openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getInstrumentation().getTargetContext());
onView(withText(R.string.copy)).perform(click());

Expand All @@ -86,10 +109,10 @@ public void copySoundTest() {

onView(withId(R.id.confirm)).perform(click());

onView(withText(toBeCopiedSoundName))
onView(withText(testSoundName1))
.check(matches(isDisplayed()));

onView(withText(toBeCopiedSoundName + " (1)"))
onView(withText(toBeCopiedSoundName1))
.check(matches(isDisplayed()));
}

Expand All @@ -103,27 +126,15 @@ public void selectFragmentToCopyTest() {
onRecyclerView().atPosition(0).performCheckItemCheck();
}

private void createProject() throws IOException {
private void createProject() {
String projectName = "copySoundFragmentTest";
Project project = new Project(ApplicationProvider.getApplicationContext(), projectName);

Sprite sprite = new Sprite("testSprite");
project.getDefaultScene().addSprite(sprite);

ProjectManager.getInstance().setCurrentProject(project);
ProjectManager.getInstance().setCurrentSprite(sprite);
projectManager.setCurrentProject(project);
projectManager.setCurrentSprite(sprite);
XstreamSerializer.getInstance().saveProject(project);

File soundFile = ResourceImporter.createSoundFileFromResourcesInDirectory(
InstrumentationRegistry.getInstrumentation().getContext().getResources(),
org.catrobat.catroid.test.R.raw.longsound,
new File(project.getDefaultScene().getDirectory(), SOUND_DIRECTORY_NAME),
"longsound.mp3");

List<SoundInfo> soundInfoList = ProjectManager.getInstance().getCurrentSprite().getSoundList();
SoundInfo soundInfo = new SoundInfo();
soundInfo.setFile(soundFile);
soundInfo.setName(toBeCopiedSoundName);
soundInfoList.add(soundInfo);
}
}
Loading

0 comments on commit 376122e

Please sign in to comment.