11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2- import { NO_ERRORS_SCHEMA } from '@angular/core' ;
2+ import { NO_ERRORS_SCHEMA , Component } from '@angular/core' ;
33
44import { TranslateModule } from '@ngx-translate/core' ;
55import { of } from 'rxjs' ;
@@ -57,10 +57,15 @@ describe('BulkAccessComponent', () => {
5757 'file' : { }
5858 } ;
5959
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+ }
6469 const selection : any [ ] = [ { indexableObject : { uuid : '1234' } } , { indexableObject : { uuid : '5678' } } ] ;
6570 const selectableListState : SelectableListState = { id : 'test' , selection } ;
6671 const expectedIdList = [ '1234' , '5678' ] ;
@@ -73,7 +78,10 @@ describe('BulkAccessComponent', () => {
7378 RouterTestingModule ,
7479 TranslateModule . forRoot ( )
7580 ] ,
76- declarations : [ BulkAccessComponent ] ,
81+ declarations : [
82+ BulkAccessComponent ,
83+ MockBulkAccessSettingsComponent ,
84+ ] ,
7785 providers : [
7886 { provide : BulkAccessControlService , useValue : bulkAccessControlServiceMock } ,
7987 { provide : NotificationsService , useValue : NotificationsServiceStub } ,
@@ -102,7 +110,6 @@ describe('BulkAccessComponent', () => {
102110
103111 ( component as any ) . selectableListService . getSelectableList . and . returnValue ( of ( selectableListStateEmpty ) ) ;
104112 fixture . detectChanges ( ) ;
105- component . settings = mockSettings ;
106113 } ) ;
107114
108115 it ( 'should create' , ( ) => {
@@ -119,13 +126,12 @@ describe('BulkAccessComponent', () => {
119126
120127 } ) ;
121128
122- describe ( 'when there are elements selected' , ( ) => {
129+ describe ( 'when there are elements selected and step two form is invalid ' , ( ) => {
123130
124131 beforeEach ( ( ) => {
125132
126133 ( component as any ) . selectableListService . getSelectableList . and . returnValue ( of ( selectableListState ) ) ;
127134 fixture . detectChanges ( ) ;
128- component . settings = mockSettings ;
129135 } ) ;
130136
131137 it ( 'should create' , ( ) => {
@@ -136,16 +142,33 @@ describe('BulkAccessComponent', () => {
136142 expect ( component . objectsSelected$ . value ) . toEqual ( expectedIdList ) ;
137143 } ) ;
138144
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 ' , ( ) => {
140146 component . objectsSelected$ . next ( [ '1234' ] ) ;
141- expect ( component . canExport ( ) ) . toBe ( true ) ;
147+ expect ( component . canExport ( ) ) . toBe ( false ) ;
142148 } ) ;
143149
144150 it ( 'should call the settings reset method when reset is called' , ( ) => {
145151 component . reset ( ) ;
146152 expect ( component . settings . reset ) . toHaveBeenCalled ( ) ;
147153 } ) ;
148154
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+
149172 it ( 'should call the bulkAccessControlService executeScript method when submit is called' , ( ) => {
150173 ( component . settings as any ) . getValue . and . returnValue ( mockFormState ) ;
151174 bulkAccessControlService . createPayloadFile . and . returnValue ( mockFile ) ;
0 commit comments