Skip to content

Commit

Permalink
CATROID-986 Apply single choice operations immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
l-ilma committed Nov 1, 2022
1 parent 75198cb commit 8408c3e
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +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 androidx.test.InstrumentationRegistry.getInstrumentation;
import static org.koin.java.KoinJavaComponent.inject;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static androidx.test.espresso.action.ViewActions.click;
Expand All @@ -63,59 +59,67 @@
@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 copyLookOneElementListTest() throws IOException {
ActionUtils.addLook(projectManager, testLookName1);

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 copyLookTest() {
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
public void copyLookMultipleElementsListTest() throws IOException {
ActionUtils.addLook(projectManager, testLookName1);
ActionUtils.addLook(projectManager, testLookName2);

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

onRecyclerView().atPosition(0)
.performCheckItem();
.performCheckItem();

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

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

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

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,33 +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 androidx.test.InstrumentationRegistry.getInstrumentation;
import static org.koin.java.KoinJavaComponent.inject;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static androidx.test.espresso.action.ViewActions.click;
Expand All @@ -63,58 +59,70 @@
@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();
baseActivityTestRule.launchActivity();
}

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

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

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() {
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
public void copySoundMultipleElementsListTest() throws IOException {
ActionUtils.addSound(projectManager, testSoundName1);
ActionUtils.addSound(projectManager, testSoundName2);

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

onRecyclerView().atPosition(0)
.performCheckItem();

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()));
}

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@

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.UiTestUtils;
import org.catrobat.catroid.uiespresso.util.rules.FragmentActivityTestRule;
import org.junit.Before;
Expand All @@ -41,19 +40,16 @@
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.hamcrest.Matchers.allOf;
import static org.koin.java.KoinJavaComponent.inject;

import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static androidx.test.espresso.action.ViewActions.click;
Expand All @@ -67,6 +63,8 @@
@RunWith(AndroidJUnit4.class)
public class DeleteLookTest {

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

@Rule
public FragmentActivityTestRule<SpriteActivity> baseActivityTestRule = new
FragmentActivityTestRule<>(SpriteActivity.class, SpriteActivity.EXTRA_FRAGMENT_POSITION,
Expand All @@ -75,15 +73,18 @@ public class DeleteLookTest {
private String toBeDeletedLookName = "testLook2";

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

@Category({Cat.AppUi.class, Level.Smoke.class})
@Test
public void deleteLookTest() {
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
public void deleteLookMultipleElementsListTest() throws IOException {
ActionUtils.addLook(projectManager, "testLook1");
ActionUtils.addLook(projectManager, toBeDeletedLookName);

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

onRecyclerView().atPosition(1)
Expand All @@ -108,10 +109,24 @@ public void deleteLookTest() {
.check(doesNotExist());
}

@Test
public void deleteLookSingleElementListTest() throws IOException {
ActionUtils.addLook(projectManager, toBeDeletedLookName);

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

onView(withText(toBeDeletedLookName))
.check(doesNotExist());
}

@Category({Cat.AppUi.class, Level.Smoke.class})
@Test
public void cancelDeleteLookTest() {
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
public void cancelDeleteLookTest() throws IOException {
ActionUtils.addLook(projectManager, "testLook1");
ActionUtils.addLook(projectManager, toBeDeletedLookName);

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

onRecyclerView().atPosition(1)
Expand All @@ -136,40 +151,15 @@ public void cancelDeleteLookTest() {
.check(matches(isDisplayed()));
}

private void createProject() throws IOException {
private void createProject() {
String projectName = "deleteLookFragmentTest";
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);

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

List<LookData> lookDataList = ProjectManager.getInstance().getCurrentSprite().getLookList();
LookData lookData = new LookData();
lookData.setFile(imageFile);
lookData.setName("testLook1");
lookDataList.add(lookData);

LookData lookData2 = new LookData();
lookData2.setFile(imageFile2);
lookData2.setName(toBeDeletedLookName);
lookDataList.add(lookData2);
}
}
Loading

0 comments on commit 8408c3e

Please sign in to comment.