refact: depreicated importTables for setTables
This commit is contained in:
parent
2e59f14030
commit
8a1320094f
@ -44,13 +44,18 @@ class Nodule {
|
||||
}
|
||||
|
||||
importTables = tablesToImport => {
|
||||
const validateTablesResponse = this._validateTables(tablesToImport)
|
||||
console.log('Function importTables has been depricated, please use "setTables()"')
|
||||
this.setTables(tablesToImport)
|
||||
}
|
||||
|
||||
setTables = tablesToSet => {
|
||||
const validateTablesResponse = this._validateTables(tablesToSet)
|
||||
if (validateTablesResponse.status === 'ERR') {
|
||||
throw validateTablesResponse
|
||||
} else {
|
||||
let tables = []
|
||||
if (!Array.isArray(tablesToImport)) tables = [tablesToImport]
|
||||
else tables = tablesToImport
|
||||
if (!Array.isArray(tablesToSet)) tables = [tablesToSet]
|
||||
else tables = tablesToSet
|
||||
this.tables = tables
|
||||
}
|
||||
}
|
||||
@ -61,7 +66,7 @@ class Nodule {
|
||||
this.type = 'Nodule'
|
||||
this.isValid = true
|
||||
|
||||
if (props.tables) this.importTables(props.tables)
|
||||
if (props.tables) this.setTables(props.tables)
|
||||
else this.tables = []
|
||||
}
|
||||
|
||||
|
@ -113,9 +113,54 @@ const failToExport = () => {
|
||||
else return false
|
||||
}
|
||||
|
||||
const setTables = () => {
|
||||
const initialTable = new Table({
|
||||
id: 'XYZ',
|
||||
label: 'Test Table',
|
||||
rows: [{ id: 'xyz', data: 'lh' }]
|
||||
})
|
||||
|
||||
const overrideTable = new Table({
|
||||
id: 'XYZ',
|
||||
label: 'Test Table',
|
||||
rows: [{ id: 'abc', data: 'row' }]
|
||||
})
|
||||
|
||||
const expectedOutput = {
|
||||
id: 'ABC',
|
||||
label: 'Test Node',
|
||||
type: 'Nodule',
|
||||
tables: [{
|
||||
id: 'XYZ',
|
||||
label: 'Test Table',
|
||||
rows: [{ id: 'abc', data: 'row' }],
|
||||
type: 'Table',
|
||||
isValid: true
|
||||
}],
|
||||
isValid: true
|
||||
}
|
||||
|
||||
try {
|
||||
const nodule = new Nodule({
|
||||
id: 'ABC',
|
||||
label: 'Test Node',
|
||||
tables: initialTable
|
||||
})
|
||||
nodule.setTables(overrideTable)
|
||||
const nodeProps = nodule.getProperties()
|
||||
|
||||
if (JSON.stringify(nodeProps) == JSON.stringify(expectedOutput)) return true
|
||||
else return false
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export default [
|
||||
{ name: 'Entity | Get Nodule Properties', test: getNodeProperties },
|
||||
{ name: 'Entity | Create Nodule Without Tables', test: createNodeWithoutTables },
|
||||
{ name: 'Entity | Import Tables to Nodule', test: importTables },
|
||||
{ name: 'Entity | Fail to Export', test: failToExport }
|
||||
{ name: 'Entity | Fail to Export', test: failToExport },
|
||||
{ name: 'Entity | Nodule setTables', test: setTables }
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user