public void testNXTMotorActionBrick() { ListView dragDropListView = UiTestUtils.getScriptListView(solo); BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter(); int childrenCount = adapter.getChildCountFromLastGroup(); int groupCount = adapter.getScriptCount(); assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount()); assertEquals("Incorrect number of bricks.", 1, childrenCount); ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList(); assertEquals("Incorrect number of bricks.", 1, projectBrickList.size()); assertEquals( "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0)); assertNotNull( "TextView does not exist.", solo.getText(solo.getString(R.string.nxt_brick_motor_move))); assertNotNull( "TextView does not exist.", solo.getText(solo.getString(R.string.nxt_motor_speed_to))); UiTestUtils.testBrickWithFormulaEditor( solo, ProjectManager.getInstance().getCurrentSprite(), R.id.motor_action_speed_edit_text, SET_SPEED, Brick.BrickField.LEGO_NXT_SPEED, motorBrick); String[] motors = getActivity().getResources().getStringArray(R.array.nxt_motor_chooser); assertTrue("Spinner items list too short!", motors.length == 4); int legoSpinnerIndex = 0; Spinner currentSpinner = solo.getCurrentViews(Spinner.class).get(legoSpinnerIndex); solo.pressSpinnerItem(legoSpinnerIndex, 0); solo.waitForActivity(ScriptActivity.class.getSimpleName()); assertEquals("Wrong item in spinner!", motors[0], currentSpinner.getSelectedItem()); solo.pressSpinnerItem(legoSpinnerIndex, 1); solo.waitForActivity(ScriptActivity.class.getSimpleName()); assertEquals("Wrong item in spinner!", motors[1], currentSpinner.getSelectedItem()); solo.pressSpinnerItem(legoSpinnerIndex, 1); solo.waitForActivity(ScriptActivity.class.getSimpleName()); assertEquals("Wrong item in spinner!", motors[2], currentSpinner.getSelectedItem()); solo.pressSpinnerItem(legoSpinnerIndex, 1); solo.waitForActivity(ScriptActivity.class.getSimpleName()); assertEquals("Wrong item in spinner!", motors[3], currentSpinner.getSelectedItem()); }
public void testChangeYByNBrick() { ListView dragDropListView = UiTestUtils.getScriptListView(solo); BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter(); int childrenCount = adapter.getChildCountFromLastGroup(); int groupCount = adapter.getScriptCount(); assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount()); assertEquals("Incorrect number of bricks.", 1, childrenCount); ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList(); assertEquals("Incorrect number of bricks.", 1, projectBrickList.size()); assertEquals( "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0)); assertNotNull( "TextView does not exist.", solo.getText(solo.getString(R.string.brick_change_y_by))); UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, Y_TO_CHANGE, "yMovement", changeYByNBrick); }
@Smoke public void testIfBrick() { ListView view = UiTestUtils.getScriptListView(solo); ListView dragDropListView = UiTestUtils.getScriptListView(solo); BrickAdapter adapter = (BrickAdapter) view.getAdapter(); int childrenCount = adapter.getChildCountFromLastGroup(); UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, 5, "ifCondition", ifBrick); assertEquals( "Incorrect number of bricks.", 6, dragDropListView.getChildCount()); // don't forget the footer assertEquals("Incorrect number of bricks.", 0, childrenCount); ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList(); assertEquals("Incorrect number of bricks.", 4, projectBrickList.size()); assertTrue("Wrong Brick instance.", projectBrickList.get(0) instanceof IfLogicBeginBrick); assertNotNull( "TextView does not exist", solo.getText(getActivity().getString(R.string.brick_if_begin))); }
public void testGoNStepsBackBrick() { ScriptActivity activity = (ScriptActivity) solo.getCurrentActivity(); ScriptFragment fragment = (ScriptFragment) activity.getFragment(ScriptActivity.FRAGMENT_SCRIPTS); BrickAdapter adapter = fragment.getAdapter(); int childrenCount = adapter.getChildCountFromLastGroup(); int groupCount = adapter.getScriptCount(); assertEquals( "Incorrect number of bricks.", 2, solo.getCurrentViews(ListView.class).get(0).getChildCount()); assertEquals("Incorrect number of bricks.", 1, childrenCount); ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList(); assertEquals("Incorrect number of bricks.", 1, projectBrickList.size()); assertEquals( "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0)); assertNotNull("TextView does not exist.", solo.getText(solo.getString(R.string.brick_move))); UiTestUtils.testBrickWithFormulaEditor( solo, ProjectManager.getInstance().getCurrentSprite(), R.id.brick_move_n_steps_edit_text, STEPS_TO_MOVE, Brick.BrickField.STEPS, moveNStepsBrick); UiTestUtils.insertValueViaFormulaEditor(solo, R.id.brick_move_n_steps_edit_text, STEPS_TO_MOVE); try { assertEquals( "Wrong text in field.", STEPS_TO_MOVE, (moveNStepsBrick.getFormulaWithBrickField(Brick.BrickField.STEPS)).interpretDouble(null)); } catch (InterpretationException interpretationException) { fail("Wrong text in field."); } assertEquals( "Value in Brick is not updated.", STEPS_TO_MOVE, Double.valueOf( ((TextView) solo.getView(R.id.brick_move_n_steps_edit_text)) .getText() .toString() .replace(',', '.'))); UiTestUtils.insertValueViaFormulaEditor(solo, R.id.brick_move_n_steps_edit_text, 1); TextView stepTextView = (TextView) solo.getView(R.id.brick_move_n_steps_step_text_view); assertTrue( "Specifier hasn't changed from plural to singular", stepTextView .getText() .equals( stepTextView .getResources() .getQuantityString(R.plurals.brick_move_n_step_plural, 1))); UiTestUtils.insertValueViaFormulaEditor(solo, R.id.brick_move_n_steps_edit_text, 1.4); stepTextView = (TextView) solo.getView(R.id.brick_move_n_steps_step_text_view); assertTrue( "Specifier hasn't changed from singular to plural", stepTextView .getText() .equals( stepTextView .getResources() .getQuantityString( R.plurals.brick_move_n_step_plural, Utils.convertDoubleToPluralInteger(1.4)))); }