Skip to content

Commit

Permalink
add test for csv chunks #60
Browse files Browse the repository at this point in the history
  • Loading branch information
lana-k committed Jun 13, 2021
1 parent 5b3f34c commit df4595f
Showing 1 changed file with 94 additions and 1 deletion.
95 changes: 94 additions & 1 deletion tests/components/CsvImport/csv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('csv.js', () => {

it('parse resolves', async () => {
sinon.stub(Papa, 'parse').callsFake((file, config) => {
config.complete({
config.chunk({
data: [
[1, 'foo'],
[2, 'bar']
Expand All @@ -72,6 +72,7 @@ describe('csv.js', () => {
truncated: true
}
})
config.complete()
})
const file = {}
const result = await csv.parse(file)
Expand Down Expand Up @@ -112,4 +113,96 @@ describe('csv.js', () => {
const file = {}
await expect(csv.parse(file)).to.be.rejectedWith(err)
})

it('concat chunks', async () => {
sinon.stub(Papa, 'parse').callsFake((file, config) => {
config.chunk({
data: [
[1, 'foo'],
[2, 'bar']
],
errors: [
{
type: 'Quotes',
code: 'MissingQuotes',
message: 'Quote is missed',
row: 0
},
{
type: 'Delimiter',
code: 'UndetectableDelimiter',
message: 'Comma was used as a standart delimiter',
row: 0
}
],
meta: {
delimiter: ',',
linebreak: '\n',
aborted: false,
truncated: true
}
})

config.chunk({
data: [
[3, 'baz'],
[4, 'boo']
],
errors: [
{
type: 'Delimiter',
code: 'UndetectableDelimiter',
message: 'Comma was used as a standart delimiter',
row: 2
}
],
meta: {
delimiter: ',',
linebreak: '\n',
aborted: false,
truncated: true
}
})
config.complete()
})
const file = {}
const result = await csv.parse(file)

expect(result).to.eql({
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo'],
[2, 'bar'],
[3, 'baz'],
[4, 'boo']
]
},
delimiter: ',',
hasErrors: true,
messages: [
{
code: 'MissingQuotes',
message: 'Quote is missed',
row: 0,
type: 'error',
hint: 'Edit your CSV so that the field has a closing quote char.'
},
{
code: 'UndetectableDelimiter',
message: 'Comma was used as a standart delimiter',
row: 0,
type: 'info',
hint: undefined
},
{
code: 'UndetectableDelimiter',
message: 'Comma was used as a standart delimiter',
row: 2,
type: 'info',
hint: undefined
}
]
})
})
})

0 comments on commit df4595f

Please sign in to comment.