1
1
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2
- import { NO_ERRORS_SCHEMA } from '@angular/core' ;
2
+ import { NO_ERRORS_SCHEMA , Component } from '@angular/core' ;
3
3
4
4
import { TranslateModule } from '@ngx-translate/core' ;
5
5
import { of } from 'rxjs' ;
@@ -57,10 +57,15 @@ describe('BulkAccessComponent', () => {
57
57
'file' : { }
58
58
} ;
59
59
60
- const mockSettings : any = jasmine . createSpyObj ( 'AccessControlFormContainerComponent' , {
61
- getValue : jasmine . createSpy ( 'getValue' ) ,
62
- reset : jasmine . createSpy ( 'reset' )
63
- } ) ;
60
+ @Component ( {
61
+ selector : 'ds-bulk-access-settings' ,
62
+ template : ''
63
+ } )
64
+ class MockBulkAccessSettingsComponent {
65
+ isFormValid = jasmine . createSpy ( 'isFormValid' ) . and . returnValue ( false ) ;
66
+ getValue = jasmine . createSpy ( 'getValue' ) ;
67
+ reset = jasmine . createSpy ( 'reset' ) ;
68
+ }
64
69
const selection : any [ ] = [ { indexableObject : { uuid : '1234' } } , { indexableObject : { uuid : '5678' } } ] ;
65
70
const selectableListState : SelectableListState = { id : 'test' , selection } ;
66
71
const expectedIdList = [ '1234' , '5678' ] ;
@@ -73,7 +78,10 @@ describe('BulkAccessComponent', () => {
73
78
RouterTestingModule ,
74
79
TranslateModule . forRoot ( )
75
80
] ,
76
- declarations : [ BulkAccessComponent ] ,
81
+ declarations : [
82
+ BulkAccessComponent ,
83
+ MockBulkAccessSettingsComponent ,
84
+ ] ,
77
85
providers : [
78
86
{ provide : BulkAccessControlService , useValue : bulkAccessControlServiceMock } ,
79
87
{ provide : NotificationsService , useValue : NotificationsServiceStub } ,
@@ -102,7 +110,6 @@ describe('BulkAccessComponent', () => {
102
110
103
111
( component as any ) . selectableListService . getSelectableList . and . returnValue ( of ( selectableListStateEmpty ) ) ;
104
112
fixture . detectChanges ( ) ;
105
- component . settings = mockSettings ;
106
113
} ) ;
107
114
108
115
it ( 'should create' , ( ) => {
@@ -119,13 +126,12 @@ describe('BulkAccessComponent', () => {
119
126
120
127
} ) ;
121
128
122
- describe ( 'when there are elements selected' , ( ) => {
129
+ describe ( 'when there are elements selected and step two form is invalid ' , ( ) => {
123
130
124
131
beforeEach ( ( ) => {
125
132
126
133
( component as any ) . selectableListService . getSelectableList . and . returnValue ( of ( selectableListState ) ) ;
127
134
fixture . detectChanges ( ) ;
128
- component . settings = mockSettings ;
129
135
} ) ;
130
136
131
137
it ( 'should create' , ( ) => {
@@ -136,16 +142,33 @@ describe('BulkAccessComponent', () => {
136
142
expect ( component . objectsSelected$ . value ) . toEqual ( expectedIdList ) ;
137
143
} ) ;
138
144
139
- it ( 'should enable the execute button when there are objects selected' , ( ) => {
145
+ it ( 'should not enable the execute button when there are objects selected and step two form is invalid ' , ( ) => {
140
146
component . objectsSelected$ . next ( [ '1234' ] ) ;
141
- expect ( component . canExport ( ) ) . toBe ( true ) ;
147
+ expect ( component . canExport ( ) ) . toBe ( false ) ;
142
148
} ) ;
143
149
144
150
it ( 'should call the settings reset method when reset is called' , ( ) => {
145
151
component . reset ( ) ;
146
152
expect ( component . settings . reset ) . toHaveBeenCalled ( ) ;
147
153
} ) ;
148
154
155
+
156
+ } ) ;
157
+
158
+ describe ( 'when there are elements selectedted and the step two form is valid' , ( ) => {
159
+
160
+ beforeEach ( ( ) => {
161
+
162
+ ( component as any ) . selectableListService . getSelectableList . and . returnValue ( of ( selectableListState ) ) ;
163
+ fixture . detectChanges ( ) ;
164
+ ( component as any ) . settings . isFormValid . and . returnValue ( true ) ;
165
+ } ) ;
166
+
167
+ it ( 'should enable the execute button when there are objects selected and step two form is valid' , ( ) => {
168
+ component . objectsSelected$ . next ( [ '1234' ] ) ;
169
+ expect ( component . canExport ( ) ) . toBe ( true ) ;
170
+ } ) ;
171
+
149
172
it ( 'should call the bulkAccessControlService executeScript method when submit is called' , ( ) => {
150
173
( component . settings as any ) . getValue . and . returnValue ( mockFormState ) ;
151
174
bulkAccessControlService . createPayloadFile . and . returnValue ( mockFile ) ;
0 commit comments