Skip to content

Commit

Permalink
updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markgrahamdawson committed Nov 1, 2024
1 parent 63c6758 commit f1540f6
Show file tree
Hide file tree
Showing 4 changed files with 747 additions and 270 deletions.
30 changes: 0 additions & 30 deletions src/views/Graph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -622,17 +622,6 @@ export default {
})
return nodesFiltered
},
checkForNode (nodeName, cyclePoint, nodes) {
// checks the 'edges' array to see if edge is present
const nodePath = this.workflowIDs[0]
const nodeId = `${nodePath}//${cyclePoint}/${nodeName}`
const nodeSearch = nodes.find((node) => { return node.id === nodeId })
if (nodeSearch === -1) {
return null
} else {
return nodeSearch
}
},
createEdge (edgeType, sourceName, targetName, sourceCyclePoint, targetCyclePoint) {
// adds a new edge object to 'edges' array
const edgePath = this.workflowIDs[0]
Expand Down Expand Up @@ -722,20 +711,6 @@ export default {
})
return edgesFiltered
},
checkForEdge (sourceName, targetName, cyclePoint, edges) {
const edgePath = this.workflowIDs[0]
const edgeSearchTerm = `${edgePath}//$edge|${cyclePoint}/${sourceName}|${cyclePoint}/${targetName}`
const edgeSearch = edges.filter((edge) => {
const stringSearch = edge.id.indexOf(edgeSearchTerm)
if (stringSearch === -1) {
return false
} else {
return true
}
})
return edgeSearch
},
checkForEdgeBySource (sourceName, cyclePoint, edges) {
const edgePath = this.workflowIDs[0]
const edgeSearchTerm = `${edgePath}//${cyclePoint}/${sourceName}`
Expand Down Expand Up @@ -915,11 +890,6 @@ export default {
return x
}, {})
},
getNodeByFamilyAndCycle (family, cycle) {
Object.values(this.cylcTree.$index).find((node) => {
return node.name === family && node.tokens.cycle === cycle
})
},
addSubgraph (dotcode, pointer, graphSections) {
pointer.children.forEach((key, i) => {
const value = key
Expand Down
157 changes: 123 additions & 34 deletions tests/unit/views/graphv2utils.js → tests/unit/views/graph-utils.js
Original file line number Diff line number Diff line change
@@ -1,134 +1,205 @@
import { Tokens } from '@/utils/uid'

const nodeSuceeded =
const nodeSucceeded =
{
id: 'user/one/run1//1/succeeded',
id: 'user/one/run1//2/succeeded',
name: 'succeeded',
node: {
name: 'succeeded',
firstParent: {
id: 'user/one/run1//1/SUCCEEDED'
id: 'user/one/run1//2/SUCCEEDED'
}
},
tokens: {
cycle: '2'
}
},
children: []
}

const nodeRetrying =
{
id: 'user/one/run1//1/retrying',
name: 'retrying',
node: {
name: 'retrying',
firstParent: {
id: 'user/one/run1//1/BAD'
}
},
tokens: {
cycle: '1'
}
},
children: [
{
id: 'user/one/run1//1/retrying/01',
name: 'retrying',
},
{
id: 'user/one/run1//1/retrying/02',
name: 'retrying',
}
]
}

const nodeSleepy =
{
id: 'user/one/run1//1/sleepy',
id: 'user/one/run1//2/sleepy',
name: 'sleepy',
node: {
name: 'sleepy',
firstParent: {
id: 'user/one/run1//1/root'
}
},
tokens: {
cycle: '2'
}
},
children: []
}

const nodeFailed =
{
id: 'user/one/run1//1/failed',
name: 'failed',
node: {
name: 'failed',
firstParent: {
id: 'user/one/run1//1/BAD'
}
},
tokens: {
cycle: '1'
}
},
}

const nodeNamespaceRoot =
{
id: 'user/one/run1//$namespace|root',
name: 'root',
node: {
name: 'root',
parents: [],
childFamilies: [{ name: 'GOOD' }, { name: 'BAD' }],
childTasks: [{ name: 'checkpoint' }, { name: 'sleepy' }, { name: 'waiting' }]
}
},
tokens: { cycle: undefined }
}

const nodeNamespaceBad =
{
id: 'user/one/run1//$namespace|BAD',
name: 'BAD',
node: {
name: 'root',
parents: [{ name: 'root' }],
childFamilies: [],
childTasks: [{ name: 'retrying' }, { name: 'failed' }]
}
},
tokens: { cycle: undefined }
}

const nodeNamespaceGood =
{
id: 'user/one/run1//$namespace|GOOD',
name: 'GOOD',
node: {
name: 'GOOD',
parents: [{ name: 'root' }],
childFamilies: [{ name: 'SUCCEEDED' }],
childTasks: [{ name: 'retrying' }, { name: 'failed' }]
}
},
tokens: { cycle: undefined }
}

const nodeNamespaceSucceeded =
{
id: 'user/one/run1//$namespace|SUCCEEDED',
name: 'SUCCEEDED',
node: {
name: 'GOOD',
parents: [{ name: 'GOOD' }],
childFamilies: [],
childTasks: [{ name: 'succeeded' }, { name: 'eventually_succeeded' }]
}
},
tokens: { cycle: undefined }
}

const workflows = [
{
id: '~user/one',
node: {
firstParent: {
id: ''
}
},
children: [
{
id: '~user/one//1',
tokens: { cycle: 1 },
node: {
firstParent: {
id: ''
}
},
children: [
{
id: '~user/one//1/eventually_succeeded',
tokens: { cycle: 1 },
node: {
firstParent: {
id: 'user/one/run1//1/SUCCEEDED'
}
},
children: [
{
id: '~user/one//1/eventually_succeeded/3',
tokens: { cycle: 1 },
node: {
firstParent: {
id: 'user/one/run1//1/SUCCEEDED'
}
},
children: [],
},
{
id: '~user/one//1/eventually_succeeded/2',
tokens: { cycle: 1 },
node: {
firstParent: {
id: 'user/one/run1//1/SUCCEEDED'
}
},
children: [],
},
{
id: '~user/one//1/eventually_succeeded/1',
tokens: { cycle: 1 },
node: {
firstParent: {
id: 'user/one/run1//1/SUCCEEDED'
}
},
children: [],
},
],
},
{
id: '~user/one//1/failed',
tokens: { cycle: 1 },
node: {
firstParent: {
id: 'user/one/run1//1/BAD'
}
},
children: [
{
id: '~user/one//1/failed/1',
tokens: { cycle: 1 },
node: {
firstParent: {
id: 'user/one/run1//1/BAD'
}
},
children: [],
},
],
Expand All @@ -150,13 +221,49 @@ const nodes = [
nodeFailed,
nodeRetrying,
nodeSleepy,
nodeSuceeded
nodeSucceeded
]

const edges = [
{
id: 'user/one/run1//$edge|1/succeeded|1/failed',
name: 'user/one/run1//$edge|1/succeeded|1/failed',
parent: 'user/one/run1',
node: {
id: 'user/one/run1//$edge|1/succeeded|1/failed',
source: 'user/one/run1//1/succeeded',
target: 'user/one/run1//1/failed',
__typename: 'Edge'
}
},
{
id: 'user/one/run1//$edge|1/failed|1/checkpoint',
name: 'user/one/run1//$edge|1/failed|1/checkpoint',
parent: 'user/one/run1',
node: {
id: 'user/one/run1//$edge|1/failed|1/checkpoint',
source: 'user/one/run1//1/failed',
target: 'user/one/run1//1/checkpoint',
__typename: 'Edge'
}
},
{
id: 'user/one/run1//$edge|2/sleepy|1/failed',
name: 'user/one/run1//$edge|2/sleepy|1/failed',
parent: 'user/one/run1',
node: {
id: 'user/one/run1//$edge|2/sleepy|1/failed',
source: 'user/one/run1//2/sleepy',
target: 'user/one/run1//1/failed',
__typename: 'Edge'
}
}
]

const cylcTree = {
$index: {
'user/one/run1//1/succeeded': nodeSuceeded,
'user/one/run1//1/sleepy': nodeSleepy,
'user/one/run1//1/succeeded': nodeSucceeded,
'user/one/run1//2/sleepy': nodeSleepy,
'user/one/run1//1/retrying': nodeRetrying,
'user/one/run1//1/failed': nodeFailed,
'user/one/run1//$namespace|root': nodeNamespaceRoot,
Expand All @@ -166,32 +273,14 @@ const cylcTree = {
}
}

// const getFamilies = (nodes) => {
// if (!groupFamily) return
// return nodes.reduce((x, y) => {
// if (y.node.firstParent) {
// (x[y.node.firstParent.id.split('/')[y.node.firstParent.id.split('/').length - 1]] ||= []).push(y)
// }
// return x
// }, {})
// }

const getCycles = (nodes) => {
return nodes.reduce((x, y) => {
(x[y.tokens.cycle] ||= []).push(y)
return x
}, {})
}

const namespaces = () => {
return workflows[0]?.$namespaces || []
}

export {
workflows,
nodes,
edges,
cylcTree,
// getFamilies,
getCycles,
namespaces
}
Loading

0 comments on commit f1540f6

Please sign in to comment.