Merge pull request #1829 from OpenRefine/issue1827

Fix issue of empty list facet choices disappearing.
This commit is contained in:
Antonin Delpeuch 2018-11-17 08:56:41 +00:00 committed by GitHub
commit 3431a9ee1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -305,6 +305,7 @@ public class ListFacet implements Facet {
*/
NominalFacetChoice choice = new NominalFacetChoice(decoratedValue);
choice.count = 0;
choice.selected = true;
_choices.add(choice);
}
}

View File

@ -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);
}
}