Skip to content

Commit

Permalink
moved unit test functions into utils
Browse files Browse the repository at this point in the history
  • Loading branch information
markgrahamdawson committed Oct 29, 2024
1 parent ad92b1d commit 63c6758
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 178 deletions.
179 changes: 1 addition & 178 deletions tests/unit/views/graphv2.vue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,180 +13,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */

import { Tokens } from '@/utils/uid'
import { workflows, cylcTree, nodes, namespaces, getCycles } from './graphv2utils.js'

chai.config.truncateThreshold = 0

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

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

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

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

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

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

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

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

const workflows = [
{
id: '~user/one',
children: [
{
id: '~user/one//1',
children: [
{
id: '~user/one//1/eventually_succeeded',
children: [
{
id: '~user/one//1/eventually_succeeded/3',
children: [],
},
{
id: '~user/one//1/eventually_succeeded/2',
children: [],
},
{
id: '~user/one//1/eventually_succeeded/1',
children: [],
},
],
},
{
id: '~user/one//1/failed',
children: [
{
id: '~user/one//1/failed/1',
children: [],
},
],
},
]
}
],
tokens: new Tokens('user/one/run1'),
$namespaces: [
nodeNamespaceBad,
nodeNamespaceGood,
nodeNamespaceRoot,
nodeNamespaceSucceeded
]
}
]

const nodes = [
nodeFailed,
nodeRetrying,
nodeSleepy,
nodeSuceeded
]

const cylcTree = {
$index: {
'user/one/run1//1/succeeded': nodeSuceeded,
'user/one/run1//1/sleepy': nodeSleepy,
'user/one/run1//1/retrying': nodeRetrying,
'user/one/run1//1/failed': nodeFailed,
'user/one/run1//$namespace|root': nodeNamespaceRoot,
'user/one/run1//$namespace|BAD': nodeNamespaceBad,
'user/one/run1//$namespace|GOOD': nodeNamespaceGood,
'user/one/run1//$namespace|SUCCEEDED': nodeNamespaceSucceeded
}
}

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

let groupFamily
const getFamilies = (nodes) => {
if (!groupFamily) return
Expand All @@ -198,13 +28,6 @@ const getFamilies = (nodes) => {
}, {})
}

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

let allParentLookUp = {}
const namespaces2 = namespaces()

Expand Down
197 changes: 197 additions & 0 deletions tests/unit/views/graphv2utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { Tokens } from '@/utils/uid'

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

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

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

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

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

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

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

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

const workflows = [
{
id: '~user/one',
children: [
{
id: '~user/one//1',
children: [
{
id: '~user/one//1/eventually_succeeded',
children: [
{
id: '~user/one//1/eventually_succeeded/3',
children: [],
},
{
id: '~user/one//1/eventually_succeeded/2',
children: [],
},
{
id: '~user/one//1/eventually_succeeded/1',
children: [],
},
],
},
{
id: '~user/one//1/failed',
children: [
{
id: '~user/one//1/failed/1',
children: [],
},
],
},
]
}
],
tokens: new Tokens('user/one/run1'),
$namespaces: [
nodeNamespaceBad,
nodeNamespaceGood,
nodeNamespaceRoot,
nodeNamespaceSucceeded
]
}
]

const nodes = [
nodeFailed,
nodeRetrying,
nodeSleepy,
nodeSuceeded
]

const cylcTree = {
$index: {
'user/one/run1//1/succeeded': nodeSuceeded,
'user/one/run1//1/sleepy': nodeSleepy,
'user/one/run1//1/retrying': nodeRetrying,
'user/one/run1//1/failed': nodeFailed,
'user/one/run1//$namespace|root': nodeNamespaceRoot,
'user/one/run1//$namespace|BAD': nodeNamespaceBad,
'user/one/run1//$namespace|GOOD': nodeNamespaceGood,
'user/one/run1//$namespace|SUCCEEDED': nodeNamespaceSucceeded
}
}

// 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,
cylcTree,
// getFamilies,
getCycles,
namespaces
}

0 comments on commit 63c6758

Please sign in to comment.