@@ -7,7 +7,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'
77
88import { GeneralComponent } from './general.component'
99import { ActivatedRoute } from '@angular/router'
10- import { of } from 'rxjs'
10+ import { of , Subject } from 'rxjs'
1111import { DevicesService } from '../devices.service'
1212import { provideTranslateService } from '@ngx-translate/core'
1313import { By } from '@angular/platform-browser'
@@ -32,7 +32,8 @@ describe('GeneralComponent', () => {
3232 'bulkPowerAction' ,
3333 'sendDeactivate' ,
3434 'sendBulkDeactivate' ,
35- 'getWsmanOperations'
35+ 'getWsmanOperations' ,
36+ 'setAmtFeatures'
3637 ] )
3738 const amtFeaturesResponse = {
3839 userConsent : 'ALL' ,
@@ -143,4 +144,72 @@ describe('GeneralComponent', () => {
143144 jasmine . objectContaining ( { remoteErase : true } )
144145 )
145146 } )
147+
148+ it ( 'should update only feature loading state while setAmtFeatures is in flight' , ( ) => {
149+ const response$ = new Subject < any > ( )
150+ devicesServiceSpy . setAmtFeatures . and . returnValue ( response$ )
151+ const loadingBefore = component . isLoading ( )
152+
153+ component . setAmtFeatures ( )
154+
155+ expect ( component . isUpdatingFeatures ( ) ) . toBeTrue ( )
156+ expect ( component . isLoading ( ) ) . toBe ( loadingBefore )
157+
158+ response$ . next ( { redirection : true , status : 'ok' } )
159+ response$ . complete ( )
160+
161+ expect ( component . isUpdatingFeatures ( ) ) . toBeFalse ( )
162+ expect ( component . isLoading ( ) ) . toBe ( loadingBefore )
163+ } )
164+
165+ it ( 'keeps summary loading state independent from feature update state' , ( ) => {
166+ const response$ = new Subject < any > ( )
167+ devicesServiceSpy . setAmtFeatures . and . returnValue ( response$ )
168+
169+ component . isLoading . set ( false )
170+ component . setAmtFeatures ( )
171+
172+ expect ( component . isLoading ( ) ) . toBeFalse ( )
173+ expect ( component . isUpdatingFeatures ( ) ) . toBeTrue ( )
174+
175+ response$ . next ( { redirection : true , status : 'ok' } )
176+ response$ . complete ( )
177+
178+ expect ( component . isLoading ( ) ) . toBeFalse ( )
179+ expect ( component . isUpdatingFeatures ( ) ) . toBeFalse ( )
180+ } )
181+
182+ it ( 'keeps feature loading state true until the last overlapping update completes' , ( ) => {
183+ const firstResponse$ = new Subject < any > ( )
184+ const secondResponse$ = new Subject < any > ( )
185+ devicesServiceSpy . setAmtFeatures . and . returnValues ( firstResponse$ , secondResponse$ )
186+
187+ component . setAmtFeatures ( )
188+ component . setAmtFeatures ( )
189+
190+ expect ( component . isUpdatingFeatures ( ) ) . toBeTrue ( )
191+
192+ firstResponse$ . next ( { redirection : true , status : 'ok' } )
193+ firstResponse$ . complete ( )
194+
195+ expect ( component . isUpdatingFeatures ( ) ) . toBeTrue ( )
196+
197+ secondResponse$ . next ( { redirection : true , status : 'ok' } )
198+ secondResponse$ . complete ( )
199+
200+ expect ( component . isUpdatingFeatures ( ) ) . toBeFalse ( )
201+ } )
202+
203+ it ( 'stops tracking an in-flight feature update when the component is destroyed' , ( ) => {
204+ const response$ = new Subject < any > ( )
205+ devicesServiceSpy . setAmtFeatures . and . returnValue ( response$ )
206+
207+ component . setAmtFeatures ( )
208+
209+ expect ( component . isUpdatingFeatures ( ) ) . toBeTrue ( )
210+
211+ component . ngOnDestroy ( )
212+
213+ expect ( component . isUpdatingFeatures ( ) ) . toBeFalse ( )
214+ } )
146215} )
0 commit comments