Added test, changed visualization
This commit is contained in:
parent
81e8e4c2f6
commit
f288bc653e
@ -114,7 +114,7 @@ public class SeparatorBasedImporter extends TabularImportingParserBase {
|
||||
}
|
||||
}
|
||||
|
||||
if (retrievedColumnNames.size() > 0) {
|
||||
if (!retrievedColumnNames.isEmpty()) {
|
||||
JSONUtilities.safePut(options, "headerLines", 1);
|
||||
} else {
|
||||
retrievedColumnNames = null;
|
||||
|
@ -514,6 +514,27 @@ public class TsvCsvImporterTests extends ImporterTest {
|
||||
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------------------------
|
||||
@Test
|
||||
public void readCsvWithProperties() {
|
||||
@ -579,17 +600,24 @@ public class TsvCsvImporterTests extends ImporterTest {
|
||||
protected void prepareOptions(
|
||||
String sep, int limit, int skip, int ignoreLines,
|
||||
int headerLines, boolean guessValueType, boolean ignoreQuotes, String quoteCharacter) {
|
||||
|
||||
whenGetStringOption("separator", options, sep);
|
||||
whenGetStringOption("quoteCharacter", options, quoteCharacter);
|
||||
whenGetIntegerOption("limit", options, limit);
|
||||
whenGetIntegerOption("skipDataLines", options, skip);
|
||||
whenGetIntegerOption("ignoreLines", options, ignoreLines);
|
||||
whenGetIntegerOption("headerLines", options, headerLines);
|
||||
whenGetBooleanOption("guessCellValueTypes", options, guessValueType);
|
||||
whenGetBooleanOption("processQuotes", options, !ignoreQuotes);
|
||||
whenGetBooleanOption("storeBlankCellsAsNulls", options, true);
|
||||
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("quoteCharacter", options, quoteCharacter);
|
||||
whenGetIntegerOption("limit", options, limit);
|
||||
whenGetIntegerOption("skipDataLines", options, skip);
|
||||
whenGetIntegerOption("ignoreLines", options, ignoreLines);
|
||||
whenGetIntegerOption("headerLines", options, headerLines);
|
||||
whenGetBooleanOption("guessCellValueTypes", options, guessValueType);
|
||||
whenGetBooleanOption("processQuotes", options, !ignoreQuotes);
|
||||
whenGetBooleanOption("storeBlankCellsAsNulls", options, true);
|
||||
whenGetStringOption("columnNames", options, columnNames);
|
||||
}
|
||||
|
||||
private void verifyOptions() {
|
||||
try {
|
||||
@ -601,6 +629,7 @@ public class TsvCsvImporterTests extends ImporterTest {
|
||||
verify(options, times(1)).getBoolean("guessCellValueTypes");
|
||||
verify(options, times(1)).getBoolean("processQuotes");
|
||||
verify(options, times(1)).getBoolean("storeBlankCellsAsNulls");
|
||||
verify(options, times(1)).getBoolean("columnNames");
|
||||
} catch (JSONException e) {
|
||||
Assert.fail("JSON exception",e);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="grid-layout layout-loose layout-full"><table>
|
||||
<div class="grid-layout layout-loose layout-full"><table>
|
||||
<tr>
|
||||
<td><div class="grid-layout layout-tighter"><table>
|
||||
<tr>
|
||||
@ -24,12 +24,7 @@
|
||||
<td><label for="$column-separator-custom" id="or-import-custom"></label>
|
||||
<input bind="columnSeparatorInput" type="text" class="lightweight" size="5" /></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>
|
||||
<tr><td width="1%"><input type="checkbox" bind="ignoreCheckbox" id="$ignore" /></td>
|
||||
@ -60,9 +55,14 @@
|
||||
</table></div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </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>
|
||||
<td><label for="$guess" id="or-import-parseCell"></label></td></tr>
|
||||
</table></div></td>
|
||||
|
@ -118,9 +118,11 @@ Refine.SeparatorBasedParserUI.prototype.getOptions = function() {
|
||||
options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked;
|
||||
options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked;
|
||||
|
||||
var columnNames = this._optionContainerElmts.columnNamesInput.val();
|
||||
if (columnNames != undefined && columnNames != null && columnNames != '') {
|
||||
options.columnNames = columnNames.split(",");
|
||||
if (this._optionContainerElmts.columnNamesCheckbox[0].checked) {
|
||||
var columnNames = this._optionContainerElmts.columnNamesInput.val();
|
||||
if (columnNames != undefined && columnNames != null && columnNames != '') {
|
||||
options.columnNames = columnNames.split(",");
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
@ -174,10 +176,23 @@ Refine.SeparatorBasedParserUI.prototype._initialize = function() {
|
||||
var isDisabled = $('textbox').prop('disabled');
|
||||
if (!isDisabled) {
|
||||
self._optionContainerElmts.columnNamesInput.prop('disabled', true);
|
||||
self._optionContainerElmts.columnNamesCheckbox.prop("checked", false);
|
||||
self._optionContainerElmts.columnNamesInput.val('');
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user