Added test, changed visualization

This commit is contained in:
xseris 2018-09-13 14:45:38 +02:00
parent 81e8e4c2f6
commit f288bc653e
4 changed files with 67 additions and 23 deletions

View File

@ -114,7 +114,7 @@ public class SeparatorBasedImporter extends TabularImportingParserBase {
} }
} }
if (retrievedColumnNames.size() > 0) { if (!retrievedColumnNames.isEmpty()) {
JSONUtilities.safePut(options, "headerLines", 1); JSONUtilities.safePut(options, "headerLines", 1);
} else { } else {
retrievedColumnNames = null; retrievedColumnNames = null;

View File

@ -514,6 +514,27 @@ public class TsvCsvImporterTests extends ImporterTest {
Assert.assertEquals(project.rows.get(0).cells.get(2).value, "data3"); Assert.assertEquals(project.rows.get(0).cells.get(2).value, "data3");
} }
@Test(dataProvider = "CSV-TSV-AutoDetermine")
public void readCustomColumnNames(String sep){
//create input
String inputSeparator = sep == null ? "\t" : sep;
String input = "data1" + inputSeparator + "data2" + inputSeparator + "data3\n";
try {
prepareOptions(sep, -1, 0, 0, 0, false, false,"\"","col1,col2,col3");
parseOneFile(SUT, new StringReader(input));
} catch (Exception e) {
Assert.fail("Exception during file parse",e);
}
Assert.assertEquals(project.columnModel.columns.size(), 3);
Assert.assertEquals(project.columnModel.columns.get(0).getName(), "col1");
Assert.assertEquals(project.columnModel.columns.get(1).getName(), "col2");
Assert.assertEquals(project.columnModel.columns.get(2).getName(), "col3");
Assert.assertEquals(project.rows.get(0).cells.get(0).value, "data1");
Assert.assertEquals(project.rows.get(0).cells.get(1).value, "data2");
Assert.assertEquals(project.rows.get(0).cells.get(2).value, "data3");
}
//---------------------read tests------------------------ //---------------------read tests------------------------
@Test @Test
public void readCsvWithProperties() { public void readCsvWithProperties() {
@ -579,6 +600,12 @@ public class TsvCsvImporterTests extends ImporterTest {
protected void prepareOptions( protected void prepareOptions(
String sep, int limit, int skip, int ignoreLines, String sep, int limit, int skip, int ignoreLines,
int headerLines, boolean guessValueType, boolean ignoreQuotes, String quoteCharacter) { int headerLines, boolean guessValueType, boolean ignoreQuotes, String quoteCharacter) {
prepareOptions(sep, limit, skip, ignoreLines, headerLines, guessValueType, ignoreQuotes, "\"","");
}
protected void prepareOptions(
String sep, int limit, int skip, int ignoreLines,
int headerLines, boolean guessValueType, boolean ignoreQuotes, String quoteCharacter, String columnNames) {
whenGetStringOption("separator", options, sep); whenGetStringOption("separator", options, sep);
whenGetStringOption("quoteCharacter", options, quoteCharacter); whenGetStringOption("quoteCharacter", options, quoteCharacter);
@ -589,6 +616,7 @@ public class TsvCsvImporterTests extends ImporterTest {
whenGetBooleanOption("guessCellValueTypes", options, guessValueType); whenGetBooleanOption("guessCellValueTypes", options, guessValueType);
whenGetBooleanOption("processQuotes", options, !ignoreQuotes); whenGetBooleanOption("processQuotes", options, !ignoreQuotes);
whenGetBooleanOption("storeBlankCellsAsNulls", options, true); whenGetBooleanOption("storeBlankCellsAsNulls", options, true);
whenGetStringOption("columnNames", options, columnNames);
} }
private void verifyOptions() { private void verifyOptions() {
@ -601,6 +629,7 @@ public class TsvCsvImporterTests extends ImporterTest {
verify(options, times(1)).getBoolean("guessCellValueTypes"); verify(options, times(1)).getBoolean("guessCellValueTypes");
verify(options, times(1)).getBoolean("processQuotes"); verify(options, times(1)).getBoolean("processQuotes");
verify(options, times(1)).getBoolean("storeBlankCellsAsNulls"); verify(options, times(1)).getBoolean("storeBlankCellsAsNulls");
verify(options, times(1)).getBoolean("columnNames");
} catch (JSONException e) { } catch (JSONException e) {
Assert.fail("JSON exception",e); Assert.fail("JSON exception",e);
} }

View File

@ -24,11 +24,6 @@
<td><label for="$column-separator-custom" id="or-import-custom"></label> <td><label for="$column-separator-custom" id="or-import-custom"></label>
<input bind="columnSeparatorInput" type="text" class="lightweight" size="5" /></td></tr> <input bind="columnSeparatorInput" type="text" class="lightweight" size="5" /></td></tr>
<tr><td colspan="2" id="or-import-escape"></td></tr> <tr><td colspan="2" id="or-import-escape"></td></tr>
</table>
<br>
<table>
<tr><td colspan="2" id="or-import-columnNames"></td></tr>
<tr><td><input style="width: 33em;" bind="columnNamesInput" /></td><td id="or-import-optional"></td></tr>
</table></div></td> </table></div></td>
<td colspan="2"><div class="grid-layout layout-tightest"><table> <td colspan="2"><div class="grid-layout layout-tightest"><table>
@ -60,9 +55,14 @@
</table></div></td> </table></div></td>
</tr> </tr>
<tr> <tr>
<td>&nbsp;</td> <td><div class="grid-layout layout-tightest" style="width:fit-content;"><table>
<tr><td width="1%"><input type="checkbox" bind="columnNamesCheckbox" id="$check-column-names" /></td>
<td id="or-import-columnNames"></td>
<td><input style="width: 18em;" bind="columnNamesInput" /></td>
<td id="or-import-optional"></td>
</tr></table></div></td>
<td><div class="grid-layout layout-tightest"><table> <td colspan="1"><div class="grid-layout layout-tightest"><table>
<tr><td width="1%"><input type="checkbox" bind="guessCellValueTypesCheckbox" id="$guess" /></td> <tr><td width="1%"><input type="checkbox" bind="guessCellValueTypesCheckbox" id="$guess" /></td>
<td><label for="$guess" id="or-import-parseCell"></label></td></tr> <td><label for="$guess" id="or-import-parseCell"></label></td></tr>
</table></div></td> </table></div></td>

View File

@ -118,10 +118,12 @@ Refine.SeparatorBasedParserUI.prototype.getOptions = function() {
options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked; options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked;
options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked;
if (this._optionContainerElmts.columnNamesCheckbox[0].checked) {
var columnNames = this._optionContainerElmts.columnNamesInput.val(); var columnNames = this._optionContainerElmts.columnNamesInput.val();
if (columnNames != undefined && columnNames != null && columnNames != '') { if (columnNames != undefined && columnNames != null && columnNames != '') {
options.columnNames = columnNames.split(","); options.columnNames = columnNames.split(",");
} }
}
return options; return options;
}; };
@ -174,10 +176,23 @@ Refine.SeparatorBasedParserUI.prototype._initialize = function() {
var isDisabled = $('textbox').prop('disabled'); var isDisabled = $('textbox').prop('disabled');
if (!isDisabled) { if (!isDisabled) {
self._optionContainerElmts.columnNamesInput.prop('disabled', true); self._optionContainerElmts.columnNamesInput.prop('disabled', true);
self._optionContainerElmts.columnNamesCheckbox.prop("checked", false);
self._optionContainerElmts.columnNamesInput.val(''); self._optionContainerElmts.columnNamesInput.val('');
} }
} else { } else {
self._optionContainerElmts.columnNamesInput.prop('disabled', false); self._optionContainerElmts.columnNamesInput.prop('disabled', false);
self._optionContainerElmts.columnNamesCheckbox.prop("checked", true);
}
});
this._optionContainerElmts.columnNamesCheckbox.on("click", function() {
if ($(this).is(':checked')) {
self._optionContainerElmts.headerLinesCheckbox.prop("checked", false);
self._optionContainerElmts.columnNamesInput.prop('disabled', false);
} else {
self._optionContainerElmts.headerLinesCheckbox.prop("checked", true);
self._optionContainerElmts.columnNamesInput.val('');
self._optionContainerElmts.columnNamesInput.prop('disabled', true);
} }
}); });