diff options
author | Michael Lando <ml636r@att.com> | 2018-09-26 14:07:54 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-26 14:07:54 +0000 |
commit | 731714d8a00dc2129cfd8c1ca813fd810086af43 (patch) | |
tree | dbb5e60511e9d3186a5522fd1dc62186f7056634 /public/src/app/rule-engine/action/papa.spec.ts | |
parent | cf8f39f36b08ee1242c6f1ea472830a9e4be49f9 (diff) | |
parent | 22eda038b6cb646d63bfaf617372fce2b5d98631 (diff) |
Merge "update code to latest"
Diffstat (limited to 'public/src/app/rule-engine/action/papa.spec.ts')
-rw-r--r-- | public/src/app/rule-engine/action/papa.spec.ts | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/public/src/app/rule-engine/action/papa.spec.ts b/public/src/app/rule-engine/action/papa.spec.ts new file mode 100644 index 0000000..864d581 --- /dev/null +++ b/public/src/app/rule-engine/action/papa.spec.ts @@ -0,0 +1,84 @@ +import * as Papa from 'papaparse'; + +describe('parse CSV to JSON', () => { + it('should have only 2 attribute key and value', () => { + const stringAsCSV = 'liav,GL'; + Papa.parse(stringAsCSV, { + complete: result => { + if (result.data) { + const parser = result.data + .slice(0, 300) + .filter(item => item[0] !== undefined && item[1] !== undefined) + .map(item => { + return { + key: item[0].trim(), + value: item[1].trim() + }; + }); + expect(parser).toEqual([ + { + key: 'liav', + value: 'GL' + } + ]); + } + } + }); + }); + + it('should have 2 attribute ignore 1', () => { + const stringAsCSV = 'liav,GL,DCAE'; + Papa.parse(stringAsCSV, { + complete: result => { + if (result.data) { + const parser = result.data + .slice(0, 300) + .filter(item => item[0] !== undefined && item[1] !== undefined) + .map(item => { + return { + key: item[0].trim(), + value: item[1].trim() + }; + }); + expect(parser).toEqual([ + { + key: 'liav', + value: 'GL' + } + ]); + } + } + }); + }); + + it('should have 4 attribute', () => { + const stringAsCSV = `liav,GL + Vosk,Dev`; + + Papa.parse(stringAsCSV, { + complete: result => { + if (result.data) { + const parser = result.data + .slice(0, 300) + .filter(item => item[0] !== undefined && item[1] !== undefined) + .map(item => { + return { + key: item[0].trim(), + value: item[1].trim() + }; + }); + expect(parser).toEqual([ + { + key: 'liav', + value: 'GL' + }, + { + key: 'Vosk', + value: 'Dev' + } + ]); + } + } + }); + }); +}); |