Skip to content

Commit

Permalink
Merge 8e3ed56 into 6c5de6a
Browse files Browse the repository at this point in the history
  • Loading branch information
viniagostini committed Mar 25, 2019
2 parents 6c5de6a + 8e3ed56 commit 60ab346
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const _getSheet = (keyword, spreadSheet) =>
*/
const _getSheetData = (sheetModel, sheet) => {
const headerLine = _getHeaderLine(sheet);
const isDataLine = line => line.length > 1 && !!line[0] && !!line[1];
const isDataLine = line => line.length > 1 && !!line[1];
return sheet
.filter((line, index) => index >= headerLine && line.length >= sheetModel.length && isDataLine(line))
.map(line =>
Expand Down
28 changes: 28 additions & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,34 @@ describe('paser _getSheetData', () => {
{campo1: 'dados31', campo2: 'dados32'}
]);
});

it('should remove lines that are not data', () => {
const sheetMock = [
['asdf', 'asdf'],
['fsda', 'fasd'],
['cpf', 'nome'], //header
[0, 'dados12'],
['dados21', 'dados22'],
['dados31', 'dados32'],
[0, 'dados42'],
['dados51', 'dados52'],
[]
];
const sheetModel = [
{fieldName: 'campo1'},
{fieldName: 'campo2'},
];

const data = parser._getSheetData(sheetModel, sheetMock);

expect(data).toEqual([
{campo1: 0, campo2: 'dados12'},
{campo1: 'dados21', campo2: 'dados22'},
{campo1: 'dados31', campo2: 'dados32'},
{campo1: 0, campo2: 'dados42'},
{campo1: 'dados51', campo2: 'dados52'}
]);
});
});

describe('parser _getContrachequeData', () => {
Expand Down

0 comments on commit 60ab346

Please sign in to comment.