feat: node export as table
This commit is contained in:
parent
b78a064f0e
commit
cdfac800a1
@ -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 = []
|
||||
|
@ -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 }
|
||||
]
|
@ -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 },
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user