1- import { NO_ERRORS_SCHEMA } from '@angular/core' ;
1+ import {
2+ Component ,
3+ NO_ERRORS_SCHEMA ,
4+ } from '@angular/core' ;
25import {
36 ComponentFixture ,
47 TestBed ,
@@ -62,10 +65,17 @@ describe('BulkAccessComponent', () => {
6265 'file' : { } ,
6366 } ;
6467
65- const mockSettings : any = jasmine . createSpyObj ( 'AccessControlFormContainerComponent' , {
66- getValue : jasmine . createSpy ( 'getValue' ) ,
67- reset : jasmine . createSpy ( 'reset' ) ,
68- } ) ;
68+ @Component ( {
69+ selector : 'ds-bulk-access-settings' ,
70+ template : '' ,
71+ exportAs : 'dsBulkSettings' ,
72+ standalone : true ,
73+ } )
74+ class MockBulkAccessSettingsComponent {
75+ isFormValid = jasmine . createSpy ( 'isFormValid' ) . and . returnValue ( false ) ;
76+ getValue = jasmine . createSpy ( 'getValue' ) ;
77+ reset = jasmine . createSpy ( 'reset' ) ;
78+ }
6979 const selection : any [ ] = [ { indexableObject : { uuid : '1234' } } , { indexableObject : { uuid : '5678' } } ] ;
7080 const selectableListState : SelectableListState = { id : 'test' , selection } ;
7181 const expectedIdList = [ '1234' , '5678' ] ;
@@ -93,6 +103,9 @@ describe('BulkAccessComponent', () => {
93103 BulkAccessSettingsComponent ,
94104 ] ,
95105 } ,
106+ add : {
107+ imports : [ MockBulkAccessSettingsComponent ] ,
108+ } ,
96109 } )
97110 . compileComponents ( ) ;
98111 } ) ;
@@ -109,13 +122,12 @@ describe('BulkAccessComponent', () => {
109122 fixture . destroy ( ) ;
110123 } ) ;
111124
112- describe ( 'when there are no elements selected' , ( ) => {
125+ describe ( 'when there are no elements selected and step two form is invalid ' , ( ) => {
113126
114127 beforeEach ( ( ) => {
115128
116129 ( component as any ) . selectableListService . getSelectableList . and . returnValue ( of ( selectableListStateEmpty ) ) ;
117130 fixture . detectChanges ( ) ;
118- component . settings = mockSettings ;
119131 } ) ;
120132
121133 it ( 'should create' , ( ) => {
@@ -138,7 +150,6 @@ describe('BulkAccessComponent', () => {
138150
139151 ( component as any ) . selectableListService . getSelectableList . and . returnValue ( of ( selectableListState ) ) ;
140152 fixture . detectChanges ( ) ;
141- component . settings = mockSettings ;
142153 } ) ;
143154
144155 it ( 'should create' , ( ) => {
@@ -149,15 +160,29 @@ describe('BulkAccessComponent', () => {
149160 expect ( component . objectsSelected$ . value ) . toEqual ( expectedIdList ) ;
150161 } ) ;
151162
152- it ( 'should enable the execute button when there are objects selected' , ( ) => {
163+ it ( 'should not enable the execute button when there are objects selected and step two form is invalid ' , ( ) => {
153164 component . objectsSelected$ . next ( [ '1234' ] ) ;
154- expect ( component . canExport ( ) ) . toBe ( true ) ;
165+ expect ( component . canExport ( ) ) . toBe ( false ) ;
155166 } ) ;
156167
157168 it ( 'should call the settings reset method when reset is called' , ( ) => {
158169 component . reset ( ) ;
159170 expect ( component . settings . reset ) . toHaveBeenCalled ( ) ;
160171 } ) ;
172+ } ) ;
173+ describe ( 'when there are elements selected and the step two form is valid' , ( ) => {
174+
175+ beforeEach ( ( ) => {
176+
177+ ( component as any ) . selectableListService . getSelectableList . and . returnValue ( of ( selectableListState ) ) ;
178+ fixture . detectChanges ( ) ;
179+ ( component as any ) . settings . isFormValid . and . returnValue ( true ) ;
180+ } ) ;
181+
182+ it ( 'should enable the execute button when there are objects selected and step two form is valid' , ( ) => {
183+ component . objectsSelected$ . next ( [ '1234' ] ) ;
184+ expect ( component . canExport ( ) ) . toBe ( true ) ;
185+ } ) ;
161186
162187 it ( 'should call the bulkAccessControlService executeScript method when submit is called' , ( ) => {
163188 ( component . settings as any ) . getValue . and . returnValue ( mockFormState ) ;
0 commit comments