Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor uitest framework #255

Merged
merged 20 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
".idea/": true,
},
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": true,
"source.fixAll": true,
},
"java.codeGeneration.useBlocks": true,
"editor.formatOnSave": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxRobot;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.Start;
import org.testfx.framework.junit5.Stop;
import org.testfx.framework.junit5.*;

import javafx.scene.Node;
import javafx.scene.input.KeyCode;
Expand Down Expand Up @@ -71,7 +69,7 @@ void doubleClickingEmptyTableAddsActivity()
assertActionAddsActivity(() -> app().activitiesTable().table().doubleClick());
}

private void assertActionAddsActivity(Runnable action)
private void assertActionAddsActivity(final Runnable action)
{
time().tickMinute();
selectCurrentDay();
Expand Down Expand Up @@ -122,7 +120,7 @@ void clickRemoveButtonRemovesSelectedActivity()

activities.table().assertRowCount(1);

activities.table().clickRow(0);
activities.table().row(0).click();

activities.removeActivity();

Expand Down Expand Up @@ -156,7 +154,7 @@ void typingDeleteKeyRemovesSelectedActivity()

activities.table().assertRowCount(1);

activities.table().clickRow(0);
activities.table().row(0).click();

robot.type(KeyCode.DELETE);

Expand All @@ -174,7 +172,7 @@ void typingOtherKeyKeyDoesNotRemoveSelectedActivity()

activities.table().assertRowCount(1);

activities.table().clickRow(0);
activities.table().row(0).click();

robot.type(KeyCode.BACK_SPACE);

Expand Down Expand Up @@ -301,8 +299,8 @@ void addActivityDeselectRemainder()
addActivity();

final JavaFxTable<ActivityPropertyAdapter> activitiesTable = app().activitiesTable().table();
robot.clickOn(activitiesTable.getTableCell(0, "remainder"));
activitiesTable.assertRowContent(0, ActivitiesTableExpectedRow.defaultRow().withRemainder(false).build());
robot.clickOn(activitiesTable.row(0).cell("remainder"));
activitiesTable.row(0).assertContent(ActivitiesTableExpectedRow.defaultRow().withRemainder(false).build());
}

@Test
Expand All @@ -312,10 +310,10 @@ void addActivitySelectProject()
addActivity();

final JavaFxTable<ActivityPropertyAdapter> activitiesTable = app().activitiesTable().table();
final Node projectCell = activitiesTable.getTableCell(0, "project");
final Node projectCell = activitiesTable.row(0).cell("project");

robot.doubleClickOn(projectCell).clickOn(projectCell).type(KeyCode.ENTER);
activitiesTable.assertRowContent(0,
activitiesTable.row(0).assertContent(
ActivitiesTableExpectedRow.defaultRow().withRemainder(true).withProject(PROJECT1).build());
}

Expand All @@ -326,7 +324,7 @@ void addActivityForOtherDay()
final int rowTomorrow = time().getCurrentDayRowIndex() + 1;
final JavaFxTable<ActivityPropertyAdapter> table = app().activitiesTable().table();

app().genericDayTable().clickRow(rowTomorrow);
app().genericDayTable().row(rowTomorrow).click();

table.assertRowCount(0);

Expand All @@ -340,15 +338,15 @@ void activitiesTableUpdatedWhenSwitchingDays()
{
time().tickMinute();
final int row = time().getCurrentDayRowIndex();
app().genericDayTable().clickRow(row + 1);
app().genericDayTable().row(row + 1).click();

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

addActivity();
table.assertRowCount(1);

app().genericDayTable().clickRow(row);
app().genericDayTable().row(row).click();
table.assertRowCount(0);
}

Expand Down Expand Up @@ -381,7 +379,7 @@ void activitiesDurationUpdatedWhenChangingBegin()
final Builder expectedRow = ActivitiesTableExpectedRow.defaultRow().withRemainder(true).withComment("act");
activities.table().assertContent(expectedRow.withDuration(Duration.ZERO).build());

app().dayTable().typeBegin(row, "11:00");
app().dayTable().row(row).typeBegin("11:00");
activities.table().assertContent(expectedRow.withDuration(Duration.ofMinutes(16)).build());
}

Expand All @@ -396,20 +394,20 @@ private void addActivity()
final Builder expectedRowContent = ActivitiesTableExpectedRow.defaultRow().withRemainder(isFirstActivity);

assertAll(() -> table.assertRowCount(1),
() -> table.assertRowContent(0, expectedRowContent.build()));
() -> table.row(0).assertContent(expectedRowContent.build()));
}

private void selectCurrentDay()
{
final JavaFxTable<DayRecordPropertyAdapter> dayTable = app().genericDayTable();

final int dayRowIndex = time().getCurrentDayRowIndex();
robot.clickOn(dayTable.getTableRow(dayRowIndex));
robot.clickOn(dayTable.row(dayRowIndex).tableRow());
}

@Override
@Start
void start(Stage stage)
void start(final Stage stage)
{
setLocale(Locale.GERMANY);
setInitialTime(Instant.parse("2007-12-03T10:15:30.20Z"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxRobot;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.Start;
import org.testfx.framework.junit5.Stop;
import org.testfx.framework.junit5.*;

import javafx.stage.Stage;

Expand Down Expand Up @@ -83,7 +81,7 @@ private void assertNewDuration(Duration expectedDuration)
{
final int currentDayRowIndex = time().getCurrentDayRowIndex();
final DayTable dayTable = app().dayTable();
dayTable.assertInterruption(currentDayRowIndex, expectedDuration);
dayTable.row(currentDayRowIndex).assertInterruption(expectedDuration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxRobot;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.Start;
import org.testfx.framework.junit5.Stop;
import org.testfx.framework.junit5.*;

import javafx.scene.control.TableCell;
import javafx.scene.input.KeyCode;
Expand All @@ -29,10 +27,10 @@ void autocompleteAllowsSelectingProposal()

final DayTable dayTable = app().dayTable();

dayTable.typeComment(3, "txt1");
dayTable.typeComment(4, "txt2");
dayTable.row(3).typeComment("txt1");
dayTable.row(4).typeComment("txt2");

final TableCell<?, ?> commentCell = dayTable.getCommentCell(5);
final TableCell<?, ?> commentCell = dayTable.row(5).getCommentCell();

robot.doubleClickOn(commentCell)
.write("t")
Expand All @@ -46,7 +44,7 @@ void autocompleteAllowsSelectingProposal()

@Override
@Start
void start(Stage stage)
void start(final Stage stage)
{
setLocale(Locale.GERMANY);
setInitialTime(Instant.parse("2007-12-03T10:15:30.20Z"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.itsallcode.whiterabbit.jfxui;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalTime;
import java.time.*;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -11,14 +9,10 @@
import org.itsallcode.whiterabbit.jfxui.testutil.TestUtil;
import org.itsallcode.whiterabbit.jfxui.testutil.model.AutomaticInterruptionDialog;
import org.itsallcode.whiterabbit.jfxui.testutil.model.DayTable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxRobot;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.Start;
import org.testfx.framework.junit5.Stop;
import org.testfx.framework.junit5.*;

import javafx.stage.Stage;

Expand Down Expand Up @@ -90,8 +84,8 @@ private void assertDay(Duration expectedInterruption, LocalTime expectedBegin, L
{
final int currentDayRowIndex = time().getCurrentDayRowIndex();
final DayTable dayTable = app().dayTable();
dayTable.assertInterruption(currentDayRowIndex, expectedInterruption);
dayTable.assertBeginAndEnd(currentDayRowIndex, expectedBegin, expectedEnd);
dayTable.row(currentDayRowIndex).assertInterruption(expectedInterruption);
dayTable.row(currentDayRowIndex).assertBeginAndEnd(expectedBegin, expectedEnd);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalTime;
import java.time.*;
import java.util.Locale;

import org.itsallcode.whiterabbit.api.model.DayType;
Expand All @@ -15,9 +13,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxRobot;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.Start;
import org.testfx.framework.junit5.Stop;
import org.testfx.framework.junit5.*;

import javafx.stage.Stage;

Expand All @@ -39,7 +35,7 @@ void beginAndEndEmptyByDefault()
final int currentDayRowIndex = time().getCurrentDayRowIndex();

final DayTable dayTable = app().dayTable();
dayTable.assertBeginAndEnd(currentDayRowIndex, null, null);
dayTable.row(currentDayRowIndex).assertBeginAndEnd(null, null);
}

@Test
Expand All @@ -51,7 +47,7 @@ void beginAndEndUpdatedEqualAfterFirstMinuteTick()
final int currentDayRowIndex = time().getCurrentDayRowIndex();
final LocalTime now = time().getCurrentTimeMinutes();
final DayTable dayTable = app().dayTable();
dayTable.assertBeginAndEnd(currentDayRowIndex, now, now);
dayTable.row(currentDayRowIndex).assertBeginAndEnd(now, now);
}

@Test
Expand All @@ -64,14 +60,14 @@ void beginAndEndUpdatedEqualAfterSecondMinuteTick()
final LocalTime firstTick = time().getCurrentTimeMinutes();
TestUtil.sleepShort();

dayTable.assertBeginAndEnd(currentDayRowIndex, firstTick, firstTick);
dayTable.row(currentDayRowIndex).assertBeginAndEnd(firstTick, firstTick);

time().tickMinute();

TestUtil.sleepShort();

final LocalTime secondTick = time().getCurrentTimeMinutes();
dayTable.assertBeginAndEnd(currentDayRowIndex, firstTick, secondTick);
dayTable.row(currentDayRowIndex).assertBeginAndEnd(firstTick, secondTick);
}

@Test
Expand All @@ -92,7 +88,7 @@ void beginAndEndUpdatedEveryMinute()

TestUtil.sleepShort();

dayTable.assertBeginAndEnd(currentDayRowIndex, firstTick, secondTick);
dayTable.row(currentDayRowIndex).assertBeginAndEnd(firstTick, secondTick);
}

@Test
Expand All @@ -105,12 +101,12 @@ void beginAndEndDeletedWhenChangingDayTypeToSick()
final LocalTime now = time().getCurrentTimeMinutes();
TestUtil.sleepShort();

dayTable.assertBeginAndEnd(currentDayRowIndex, now, now);
dayTable.row(currentDayRowIndex).assertBeginAndEnd(now, now);

dayTable.selectDayType(currentDayRowIndex, DayType.SICK);
dayTable.row(currentDayRowIndex).selectDayType(DayType.SICK);
TestUtil.sleepShort();

dayTable.assertBeginAndEnd(currentDayRowIndex, null, null);
dayTable.row(currentDayRowIndex).assertBeginAndEnd(null, null);
}

@Test
Expand Down Expand Up @@ -167,24 +163,24 @@ void timeWithOnlyHourSupported()
assertTimeParsed("08", LocalTime.of(8, 0));
}

private void assertTimeParsed(String enteredText, LocalTime expectedTime)
private void assertTimeParsed(final String enteredText, final LocalTime expectedTime)
{
final int row = time().getCurrentDayRowIndex() + 1;
final DayTable dayTable = app().dayTable();

dayTable.typeBegin(row, enteredText);
dayTable.row(row).typeBegin(enteredText);

assertThat(dayTable.getBegin(row)).isEqualTo(expectedTime);
assertThat(dayTable.row(row).getBegin()).isEqualTo(expectedTime);
}

private void assertDurationParsed(String enteredText, Duration expectedDuration)
private void assertDurationParsed(final String enteredText, final Duration expectedDuration)
{
final int row = time().getCurrentDayRowIndex() + 1;
final DayTable dayTable = app().dayTable();

dayTable.typeInterruption(row, enteredText);
dayTable.row(row).typeInterruption( enteredText);

assertThat(dayTable.getInterruption(row)).isEqualTo(expectedDuration);
assertThat(dayTable.row(row).getInterruption()).isEqualTo(expectedDuration);
}

@Test
Expand All @@ -195,7 +191,7 @@ void beginFormatted()

final int currentDayRowIndex = time().getCurrentDayRowIndex();
final DayTable dayTable = app().dayTable();
assertThat(dayTable.getBeginText(currentDayRowIndex)).isEqualTo("11:16");
assertThat(dayTable.row(currentDayRowIndex).getBeginText()).isEqualTo("11:16");
}

@Test
Expand All @@ -206,7 +202,7 @@ void zeroInterruptionFormatted()

final int currentDayRowIndex = time().getCurrentDayRowIndex();
final DayTable dayTable = app().dayTable();
assertThat(dayTable.getInterruptionText(currentDayRowIndex)).isEqualTo("00:00");
assertThat(dayTable.row(currentDayRowIndex).getInterruptionText()).isEqualTo("00:00");
}

@Test
Expand All @@ -215,9 +211,9 @@ void nonZeroInterruptionFormatted()
final int row = time().getCurrentDayRowIndex() + 1;
final DayTable dayTable = app().dayTable();

dayTable.typeInterruption(row, "1:02");
dayTable.row(row).typeInterruption( "1:02");

assertThat(dayTable.getInterruptionText(row)).isEqualTo("01:02");
assertThat(dayTable.row(row).getInterruptionText()).isEqualTo("01:02");
}

@Test
Expand All @@ -242,7 +238,7 @@ void currentDaySelectedAtDayChange()

@Override
@Start
void start(Stage stage)
void start(final Stage stage)
{
setLocale(Locale.GERMANY);
setInitialTime(Instant.parse("2007-12-03T10:15:30.20Z"));
Expand Down
Loading