14
14
15
15
import deployModule from 'deploy/deploy_module' ;
16
16
import PortMappingsController from 'deploy/portmappings_controller' ;
17
+ import * as serviceTypes from 'deploy/portmappings_controller' ;
17
18
18
19
describe ( 'PortMappingsController controller' , ( ) => {
19
20
/** @type {!PortMappingsController } */
@@ -36,37 +37,73 @@ describe('PortMappingsController controller', () => {
36
37
} ) ;
37
38
} ) ;
38
39
39
- it ( 'should initialize first value' , ( ) => {
40
- expect ( ctrl . portMappings ) . toEqual ( [ { port : null , targetPort : null , protocol : 'FOO' } ] ) ;
41
- } ) ;
40
+ it ( 'should be initialized without port mapping line' ,
41
+ ( ) => { expect ( ctrl . portMappings . length ) . toBe ( 0 ) ; } ) ;
42
42
43
- it ( 'should add new mappings when needed' , ( ) => {
44
- expect ( ctrl . portMappings . length ) . toBe ( 1 ) ;
43
+ it ( 'should add or remove port mappings, depending on service type' , ( ) => {
45
44
46
- ctrl . checkPortMapping ( undefined , 0 ) ;
45
+ // select internal service will add an empty port mapping
46
+ ctrl . serviceType = serviceTypes . INT_SERVICE ;
47
+ ctrl . changeServiceType ( ) ;
47
48
expect ( ctrl . portMappings . length ) . toBe ( 1 ) ;
48
49
50
+ // select no service will remove all port mappings
51
+ ctrl . serviceType = serviceTypes . NO_SERVICE ;
52
+ ctrl . changeServiceType ( ) ;
53
+ expect ( ctrl . portMappings . length ) . toBe ( 0 ) ;
54
+ } ) ;
55
+
56
+ it ( 'should add one additional port mapping when ports are filled' , ( ) => {
57
+
58
+ // given is an empty port mapping line
59
+ ctrl . serviceType = serviceTypes . INT_SERVICE ;
60
+ ctrl . changeServiceType ( ) ;
61
+
62
+ // when filling
49
63
ctrl . portMappings [ 0 ] . port = 80 ;
50
64
ctrl . portMappings [ 0 ] . targetPort = 8080 ;
51
-
52
65
ctrl . checkPortMapping ( undefined , 0 ) ;
66
+
67
+ // then another line is added
53
68
expect ( ctrl . portMappings . length ) . toBe ( 2 ) ;
54
69
} ) ;
55
70
56
- it ( 'should determine removability' , ( ) => {
71
+ it ( 'should not allow removal if no port mapping line would be left over' , ( ) => {
72
+
73
+ // given is one (empty) port mapping line
74
+ ctrl . serviceType = serviceTypes . INT_SERVICE ;
75
+ ctrl . changeServiceType ( ) ;
76
+
77
+ // then it cannot be removed
57
78
expect ( ctrl . isRemovable ( 0 ) ) . toBe ( false ) ;
79
+ } ) ;
80
+
81
+ it ( 'should allow removal of one line if another is left over ' , ( ) => {
82
+
83
+ // given is a filled and an empty port mapping line
84
+ ctrl . serviceType = serviceTypes . INT_SERVICE ;
85
+ ctrl . changeServiceType ( ) ;
58
86
ctrl . portMappings [ 0 ] . port = 80 ;
59
87
ctrl . portMappings [ 0 ] . targetPort = 8080 ;
60
88
ctrl . checkPortMapping ( undefined , 0 ) ;
89
+
90
+ // then the first line is removable
61
91
expect ( ctrl . isRemovable ( 0 ) ) . toBe ( true ) ;
62
92
} ) ;
63
93
64
94
it ( 'should remove port mappings' , ( ) => {
95
+
96
+ // given is a filled and an empty port mapping line
97
+ ctrl . serviceType = serviceTypes . INT_SERVICE ;
98
+ ctrl . changeServiceType ( ) ;
65
99
ctrl . portMappings [ 0 ] . port = 80 ;
66
100
ctrl . portMappings [ 0 ] . targetPort = 8080 ;
67
101
ctrl . checkPortMapping ( undefined , 0 ) ;
68
- expect ( ctrl . portMappings . length ) . toBe ( 2 ) ;
102
+
103
+ // when removing the first line
69
104
ctrl . remove ( 0 ) ;
105
+
106
+ // then the empty line is left over
70
107
expect ( ctrl . portMappings . length ) . toBe ( 1 ) ;
71
108
expect ( ctrl . portMappings [ 0 ] . port ) . toBeNull ( ) ;
72
109
} ) ;
@@ -82,6 +119,8 @@ describe('PortMappingsController controller', () => {
82
119
testData . forEach ( ( testData ) => {
83
120
// given
84
121
let [ port , targetPort , portValidity , targetPortValidity ] = testData ;
122
+ ctrl . serviceType = serviceTypes . INT_SERVICE ;
123
+ ctrl . changeServiceType ( ) ;
85
124
ctrl . portMappings [ 0 ] . port = port ;
86
125
ctrl . portMappings [ 0 ] . targetPort = targetPort ;
87
126
@@ -93,4 +132,9 @@ describe('PortMappingsController controller', () => {
93
132
expect ( portMappingForm . targetPort . $valid ) . toEqual ( targetPortValidity ) ;
94
133
} ) ;
95
134
} ) ;
135
+
136
+ it ( 'should identify first index' , ( ) => {
137
+ expect ( ctrl . isFirst ( 0 ) ) . toEqual ( true ) ;
138
+ expect ( ctrl . isFirst ( 1 ) ) . toEqual ( false ) ;
139
+ } ) ;
96
140
} ) ;
0 commit comments