Skip to content

Commit

Permalink
Merge pull request #3005 from Catrobat/hotfix-0.9.44
Browse files Browse the repository at this point in the history
Hotfix-0.9.44
  • Loading branch information
wslany authored Oct 25, 2018
2 parents 90ca0ad + 1464b1a commit 3fda750
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 14 deletions.
4 changes: 2 additions & 2 deletions catroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ android {
targetSdkVersion 22
applicationId appId
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode 50
versionCode 51
println "VersionCode is $versionCode"
versionName "0.9.42"
versionName "0.9.44"
println "VersionName is $versionName"
buildConfigField "String", "GIT_DESCRIBE", "\"${versionName}\""
buildConfigField "String", "GIT_CURRENT_BRANCH", "\"${getCurrentGitBranch()}\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void deleteVariableTest() {
.performDelete();

onRecyclerView()
.checkCountEquals(0);
.checkHasNumberOfItems(0);
}

@Category({Cat.AppUi.class, Level.Smoke.class})
Expand All @@ -99,6 +99,6 @@ public void deleteVariableFromMenuTest() throws InterruptedException {
onView(withId(android.R.id.button1))
.perform(click());

onRecyclerView().checkCountEquals(0);
onRecyclerView().checkHasNumberOfItems(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2018 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.intents;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.intent.Intents;
import android.support.test.runner.AndroidJUnit4;

import org.catrobat.catroid.ProjectManager;
import org.catrobat.catroid.R;
import org.catrobat.catroid.common.Constants;
import org.catrobat.catroid.content.Project;
import org.catrobat.catroid.ui.ProjectActivity;
import org.catrobat.catroid.uiespresso.testsuites.Cat;
import org.catrobat.catroid.uiespresso.testsuites.Level;
import org.catrobat.catroid.uiespresso.util.UiTestUtils;
import org.catrobat.catroid.uiespresso.util.rules.BaseActivityInstrumentationRule;
import org.hamcrest.Matcher;
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 static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.Intents.intending;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasCategories;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtras;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

import static org.catrobat.catroid.uiespresso.ui.fragment.rvutils.RecyclerViewInteractionWrapper.onRecyclerView;
import static org.catrobat.catroid.uiespresso.util.matchers.BundleMatchers.bundleHasMatchingString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.core.AllOf.allOf;

@RunWith(AndroidJUnit4.class)
public class PocketPaintFromProjectActivityDiscardIntentTest {

private Matcher expectedIntent;
private final String projectName = "PaintroidNewLookIntentTest";

@Rule
public BaseActivityInstrumentationRule<ProjectActivity> baseActivityTestRule = new
BaseActivityInstrumentationRule<>(ProjectActivity.class, ProjectActivity.EXTRA_FRAGMENT_POSITION, ProjectActivity.FRAGMENT_SPRITES);

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

baseActivityTestRule.launchActivity();
Intents.init();

String defaultLookName = UiTestUtils.getResourcesString(R.string.default_look_name);
expectedIntent = allOf(
hasComponent(Constants.POCKET_PAINT_INTENT_ACTIVITY_NAME),
hasAction("android.intent.action.MAIN"),
hasCategories(hasItem(equalTo("android.intent.category.LAUNCHER"))),
hasExtras(bundleHasMatchingString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT, "")),
hasExtras(bundleHasMatchingString(Constants.EXTRA_PICTURE_NAME_POCKET_PAINT, defaultLookName)));

Intent resultData = new Intent();
Instrumentation.ActivityResult result =
new Instrumentation.ActivityResult(Activity.RESULT_CANCELED, resultData);

intending(expectedIntent).respondWith(result);
}

@After
public void tearDown() {
Intents.release();
baseActivityTestRule.finishActivity();
}

@Category({Cat.AppUi.class, Level.Smoke.class})
@Test
public void testCancelPaintroid() {
onView(withId(R.id.button_add))
.perform(click());

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

intended(expectedIntent);

onRecyclerView().checkHasNumberOfItems(1);
}

private void createProject(String projectName) {
Project project = new Project(InstrumentationRegistry.getTargetContext(), projectName);
ProjectManager.getInstance().setProject(project);
ProjectManager.getInstance().setCurrentlyEditedScene(project.getDefaultScene());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2018 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.intents;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.intent.Intents;
import android.support.test.runner.AndroidJUnit4;

import org.catrobat.catroid.ProjectManager;
import org.catrobat.catroid.R;
import org.catrobat.catroid.common.Constants;
import org.catrobat.catroid.content.Project;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.ui.SpriteActivity;
import org.catrobat.catroid.uiespresso.testsuites.Cat;
import org.catrobat.catroid.uiespresso.testsuites.Level;
import org.catrobat.catroid.uiespresso.util.UiTestUtils;
import org.catrobat.catroid.uiespresso.util.rules.BaseActivityInstrumentationRule;
import org.hamcrest.Matcher;
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 static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.Intents.intending;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasCategories;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtras;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

import static org.catrobat.catroid.uiespresso.ui.fragment.rvutils.RecyclerViewInteractionWrapper.onRecyclerView;
import static org.catrobat.catroid.uiespresso.util.matchers.BundleMatchers.bundleHasMatchingString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.core.AllOf.allOf;

@RunWith(AndroidJUnit4.class)
public class PocketPaintFromSpriteActivityDiscardIntentTest {

private Matcher expectedIntent;
private final String projectName = "PaintroidNewLookIntentTest";

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

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

baseActivityTestRule.launchActivity();
Intents.init();

String defaultLookName = UiTestUtils.getResourcesString(R.string.default_look_name);
expectedIntent = allOf(
hasComponent(Constants.POCKET_PAINT_INTENT_ACTIVITY_NAME),
hasAction("android.intent.action.MAIN"),
hasCategories(hasItem(equalTo("android.intent.category.LAUNCHER"))),
hasExtras(bundleHasMatchingString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT, "")),
hasExtras(bundleHasMatchingString(Constants.EXTRA_PICTURE_NAME_POCKET_PAINT, defaultLookName)));

Intent resultData = new Intent();
Instrumentation.ActivityResult result =
new Instrumentation.ActivityResult(Activity.RESULT_CANCELED, resultData);

intending(expectedIntent).respondWith(result);
}

@After
public void tearDown() {
Intents.release();
baseActivityTestRule.finishActivity();
}

@Category({Cat.AppUi.class, Level.Smoke.class})
@Test
public void testCancelPaintroid() {
onView(withId(R.id.button_add))
.perform(click());

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

intended(expectedIntent);

onRecyclerView().checkHasNumberOfItems(0);
}

private void createProject(String projectName) {
Project project = new Project(InstrumentationRegistry.getTargetContext(), projectName);
Sprite testSprite = new Sprite();
project.getDefaultScene().addSprite(testSprite);
ProjectManager.getInstance().setProject(project);
ProjectManager.getInstance().setCurrentSprite(testSprite);
ProjectManager.getInstance().setCurrentlyEditedScene(project.getDefaultScene());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public ViewInteraction performOnItemWithText(String text, ViewAction viewAction)
return perform(actionOnHolderItem(new RecyclerViewHolderMatcher().withText(text), viewAction));
}

public RecyclerViewInteractionWrapper checkCountEquals(int count) {
public RecyclerViewInteractionWrapper checkHasNumberOfItems(int count) {
viewInteraction
.check(matches(new RecyclerViewMatcher(recyclerViewId).withCount(count)));
.check(matches(new RecyclerViewMatcher(recyclerViewId).withNumberOfItems(count)));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public RecyclerViewMatcher(int recyclerViewId) {
this.recyclerViewId = recyclerViewId;
}

public Matcher<View> withCount(final int count) {
public Matcher<View> withNumberOfItems(final int numberOfItems) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("RecyclerViewItemMatcher with count:" + count + " does not match the view");
description.appendText("RecyclerViewItemMatcher with number of items:" + numberOfItems + " does not match the view");
}

@Override
Expand All @@ -51,7 +51,7 @@ protected boolean matchesSafely(View view) {
return recyclerView != null
&& recyclerView.getId() == recyclerViewId
&& recyclerView.getAdapter() != null
&& recyclerView.getAdapter().getItemCount() == count;
&& recyclerView.getAdapter().getItemCount() == numberOfItems;
}
};
}
Expand Down
16 changes: 11 additions & 5 deletions catroid/src/main/java/org/catrobat/catroid/ui/ProjectActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
FaceDetectionHandler.stopFaceDetection();
}

if (requestCode != RESULT_OK
&& SettingsFragment.isCastSharedPreferenceEnabled(this)
&& ProjectManager.getInstance().getCurrentProject().isCastProject()
&& !CastManager.getInstance().isConnected()) {
if (resultCode != RESULT_OK) {
if (SettingsFragment.isCastSharedPreferenceEnabled(this)
&& ProjectManager.getInstance().getCurrentProject().isCastProject()
&& !CastManager.getInstance().isConnected()) {

CastManager.getInstance().openDeviceSelectorOrDisconnectDialog(this);
CastManager.getInstance().openDeviceSelectorOrDisconnectDialog(this);
}
return;
}

Uri uri;
Expand Down Expand Up @@ -383,6 +385,10 @@ void startStageActivity() {
}

private void showLegoSensorConfigInfo() {
if (ProjectManager.getInstance().getCurrentProject() == null) {
return;
}

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean nxtDialogDisabled = preferences
.getBoolean(SettingsFragment.SETTINGS_MINDSTORMS_NXT_SHOW_SENSOR_INFO_BOX_DISABLED, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.catrobat.catroid.BuildConfig;
import org.catrobat.catroid.ProjectManager;
import org.catrobat.catroid.R;
import org.catrobat.catroid.cast.CastManager;
import org.catrobat.catroid.common.LookData;
import org.catrobat.catroid.common.SoundInfo;
import org.catrobat.catroid.content.Project;
Expand Down Expand Up @@ -229,6 +230,12 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}

if (resultCode != RESULT_OK) {
if (SettingsFragment.isCastSharedPreferenceEnabled(this)
&& ProjectManager.getInstance().getCurrentProject().isCastProject()
&& !CastManager.getInstance().isConnected()) {

CastManager.getInstance().openDeviceSelectorOrDisconnectDialog(this);
}
return;
}

Expand Down

0 comments on commit 3fda750

Please sign in to comment.