27
27
28
28
import org .catrobat .catroid .ProjectManager ;
29
29
import org .catrobat .catroid .R ;
30
+ import org .catrobat .catroid .content .BroadcastScript ;
31
+ import org .catrobat .catroid .content .Script ;
32
+ import org .catrobat .catroid .content .Sprite ;
33
+ import org .catrobat .catroid .content .StartScript ;
30
34
import org .catrobat .catroid .content .bricks .Brick ;
31
35
import org .catrobat .catroid .ui .MainMenuActivity ;
32
36
import org .catrobat .catroid .ui .ProjectActivity ;
@@ -54,9 +58,6 @@ public ScriptFragmentTest() {
54
58
@ Override
55
59
public void setUp () throws Exception {
56
60
super .setUp ();
57
- brickListToCheck = UiTestUtils .createTestProject ();
58
- solo = new Solo (getInstrumentation (), getActivity ());
59
- UiTestUtils .getIntoScriptTabActivityFromMainMenu (solo );
60
61
}
61
62
62
63
@ Override
@@ -75,7 +76,20 @@ public void tearDown() throws Exception {
75
76
solo = null ;
76
77
}
77
78
79
+ private void initTestProject () {
80
+ brickListToCheck = UiTestUtils .createTestProject ();
81
+ solo = new Solo (getInstrumentation (), getActivity ());
82
+ UiTestUtils .getIntoScriptTabActivityFromMainMenu (solo );
83
+ }
84
+
85
+ private void initEmptyProject () {
86
+ UiTestUtils .createEmptyProject ();
87
+ solo = new Solo (getInstrumentation (), getActivity ());
88
+ UiTestUtils .getIntoScriptTabActivityFromMainMenu (solo );
89
+ }
90
+
78
91
public void testCreateNewBrickButton () {
92
+ initTestProject ();
79
93
int brickCountInView = solo .getCurrentListViews ().get (0 ).getCount ();
80
94
int brickCountInList = brickListToCheck .size ();
81
95
@@ -92,6 +106,7 @@ public void testCreateNewBrickButton() {
92
106
}
93
107
94
108
public void testBrickCategoryDialog () {
109
+ initTestProject ();
95
110
SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences (getActivity ());
96
111
97
112
// enable mindstorm bricks, if disabled
@@ -146,7 +161,30 @@ public void testBrickCategoryDialog() {
146
161
solo .waitForText (brickLegoStopMotor , 0 , 2000 ));
147
162
}
148
163
164
+ /**
165
+ *
166
+ * Tests issue#54. https://github.com/Catrobat/Catroid/issues/54
167
+ */
168
+ public void testOnlyAddControlBricks () {
169
+ initEmptyProject ();
170
+ Sprite sprite = ProjectManager .getInstance ().getCurrentSprite ();
171
+ assertEquals ("Project should contain only one script." , 1 , sprite .getNumberOfScripts ());
172
+
173
+ Script script = sprite .getScript (0 );
174
+ assertTrue ("Single script isn't empty." , script .getBrickList ().isEmpty ());
175
+
176
+ List <Integer > yPositionList = UiTestUtils .getListItemYPositions (solo );
177
+ UiTestUtils .addNewBrick (solo , R .string .brick_broadcast_receive );
178
+ solo .clickOnScreen (20 , yPositionList .get (1 ));
179
+ solo .sleep (200 );
180
+
181
+ assertEquals ("Two control bricks should be added." , 2 , sprite .getNumberOfScripts ());
182
+ assertTrue ("First script isn't a start script." , sprite .getScript (0 ) instanceof StartScript );
183
+ assertTrue ("Second script isn't a broadcast script." , sprite .getScript (1 ) instanceof BroadcastScript );
184
+ }
185
+
149
186
public void testSimpleDragNDrop () {
187
+ initTestProject ();
150
188
ArrayList <Integer > yPositionList = UiTestUtils .getListItemYPositions (solo );
151
189
assertTrue ("Test project brick list smaller than expected" , yPositionList .size () >= 6 );
152
190
@@ -163,6 +201,7 @@ public void testSimpleDragNDrop() {
163
201
}
164
202
165
203
public void testDeleteItem () {
204
+ initTestProject ();
166
205
ArrayList <Integer > yPositionList = UiTestUtils .getListItemYPositions (solo );
167
206
assertTrue ("Test project brick list smaller than expected" , yPositionList .size () >= 6 );
168
207
@@ -197,6 +236,7 @@ public void testDeleteItem() {
197
236
}
198
237
199
238
public void testBackgroundBricks () {
239
+ initTestProject ();
200
240
String currentProject = solo .getString (R .string .main_menu_continue );
201
241
String background = solo .getString (R .string .background );
202
242
String categoryLooks = solo .getString (R .string .category_looks );
0 commit comments