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

Keep map selection when searching #3132

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,13 @@ protected void initMapSelection() {
mapListView.getSelectionModel()
.selectedItemProperty()
.when(showing)
.subscribe(this::setSelectedMap);
.subscribe((oldItem, newItem) -> {
if (newItem == null && filteredMaps.contains(oldItem)) {
mapListView.getSelectionModel().select(oldItem);
} else {
setSelectedMap(newItem);
}
});

FilteredList<MapVersionBean> skirmishMaps = mapService.getInstalledMaps()
.filtered(mapVersion -> mapVersion.getMap().getMapType() == MapType.SKIRMISH);
Expand Down Expand Up @@ -501,7 +507,7 @@ public void setGamesRoot(StackPane root) {
}

/**
* @return returns true of the map was found and false if not
* @return returns true if the map was found and false if not
*/
boolean selectMap(String mapFolderName) {
Optional<MapVersionBean> mapBeanOptional = mapListView.getItems()
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));
}
}
Loading