4
4
*/
5
5
6
6
import * as assert from 'assert'
7
- import { Ec2InstanceNode } from '../../../ec2/explorer/ec2InstanceNode'
8
- import { Ec2Instance , getNameOfInstance } from '../../../shared/clients/ec2Client'
9
- import { contextValueEc2 } from '../../../ec2/explorer/ec2ParentNode'
7
+ import {
8
+ Ec2InstanceNode ,
9
+ Ec2InstancePendingContext ,
10
+ Ec2InstanceRunningContext ,
11
+ Ec2InstanceStoppedContext ,
12
+ } from '../../../ec2/explorer/ec2InstanceNode'
13
+ import { Ec2Client , Ec2Instance , getNameOfInstance } from '../../../shared/clients/ec2Client'
14
+ import { Ec2ParentNode } from '../../../ec2/explorer/ec2ParentNode'
10
15
11
16
describe ( 'ec2InstanceNode' , function ( ) {
12
17
let testNode : Ec2InstanceNode
13
18
let testInstance : Ec2Instance
19
+ const testRegion = 'testRegion'
20
+ const testPartition = 'testPartition'
14
21
15
22
before ( function ( ) {
16
23
testInstance = {
@@ -21,9 +28,15 @@ describe('ec2InstanceNode', function () {
21
28
Value : 'testName' ,
22
29
} ,
23
30
] ,
31
+ status : 'running' ,
24
32
}
33
+ const testClient = new Ec2Client ( '' )
34
+ const testParentNode = new Ec2ParentNode ( testRegion , testPartition , testClient )
35
+ testNode = new Ec2InstanceNode ( testParentNode , testClient , 'testRegion' , 'testPartition' , testInstance )
36
+ } )
25
37
26
- testNode = new Ec2InstanceNode ( 'testRegion' , 'testPartition' , testInstance , contextValueEc2 )
38
+ this . beforeEach ( function ( ) {
39
+ testNode . updateInstance ( testInstance )
27
40
} )
28
41
29
42
it ( 'instantiates without issue' , async function ( ) {
@@ -42,13 +55,37 @@ describe('ec2InstanceNode', function () {
42
55
assert . strictEqual ( testNode . name , getNameOfInstance ( testInstance ) )
43
56
} )
44
57
45
- it ( 'initializes the tooltip' , async function ( ) {
46
- assert . strictEqual ( testNode . tooltip , `${ testNode . name } \n${ testNode . InstanceId } \n${ testNode . arn } ` )
47
- } )
48
-
49
58
it ( 'has no children' , async function ( ) {
50
59
const childNodes = await testNode . getChildren ( )
51
60
assert . ok ( childNodes )
52
61
assert . strictEqual ( childNodes . length , 0 , 'Expected node to have no children' )
53
62
} )
63
+
64
+ it ( 'has an EC2ParentNode as parent' , async function ( ) {
65
+ assert . ok ( testNode . parent instanceof Ec2ParentNode )
66
+ } )
67
+
68
+ it ( 'intializes the client' , async function ( ) {
69
+ assert . ok ( testNode . client instanceof Ec2Client )
70
+ } )
71
+
72
+ it ( 'sets context value based on status' , async function ( ) {
73
+ const stoppedInstance = { ...testInstance , status : 'stopped' }
74
+ testNode . updateInstance ( stoppedInstance )
75
+ assert . strictEqual ( testNode . contextValue , Ec2InstanceStoppedContext )
76
+
77
+ const runningInstance = { ...testInstance , status : 'running' }
78
+ testNode . updateInstance ( runningInstance )
79
+ assert . strictEqual ( testNode . contextValue , Ec2InstanceRunningContext )
80
+
81
+ const pendingInstance = { ...testInstance , status : 'pending' }
82
+ testNode . updateInstance ( pendingInstance )
83
+ assert . strictEqual ( testNode . contextValue , Ec2InstancePendingContext )
84
+ } )
85
+
86
+ it ( 'updates label with new instance' , async function ( ) {
87
+ const newIdInstance = { ...testInstance , InstanceId : 'testId2' }
88
+ testNode . updateInstance ( newIdInstance )
89
+ assert . strictEqual ( testNode . label , `${ getNameOfInstance ( newIdInstance ) } (${ newIdInstance . InstanceId } )` )
90
+ } )
54
91
} )
0 commit comments