feat: node export as table

This commit is contained in:
ysandler 2020-05-21 23:11:28 -05:00 committed by root
parent ddd5f2fe1c
commit 26424c2795
3 changed files with 88 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import Table from './Table.js'
class Node {
constructor (props) {
const validatePropsResponse = this._validateConstructionProps(props)
@ -10,6 +12,19 @@ class Node {
}
}
asTable = () => {
if (!this.export) return null
try {
return new Table({
id: this.id,
label: this.label,
rows: this.export()
})
} catch (err) {
throw err
}
}
getProperties = () => {
let tables = []
if (!Array.isArray(this.tables)) tables = []

View File

@ -101,8 +101,21 @@ const importTables = () => {
}
}
const failToExport = () => {
const expectedOutput = null
const node = new Node({
id: 'ABC',
label: 'Test Node',
})
const nodeAsTable = node.asTable()
if (expectedOutput === nodeAsTable) return true
else return false
}
export default [
{ name: 'Entity | Get Node Properties', test: getNodeProperties },
{ name: 'Entity | Create Node Without Tables', test: createNodeWithoutTables },
{ name: 'Entity | Import Tables to Node', test: importTables }
{ name: 'Entity | Import Tables to Node', test: importTables },
{ name: 'Entity | Fail to Export', test: failToExport }
]

View File

@ -411,6 +411,64 @@ const lesserEqualFilter = () => {
}
}
const getAsTable = () => {
const expectedOutput = {
id: 'ABC',
label: 'Test Node',
rows: [
{ id: 'qwe', count: 4, contractor: 'AshBritt' },
{ id: 'xyz', count: 2, contractor: 'HeyDay' }
],
type: 'Table',
isValid: true
}
let table = {}
try {
table = new Table({
id: 'XYZ',
label: 'Test Table',
rows: [
{ id: 'abc', count: 5, contractor: 'AshBritt' },
{ id: 'qwe', count: 4, contractor: 'AshBritt' },
{ id: 'XYZ', count: 8, contractor: 'AshBritt' },
{ id: 'xyz', count: 2, contractor: 'HeyDay' },
]
})
} catch (err) {
return false
}
let filterNode = {}
try {
filterNode = new FilterNode({
id: 'ABC',
label: 'Test Node',
tables: [table],
filterParams: {
count: 4
},
filterType: 'LESSEREQUAL'
})
} catch (err) {
console.log(err)
return false
}
let filterNodeAsTable = []
try {
filterNodeAsTable = filterNode.asTable().getProperties()
} catch (err) {
console.log(err)
return false
}
if (JSON.stringify(filterNodeAsTable) === JSON.stringify(expectedOutput)) {
return true
} else {
return false
}
}
export default [
{ name: 'Entity | FilterNode Equal Filter', test: equalFilter },
{ name: 'Entity | FilterNode GREATER Filter', test: greaterFilter },
@ -420,4 +478,5 @@ export default [
{ name: 'Entity | FilterNode Add Filter', test: addFilter },
{ name: 'Entity | FilterNode Set Type', test: setType },
{ name: 'Entity | FilterNode Export Without Type Error', test: exportWithoutTypeErrorHandle },
{ name: 'Entity | FilterNode Export As Table', test: getAsTable },
]