import { assert } from 'chai' ; import * as faker from 'faker' ; import { before } from 'mocha' ; import * as Collections from 'typescript-collections' ; import { IIssueKey } from '../../main/types/issueKey' ; import { DependenciesTreeNode } from '../../main/treeDataProviders/dependenciesTree/dependenciesTreeNode' ; import { GeneralInfo } from '../../main/types/generalInfo' ; import { Severity } from '../../main/types/severity' ; /**
 * Test functionality of @class DependenciesTreeNode.
 */ describe ( 'Dependencies Tree Tests' , ( ) => { let issueOne = createDummyIssue ( ) ; let issueTwo = createDummyIssue ( ) ; let lowIssueOne = createDummyIssue ( ) ; let lowIssueTwo = createDummyIssue ( ) ; let mediumIssue = createDummyIssue ( ) ; let root = createNode ( 'root' ) ; let one = createNode ( 'one' ) ; let two = createNode ( 'two' ) ; let three = createNode ( 'three' ) ; let four = createNode ( 'four' ) ; let five = createNode ( 'five' ) ; before ( ( ) => { root . addChild ( one ) ; root . addChild ( two ) ; two . addChild ( three ) ; two . addChild ( four ) ; four . addChild ( five ) ; } ) ; it ( 'No issues' , ( ) => { let rootIssues = processTree ( ) ; assert . isTrue ( rootIssues . isEmpty ( ) ) ; assert . deepEqual ( root . topSeverity , Severity . Normal ) ; } ) ; it ( 'One node' , ( ) => { one . issues . add ( issueOne ) ; let rootIssues = processTree ( ) ; assert . deepEqual ( rootIssues . size ( ) , 1 ) ; assert . containsAllKeys ( rootIssues , one . issues ) ; } ) ; it ( 'Two nodes' , ( ) => { two . issues . add ( issueTwo ) ; let rootIssues = processTree ( ) ; assert . deepEqual ( rootIssues . size ( ) , 2 ) ; assert . containsAllKeys ( rootIssues , one . issues ) ; assert . containsAllKeys ( rootIssues , two . issues ) ; } ) ; it ( 'Four nodes' , ( ) => { three . issues . add ( lowIssueOne ) ; three . topSeverity = Severity . Low ; processTree ( ) ; let rootIssues = processTree ( ) ; assert . containsAllKeys ( rootIssues , one . issues ) ; assert . containsAllKeys ( rootIssues , two . issues ) ; assert . containsAllKeys ( rootIssues , three . issues ) ; four . issues . add ( mediumIssue ) ; four . issues . add ( lowIssueTwo ) ; four . topSeverity = Severity . Medium ; rootIssues = processTree ( ) ; assert . deepEqual ( rootIssues . size ( ) , 5 ) ; assert . deepEqual ( root . topSeverity , Severity . Medium ) ; assert . containsAllKeys ( rootIssues , one . issues ) ; assert . containsAllKeys ( rootIssues , two . issues ) ; assert . containsAllKeys ( rootIssues , three . issues ) ; assert . containsAllKeys ( rootIssues , four . issues ) ; } ) ; it ( 'Five nodes' , ( ) => { five . issues . add ( createDummyIssue ( ) ) ; five . issues . add ( createDummyIssue ( ) ) ; five . issues . add ( createDummyIssue ( ) ) ; five . issues . add ( createDummyIssue ( ) ) ; five . issues . add ( createDummyIssue ( ) ) ; five . issues . add ( createDummyIssue ( ) ) ; five . topSeverity = Severity . High ; let rootIssues = processTree ( ) ; assert . deepEqual ( rootIssues . size ( ) , 11 ) ; assert . deepEqual ( root . topSeverity , Severity . High ) ; assert . containsAllKeys ( rootIssues , one . issues ) ; assert . containsAllKeys ( rootIssues , two . issues ) ; assert . containsAllKeys ( rootIssues , three . issues ) ; assert . containsAllKeys ( rootIssues , four . issues ) ; assert . containsAllKeys ( rootIssues , five . issues ) ; } ) ; function processTree ( ) { return root . processTreeIssues ( ) ; } function createNode ( label ) { return new DependenciesTreeNode ( new GeneralInfo ( label , '1.0.0' , [ ] , '' , '' ) ) ; } function createDummyIssue ( ) { return { issue_id : faker . datatype . uuid ( ) } as IIssueKey ; } } ) ;