diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f46a42d..32fc6b0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.2.0) / ### Added * [#52](https://github.com/itsallcode/white-rabbit/issues/52): Improve keyboard usage for autocomplete text fields, immediately show proposals. +* [#54](https://github.com/itsallcode/white-rabbit/issues/54): First added activity has the remainder flag set. ## [1.1.0] 2020-11-29 diff --git a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/ActivitiesTest.java b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/ActivitiesTest.java index b90181aa..3bbdbe5e 100644 --- a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/ActivitiesTest.java +++ b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/ActivitiesTest.java @@ -231,13 +231,13 @@ void toggleRemainderDurationUpdatedAtMinuteTick() } @Test - void addActivitySelectRemainder() + void addActivityDeselectRemainder() { addActivity(); final JavaFxTable activitiesTable = app().activitiesTable().table(); robot.clickOn(activitiesTable.getTableCell(0, "remainder")); - activitiesTable.assertRowContent(0, ActivitiesTableExpectedRow.defaultRow().withRemainder(true).build()); + activitiesTable.assertRowContent(0, ActivitiesTableExpectedRow.defaultRow().withRemainder(false).build()); } @Test @@ -249,7 +249,8 @@ void addActivitySelectProject() final Node projectCell = activitiesTable.getTableCell(0, "project"); robot.doubleClickOn(projectCell).clickOn(projectCell).type(KeyCode.ENTER); - activitiesTable.assertRowContent(0, ActivitiesTableExpectedRow.defaultRow().withProject(PROJECT1).build()); + activitiesTable.assertRowContent(0, + ActivitiesTableExpectedRow.defaultRow().withRemainder(true).withProject(PROJECT1).build()); } @Test @@ -321,12 +322,14 @@ private void addActivity() time().tickMinute(); final ActivitiesTable activities = app().activitiesTable(); + final JavaFxTable table = activities.table(); + final boolean isFirstActivity = table.getRowCount() == 0; activities.addActivity(); - final Builder expectedRowContent = ActivitiesTableExpectedRow.defaultRow(); + final Builder expectedRowContent = ActivitiesTableExpectedRow.defaultRow().withRemainder(isFirstActivity); - assertAll(() -> activities.table().assertRowCount(1), - () -> activities.table().assertRowContent(0, expectedRowContent.build())); + assertAll(() -> table.assertRowCount(1), + () -> table.assertRowContent(0, expectedRowContent.build())); } private void selectCurrentDay() diff --git a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/ActivitiesTable.java b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/ActivitiesTable.java index 486513ec..008dc019 100644 --- a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/ActivitiesTable.java +++ b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/ActivitiesTable.java @@ -41,7 +41,11 @@ public void addRemainderActivity(Project project, String comment) final Node projectCell = table.getTableCell(rowIndex, "project"); robot.doubleClickOn(projectCell).clickOn(projectCell).clickOn(project.getLabel()); } - robot.clickOn(table.getTableCell(rowIndex, "remainder")); + final TableCell remainderCell = table.getTableCell(rowIndex, "remainder"); + if (!(Boolean) remainderCell.getItem()) + { + robot.clickOn(remainderCell); + } robot.doubleClickOn(table.getTableCell(rowIndex, "comment")).write(comment).type(KeyCode.ENTER); } @@ -54,6 +58,12 @@ public void addActivity(Project project, Duration duration, String comment) { final int rowIndex = addActivity(); + final TableCell remainderCell = table.getTableCell(rowIndex, "remainder"); + if ((Boolean) remainderCell.getItem()) + { + robot.clickOn(remainderCell); + } + if (project != null) { final Node projectCell = table.getTableCell(rowIndex, "project"); diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java index fc3107ab..57905e98 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java @@ -38,13 +38,17 @@ public Activity add() { day.setActivities(new ArrayList<>()); } + final boolean isFirstActivity = getActivities().findAny().isEmpty(); + final JsonActivity jsonActivity = new JsonActivity(); jsonActivity.setProjectId(""); jsonActivity.setDuration(Duration.ZERO); final int newRowIndex = day.getActivities().size(); day.getActivities().add(jsonActivity); - return wrapActivity(jsonActivity, newRowIndex); + final Activity wrappedActivity = wrapActivity(jsonActivity, newRowIndex); + wrappedActivity.setRemainderActivity(isFirstActivity); + return wrappedActivity; } public List getAll() diff --git a/logic/src/test/java/org/itsallcode/whiterabbit/logic/model/DayActivitiesTest.java b/logic/src/test/java/org/itsallcode/whiterabbit/logic/model/DayActivitiesTest.java index a86d0e67..298ceb6e 100644 --- a/logic/src/test/java/org/itsallcode/whiterabbit/logic/model/DayActivitiesTest.java +++ b/logic/src/test/java/org/itsallcode/whiterabbit/logic/model/DayActivitiesTest.java @@ -68,6 +68,29 @@ void addWhenActivitiesAreNull() assertThat(jsonDay.getActivities()).hasSize(1); } + @Test + void firstAddedActivityHasRemainderFlag() + { + final DayActivities activities = create(); + jsonDay.setActivities(new ArrayList<>()); + + final Activity newActivity = activities.add(); + + assertThat(newActivity.isRemainderActivity()).as("remainder").isTrue(); + } + + @Test + void secondAddedActivityDoesNotHaveRemainderFlag() + { + final DayActivities activities = create(); + jsonDay.setActivities(new ArrayList<>()); + + activities.add(); + final Activity newActivity = activities.add(); + + assertThat(newActivity.isRemainderActivity()).as("remainder").isFalse(); + } + @Test void addIncrementsRowIndex() {