Skip to content

Commit

Permalink
Merge branch 'master' into 301-change-create-task-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolevy authored Aug 12, 2018
2 parents 3e8f9ea + 39afac8 commit 02bc383
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,10 @@ public void whenPlanIsRemovedExpectPlanIsNotOnTheList() {
}

@Test
public void whenSearchedPlanIsRemovedExpectNoPlansInSearch(){
public void whenSearchedPlanIsRemovedExpectNoPlansInSearch() {
final int testedPlanPosition = 5;

onView(withId(R.id.menu_search)).perform(typeText(expectedName + testedPlanPosition));
closeSoftKeyboard();

onView(withId(R.id.rv_plan_list))
.perform(RecyclerViewActions
.actionOnItemAtPosition(0,
Expand All @@ -144,21 +142,50 @@ public void whenSearchedPlanIsRemovedExpectNoPlansInSearch(){

onView(withRecyclerView(R.id.rv_plan_list)
.atPosition(0))
.check(doesNotExist());
.check(doesNotExist());
}

@Test
public void whenMultiplePlansAreRemovedExpectListRefreshedAfterEachOneOfThem() {
final int testedFirstTaskPosition = 3;
final int testedSecondTaskPosition = 4;
onView(withId(R.id.rv_plan_list))
.perform(RecyclerViewActions
.actionOnItemAtPosition(testedFirstTaskPosition,
new ViewClicker(R.id.id_remove_plan)));
onView(withId(R.id.rv_plan_list)).perform(scrollToPosition(testedFirstTaskPosition));
onView(withRecyclerView(R.id.rv_plan_list)
.atPosition(testedFirstTaskPosition))
.check(matches(not(hasDescendant(withText(expectedName
+ testedFirstTaskPosition)))));

onView(withId(R.id.rv_plan_list))
.perform(RecyclerViewActions
.actionOnItemAtPosition(testedSecondTaskPosition - 1,
new ViewClicker(R.id.id_remove_plan)));
onView(withId(R.id.rv_plan_list)).perform(scrollToPosition(testedSecondTaskPosition));
onView(withRecyclerView(R.id.rv_plan_list)
.atPosition(testedSecondTaskPosition))
.check(matches(not(hasDescendant(withText(expectedName
+ testedSecondTaskPosition)))));
}

@Test
public void whenSearchPlanIsRemovedExpectItToBeRemoved(){
final int testedPlanPosition = 5;

onView(withId(R.id.menu_search)).perform(typeText(expectedName + testedPlanPosition));
closeSoftKeyboard();

onView(withId(R.id.rv_plan_list))
.perform(RecyclerViewActions
.actionOnItemAtPosition(0,
new ViewClicker(R.id.id_remove_plan)));

onView(withRecyclerView(R.id.rv_plan_list)
.atPosition(0))
.check(doesNotExist());
onView(isAssignableFrom(EditText.class)).perform(clearText());
closeSoftKeyboard();

onView(withId(R.id.rv_plan_list)).perform(scrollToPosition(testedPlanPosition));
onView(withRecyclerView(R.id.rv_plan_list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.os.Bundle;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
Expand All @@ -14,15 +15,18 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import database.repository.PlanTemplateRepository;
import pg.autyzm.friendly_plans.R;
import pg.autyzm.friendly_plans.manager_app.view.plan_create.PlanCreateActivity;
import pg.autyzm.friendly_plans.manager_app.view.plan_create_task_list.PlanTaskListFragment;
import pg.autyzm.friendly_plans.resource.DaoSessionResource;
import pg.autyzm.friendly_plans.resource.PlanTemplateRule;
import pg.autyzm.friendly_plans.resource.TaskTemplateRule;
import pg.autyzm.friendly_plans.view_actions.ViewClicker;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
Expand All @@ -36,6 +40,7 @@ public class PlanTaskListFragmentTest {
private static final String PLAN_ID = "PLAN_ID";
private static final String TASK_NAME = "TASK_NAME";
private static final String PLAN_NAME = "PLAN NAME";
private static final String DELETE_TEST_TASK = "DELETE TEST TASK";

@ClassRule
public static DaoSessionResource daoSessionResource = new DaoSessionResource();
Expand All @@ -54,10 +59,15 @@ public class PlanTaskListFragmentTest {

@Before
public void setUp() {
PlanTaskListFragment fragment = new PlanTaskListFragment();
Context context = activityRule.getActivity().getApplicationContext();
PlanTemplateRepository planTemplateRepository = new PlanTemplateRepository(daoSessionResource.getSession(context));

taskTemplateRule.createTask(TASK_NAME);
long taskId = taskTemplateRule.createTask(DELETE_TEST_TASK);
long planId = planTemplateRule.createPlan(PLAN_NAME);
planTemplateRepository.setTasksWithThisPlan(planId, taskId);
taskTemplateRule.createTask(TASK_NAME);

PlanTaskListFragment fragment = new PlanTaskListFragment();

Bundle args = new Bundle();
args.putLong(PLAN_ID, planId);
Expand Down Expand Up @@ -95,8 +105,27 @@ public void whenAddingNewTaskToPlanExpectShowTaskOnList() {
onView(withId(R.id.id_btn_add_tasks_to_plan))
.perform(click());

recyclerView = (RecyclerView) activityRule.getActivity().findViewById(R.id.rv_create_plan_task_list);
lastPosition = recyclerView.getAdapter().getItemCount() - 1;

onView(withRecyclerView(R.id.rv_create_plan_task_list)
.atPosition(0))
.atPosition(lastPosition))
.check(matches(hasDescendant(withText(TASK_NAME))));
}

@Test
public void whenRemoveIconClickedExpectTaskToNoLongerBeInThisPlan(){
final int testedTaskPosition = 0;

onView(withId(R.id.rv_create_plan_task_list))
.perform(RecyclerViewActions
.actionOnItemAtPosition(testedTaskPosition,
new ViewClicker(R.id.id_remove_task)));

onView(withId(R.id.rv_create_plan_task_list)).perform(
RecyclerViewActions.scrollToPosition(testedTaskPosition));

onView(withRecyclerView(R.id.rv_create_plan_task_list)
.atPosition(testedTaskPosition)).check(doesNotExist());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package database.repository;


import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

import database.entities.DaoSession;
Expand Down Expand Up @@ -30,7 +33,6 @@ public void update(Long planId, String name) {
daoSession.getPlanTemplateDao().update(planTemplate);
}


public void setTasksWithThisPlan(Long planId, Long taskId) {
PlanTaskTemplate planTaskTemplate = new PlanTaskTemplate();
planTaskTemplate.setTaskTemplateId(taskId);
Expand All @@ -42,6 +44,19 @@ public void setTasksWithThisPlan(Long planId, Long taskId) {
get(planId).resetTasksWithThisPlan();
}

public void deleteTaskFromThisPlan(Long planId, Long taskId){
PlanTaskTemplateDao planTaskTemplateDao = daoSession.getPlanTaskTemplateDao();
QueryBuilder<PlanTaskTemplate> queryBuilder = planTaskTemplateDao.queryBuilder();

PlanTaskTemplate planTaskTemplate = queryBuilder.where(
PlanTaskTemplateDao.Properties.PlanTemplateId.eq(planId),
PlanTaskTemplateDao.Properties.TaskTemplateId.eq(taskId))
.uniqueOrThrow();

planTaskTemplateDao.delete(planTaskTemplate);
}


public PlanTemplate get(Long id) {
return daoSession.getPlanTemplateDao().load(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public void onRemoveTaskClick(int position){
}
};



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public void onTaskItemClick(int position) {

@Override
public void onRemoveTaskClick(int position){
/*Item remove TODO*/
planTemplateRepository.deleteTaskFromThisPlan(
planId,
taskListAdapter.getTaskItem(position).getId());
taskListAdapter.removeListItem(position);
}
};

Expand Down
6 changes: 3 additions & 3 deletions Friendly-plans/app/src/main/res/layout/item_task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:orientation="vertical">

<ImageButton
android:id="@+id/id_remove_task"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_delete_black_24dp" />
android:layout_height="wrap_content"
android:src="@drawable/ic_delete_black_24dp" />
</LinearLayout>

</LinearLayout>

0 comments on commit 02bc383

Please sign in to comment.