From 0e0dcbafefc586f8914cab35d6b243aa1d953fa2 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Fri, 16 Nov 2018 12:51:49 +0000 Subject: [PATCH] Fix issue of empty list facet choices disappearing. Closes #1827. --- .../refine/browsing/facets/ListFacet.java | 1 + .../tests/browsing/facets/ListFacetTests.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/main/src/com/google/refine/browsing/facets/ListFacet.java b/main/src/com/google/refine/browsing/facets/ListFacet.java index bec36af53..5314820a7 100644 --- a/main/src/com/google/refine/browsing/facets/ListFacet.java +++ b/main/src/com/google/refine/browsing/facets/ListFacet.java @@ -305,6 +305,7 @@ public class ListFacet implements Facet { */ NominalFacetChoice choice = new NominalFacetChoice(decoratedValue); choice.count = 0; + choice.selected = true; _choices.add(choice); } } diff --git a/main/tests/server/src/com/google/refine/tests/browsing/facets/ListFacetTests.java b/main/tests/server/src/com/google/refine/tests/browsing/facets/ListFacetTests.java index 788494a58..580f0971d 100644 --- a/main/tests/server/src/com/google/refine/tests/browsing/facets/ListFacetTests.java +++ b/main/tests/server/src/com/google/refine/tests/browsing/facets/ListFacetTests.java @@ -42,6 +42,18 @@ public class ListFacetTests extends RefineTest { + " {\"v\":{\"v\":\"foobar\",\"l\":\"foobar\"},\"c\":1,\"s\":true}," + " {\"v\":{\"v\":\"barbar\",\"l\":\"barbar\"},\"c\":1,\"s\":false}" + "]}"; + + private static String selectedEmptyChoiceFacet = "{" + + "\"name\":\"facet A\"," + + "\"expression\":\"value+\\\"bar\\\"\"," + + "\"columnName\":\"Column A\"," + + "\"invert\":false," + + "\"choices\":[" + + " {\"v\":{\"v\":\"ebar\",\"l\":\"ebar\"},\"c\":1,\"s\":false}," + + " {\"v\":{\"v\":\"cbar\",\"l\":\"cbar\"},\"c\":1,\"s\":false}," + + " {\"v\":{\"v\":\"abar\",\"l\":\"abar\"},\"c\":1,\"s\":false}," + + " {\"v\":{\"v\":\"foobar\",\"l\":\"true\"},\"c\":0,\"s\":true}" + + "]}"; @Test public void serializeListFacetConfig() { @@ -77,4 +89,19 @@ public class ListFacetTests extends RefineTest { Facet facet = facetConfig.apply(project); TestUtils.isSerializedTo(facet, jsonFacetError); } + + @Test + public void testSelectedEmptyChoice() { + Project project = createCSVProject("Column A\n" + + "a\n" + + "c\n" + + "e"); + Engine engine = new Engine(project); + + ListFacetConfig facetConfig = new ListFacetConfig(); + facetConfig.initializeFromJSON(new JSONObject(jsonConfig)); + Facet facet = facetConfig.apply(project); + facet.computeChoices(project, engine.getAllFilteredRows()); + TestUtils.isSerializedTo(facet, selectedEmptyChoiceFacet); + } }