Skip to content

Commit

Permalink
Merge pull request #72 from brmighell/test-for-comma-separated-nums
Browse files Browse the repository at this point in the history
Comma-separated nums regression test (fails until fix is added)
  • Loading branch information
artoonie committed Dec 6, 2021
2 parents c57193e + df9e325 commit 09d2a13
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
33 changes: 33 additions & 0 deletions data-table/__tests__/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,36 @@ describe('Test cell getters and setters', () => {
expect(numErrorsVisible()).toEqual(0);
});
});

describe('Serialization', () => {
beforeEach(() => {
table.createDataTable({
'wrapperDivId': 'div-id',
'numRows': 1,
'numColumns': 1
});
});

test('Default serialization', () => {
expect(table.toJSON('div-id')).toEqual(JSON.stringify({
"version": 1,
"rowNames": [""],
"columnNames": [],
"data": [[{"Value": null, "Status": "Active"}]]
}));
});

test('Ensure number field doesn\'t allow commas', () => {
document.getElementById('div-id_row_1_and_col_1_and_field_0_').value = '1,000'
const serialized = table.toJSON('div-id');
const numValue = JSON.parse(serialized).data[0][0].Value;
expect(numValue).toEqual(null);
});

test('Ensure number field correctly serializes', () => {
document.getElementById('div-id_row_1_and_col_1_and_field_0_').value = '1000'
const serialized = table.toJSON('div-id');
const numValue = JSON.parse(serialized).data[0][0].Value;
expect(numValue).toEqual(1000);
});
});
9 changes: 8 additions & 1 deletion data-table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,20 @@ function createEntryCell(config, row, rowIndex, colIndex) {

let field = null;
let listener = null; // Each input type wants a different listener'focusout'; // usually we wan't a focusout, but not on dropdown
if (type === Number || type === String) {
if (type === String) {
let input = document.createElement("INPUT");
input.type = 'text';
input.placeholder = config.datumConfig.values[fieldNum];
input.classList.add('dt_cell-input');
field = input;
listener = 'focusout';
} else if (type === Number) {
let input = document.createElement("INPUT");
input.type = 'number';
input.placeholder = config.datumConfig.values[fieldNum];
input.classList.add('dt_cell-input');
field = input;
listener = 'focusout';
} else if (type === Boolean) {
let input = document.createElement("INPUT");
input.type = 'checkbox';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "usfca-data-table",
"version": "0.0.5",
"version": "0.0.6",
"description": "data table test",
"main": "data-table/table.js",
"directories": {
Expand Down

0 comments on commit 09d2a13

Please sign in to comment.