Skip to content

Commit

Permalink
#42 Add uitests for activities table
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Nov 15, 2020
1 parent 6590de9 commit 96e9666
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,55 @@ void clickingAddButtonAddsActivity()
activities.table().assertRowCount(1);
}

@Disabled("Not implemented yet, see https://github.com/itsallcode/white-rabbit/issues/23")
@Test
void removeButtonDisabledWhenNoActivitySelected()
{
selectCurrentDay();
time().tickMinute();
final ActivitiesTable activities = app().activitiesTable();

activities.addActivity();

activities.table().assertRowCount(1);

assertThat(activities.getRemoveActivityButton().isDisable()).isTrue();
}

@Test
void clickRemoveButtonWhenNoActivitySelectedDoesNothing()
{
selectCurrentDay();
time().tickMinute();
final ActivitiesTable activities = app().activitiesTable();

activities.addActivity();

activities.table().assertRowCount(1);

activities.removeActivity();

activities.table().assertRowCount(1);
}

@Test
void clickRemoveButtonRemovesSelectedActivity()
{
selectCurrentDay();
time().tickMinute();
final ActivitiesTable activities = app().activitiesTable();

activities.addActivity();

activities.table().assertRowCount(1);

activities.table().clickRow(0);

activities.removeActivity();

activities.table().assertRowCount(0);
}

@Test
void addActivitySelectRemainder()
{
Expand Down Expand Up @@ -120,6 +169,22 @@ void activitiesTableUpdatedWhenSwitchingDays()
table.assertRowCount(0);
}

@Test
void activitiesTableUpdatedWhenDayChanges()
{
time().tickMinute();

final ActivitiesTable activities = app().activitiesTable();
final JavaFxTable<ActivityPropertyAdapter> table = activities.table();
table.assertRowCount(0);

activities.addActivity();
table.assertRowCount(1);

time().tickDay();
table.assertRowCount(0);
}

private void addActivity()
{
time().tickMinute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.itsallcode.whiterabbit.jfxui.testutil.DayTableExpectedRow;
import org.itsallcode.whiterabbit.jfxui.testutil.DayTableExpectedRow.Builder;
import org.itsallcode.whiterabbit.jfxui.testutil.TestUtil;
import org.itsallcode.whiterabbit.jfxui.testutil.model.ActivitiesTable;
import org.itsallcode.whiterabbit.jfxui.testutil.model.JavaFxTable;
import org.itsallcode.whiterabbit.logic.model.json.DayType;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -112,23 +114,24 @@ void editingNotAbortedWhenMinuteChanges()
assertThat(commentCell.getText()).isEqualTo("new");
}

@Disabled("Will be fixed with https://github.com/itsallcode/white-rabbit/issues/42")
@Test
void editingNotAbortedWhenMinuteChangesInActivitiesTable()
{
time().tickMinute();

// app().activitiesTable().a
final int rowIndex = time().getCurrentDayRowIndex();
final ActivitiesTable activities = app().activitiesTable();
activities.addActivity();

final JavaFxTable<DayRecordPropertyAdapter> dayTable = app().genericDayTable();
activities.table().clickRow(0);

dayTable.clickRow(rowIndex + 1);
final TableCell<?, ?> commentCell = dayTable.getTableCell(rowIndex, "comment");
TableCell<?, ?> commentCell = activities.getCommentCell(0);

robot.doubleClickOn(commentCell).write("tst").type(KeyCode.ENTER);

assertThat(commentCell.isEditing()).as("cell is editing").isFalse();

commentCell = activities.getCommentCell(0);
robot.doubleClickOn(commentCell).write("new");

assertThat(commentCell.isEditing()).as("cell is editing").isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public void tickMinute()
tickMinute(Duration.ofMinutes(1));
}

public void tickDay()
{
tickDay(LocalTime.of(8, 0));
}

public void tickDay(LocalTime time)
{
final LocalDateTime now = LocalDateTime.now(clockMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.testfx.api.FxRobot;

import javafx.scene.control.Button;
import javafx.scene.control.TableCell;

public class ActivitiesTable
{
Expand All @@ -27,6 +28,22 @@ public void addActivity()
robot.clickOn(addActivityButton);
}

public void removeActivity()
{
final Button removeActivityButton = getRemoveActivityButton();
robot.clickOn(removeActivityButton);
}

public Button getRemoveActivityButton()
{
return robot.lookup("#remove-activity-button").queryButton();
}

public TableCell<?, ?> getCommentCell(int rowIndex)
{
return table.getTableCell(rowIndex, "comment");
}

public JavaFxTable<ActivityPropertyAdapter> table()
{
return table;
Expand Down

0 comments on commit 96e9666

Please sign in to comment.