From 7197baad73e9e9266de8dae0f5e700955c401ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne=20Martin?= Date: Mon, 4 May 2020 16:07:46 -0700 Subject: [PATCH] Never randomize choice lists to ensure stable export order --- .../briefcase/export/FormDefinition.java | 2 + ...tToCsvExplodeRandomizedChoiceListTest.java | 25 ++++++++++ .../choice-lists-randomize-submission.xml | 6 +++ .../choice-lists-randomize.csv.expected | 2 + .../export/choice-lists-randomize.xml | 49 +++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 test/java/org/opendatakit/briefcase/export/ExportToCsvExplodeRandomizedChoiceListTest.java create mode 100644 test/resources/org/opendatakit/briefcase/export/choice-lists-randomize-submission.xml create mode 100644 test/resources/org/opendatakit/briefcase/export/choice-lists-randomize.csv.expected create mode 100644 test/resources/org/opendatakit/briefcase/export/choice-lists-randomize.xml diff --git a/src/org/opendatakit/briefcase/export/FormDefinition.java b/src/org/opendatakit/briefcase/export/FormDefinition.java index 410715bdc..4fd18390c 100644 --- a/src/org/opendatakit/briefcase/export/FormDefinition.java +++ b/src/org/opendatakit/briefcase/export/FormDefinition.java @@ -136,6 +136,8 @@ private static Map getFormControls(FormDef formDef) { // instance that is not external if (secondaryInstance != null && !(secondaryInstance instanceof ExternalDataInstance)) try { + // Never randomize the choice order to ensure stable column order when using split select multiples + itemsetBinding.randomize = false; formDef.populateDynamicChoices(itemsetBinding, (TreeReference) control.getBind().getReference()); } catch (NullPointerException e) { // Ignore (see https://github.com/opendatakit/briefcase/issues/789) diff --git a/test/java/org/opendatakit/briefcase/export/ExportToCsvExplodeRandomizedChoiceListTest.java b/test/java/org/opendatakit/briefcase/export/ExportToCsvExplodeRandomizedChoiceListTest.java new file mode 100644 index 000000000..81eb6adda --- /dev/null +++ b/test/java/org/opendatakit/briefcase/export/ExportToCsvExplodeRandomizedChoiceListTest.java @@ -0,0 +1,25 @@ +package org.opendatakit.briefcase.export; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ExportToCsvExplodeRandomizedChoiceListTest { + private ExportToCsvScenario scenario; + + @Before + public void setUp() { + scenario = ExportToCsvScenario.setUp("choice-lists-randomize"); + } + + @After + public void tearDown() { + scenario.tearDown(); + } + + @Test + public void exportWithSplitSelectMultiple_hasStableColumnOrder() { + scenario.runExportExplodedChoiceLists(); + scenario.assertSameContent(); + } +} diff --git a/test/resources/org/opendatakit/briefcase/export/choice-lists-randomize-submission.xml b/test/resources/org/opendatakit/briefcase/export/choice-lists-randomize-submission.xml new file mode 100644 index 000000000..4813c4402 --- /dev/null +++ b/test/resources/org/opendatakit/briefcase/export/choice-lists-randomize-submission.xml @@ -0,0 +1,6 @@ + + a + + uuid:39f3dd36-161e-47cb-a1a4-395831d253a7 + + diff --git a/test/resources/org/opendatakit/briefcase/export/choice-lists-randomize.csv.expected b/test/resources/org/opendatakit/briefcase/export/choice-lists-randomize.csv.expected new file mode 100644 index 000000000..64eedd10e --- /dev/null +++ b/test/resources/org/opendatakit/briefcase/export/choice-lists-randomize.csv.expected @@ -0,0 +1,2 @@ +SubmissionDate,select_multiple,select_multiple/a,select_multiple/b,select_multiple/c,select_multiple/d,select_multiple/e,meta-instanceID,KEY +"Apr 26, 2020 8:58:20 AM",a,1,0,0,0,0,uuid:39f3dd36-161e-47cb-a1a4-395831d253a7,uuid:39f3dd36-161e-47cb-a1a4-395831d253a7 diff --git a/test/resources/org/opendatakit/briefcase/export/choice-lists-randomize.xml b/test/resources/org/opendatakit/briefcase/export/choice-lists-randomize.xml new file mode 100644 index 000000000..c04cf2327 --- /dev/null +++ b/test/resources/org/opendatakit/briefcase/export/choice-lists-randomize.xml @@ -0,0 +1,49 @@ + + + Randomize choice list + + + + + + + + + + + + + a + + + + b + + + + c + + + + d + + + + e + + + + + + + + + + + +