Skip to content

Commit

Permalink
FAForever#3092 review actions, add two tests
Browse files Browse the repository at this point in the history
  • Loading branch information
obydog002 committed Feb 22, 2024
1 parent 94f73c2 commit 3f05b23
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ public class CreateGameController extends NodeController<Pane> {

private final SimpleInvalidationListener createButtonStateListener = this::setCreateGameButtonState;

private MapVersionBean lastMapChosen = null;

public Label mapSizeLabel;
public Label mapPlayersLabel;
public Label mapDescriptionLabel;
Expand Down Expand Up @@ -273,7 +271,7 @@ protected void initMapSelection() {
.selectedItemProperty()
.when(showing)
.subscribe((oldItem, newItem) -> {
if (newItem == null && oldItem != null && filteredMaps.contains(oldItem)) {
if (newItem == null && filteredMaps.contains(oldItem)) {
mapListView.getSelectionModel().select(oldItem);
} else {
setSelectedMap(newItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.faforever.client.theme.UiService;
import com.faforever.client.ui.dialog.Dialog;
import com.faforever.client.user.LoginService;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
Expand All @@ -46,6 +47,7 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import java.util.function.Predicate;

import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
Expand Down Expand Up @@ -280,7 +282,6 @@ public void testButtonBindingIfNotConnecting() {
}

@Test
@Disabled("I will deal with this later")
public void testSelectLastMap() {
MapVersionBean lastMapBean = MapVersionBeanBuilder.create()
.defaultValues()
Expand Down Expand Up @@ -540,7 +541,7 @@ public void testOnGenerateMapClicked() {

@SuppressWarnings("unchecked")
@Test
public void testMapNameSearch() {
public void testMapNameSearchFilter() {
ArgumentCaptor<BiFunction<String, MapVersionBean, Boolean>> argumentCaptor = ArgumentCaptor.forClass(BiFunction.class);
verify(mapFilterController).addExternalFilter(any(ObservableValue.class),
argumentCaptor.capture());
Expand All @@ -558,4 +559,53 @@ public void testMapNameSearch() {
assertTrue(filter.apply("ua", mapVersionBean));
assertFalse(filter.apply("ap.v1000", mapVersionBean));
}

@Test
public void testMapNameSearchKeepsSelectedIfInMaps() {
ArgumentCaptor<BiFunction<String, MapVersionBean, Boolean>> argumentCaptor = ArgumentCaptor.forClass(BiFunction.class);
verify(mapFilterController).addExternalFilter(any(ObservableValue.class),
argumentCaptor.capture());
BiFunction<String, MapVersionBean, Boolean> filter = argumentCaptor.getValue();
ObjectProperty<Predicate<MapVersionBean>> predicate = mapFilterController.predicateProperty();
mapList.add(MapVersionBeanBuilder.create()
.defaultValues()
.map(MapBeanBuilder.create().defaultValues().displayName("Test1").get())
.get());

predicate.setValue((item) -> filter.apply("Test", item));
runOnFxThreadAndWait(() -> {
instance.mapListView.getSelectionModel().select(0);
instance.mapSearchTextField.setText("Test");
});

assertThat(instance.mapListView.getSelectionModel().getSelectedIndex(), is(0));

predicate.setValue((item) -> filter.apply("Test1", item));
runOnFxThreadAndWait(() -> {
instance.mapSearchTextField.setText("Test1");
});

assertThat(instance.mapListView.getSelectionModel().getSelectedIndex(), is(0));
}

@Test
public void testMapNameSearchClearsSelected() {
ArgumentCaptor<BiFunction<String, MapVersionBean, Boolean>> argumentCaptor = ArgumentCaptor.forClass(BiFunction.class);
verify(mapFilterController).addExternalFilter(any(ObservableValue.class),
argumentCaptor.capture());
BiFunction<String, MapVersionBean, Boolean> filter = argumentCaptor.getValue();
ObjectProperty<Predicate<MapVersionBean>> predicate = mapFilterController.predicateProperty();
mapList.add(MapVersionBeanBuilder.create()
.defaultValues()
.map(MapBeanBuilder.create().defaultValues().displayName("Test1").get())
.get());

predicate.setValue((item) -> filter.apply("Not in Filtered Maps", item));
runOnFxThreadAndWait(() -> {
instance.mapListView.getSelectionModel().select(0);
instance.mapSearchTextField.setText("Not in Filtered Maps");
});

assertThat(instance.mapListView.getSelectionModel().getSelectedIndex(), is(-1));
}
}

0 comments on commit 3f05b23

Please sign in to comment.