Skip to content

Commit 8db13ae

Browse files
committed
fix: AI review comments
1 parent 3958697 commit 8db13ae

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/app/devices/general/general.component.spec.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'
77

88
import { GeneralComponent } from './general.component'
99
import { ActivatedRoute } from '@angular/router'
10-
import { of } from 'rxjs'
10+
import { of, Subject } from 'rxjs'
1111
import { DevicesService } from '../devices.service'
1212
import { provideTranslateService } from '@ngx-translate/core'
1313
import { By } from '@angular/platform-browser'
14-
import { Subject } from 'rxjs'
1514

1615
describe('GeneralComponent', () => {
1716
let component: GeneralComponent
@@ -179,4 +178,25 @@ describe('GeneralComponent', () => {
179178
expect(component.isLoading()).toBeFalse()
180179
expect(component.isUpdatingFeatures()).toBeFalse()
181180
})
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+
})
182202
})

src/app/devices/general/general.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export class GeneralComponent implements OnInit, OnDestroy {
9696
public isCloudMode: boolean = environment.cloud
9797

9898
private readonly destroy$ = new Subject<void>()
99+
private pendingFeatureUpdates = 0
99100

100101
ngOnInit(): void {
101102
forkJoin({
@@ -181,6 +182,7 @@ export class GeneralComponent implements OnInit, OnDestroy {
181182
}
182183

183184
setAmtFeatures(): void {
185+
this.pendingFeatureUpdates += 1
184186
this.isUpdatingFeatures.set(true)
185187
this.devicesService
186188
.setAmtFeatures(this.deviceId(), {
@@ -189,7 +191,8 @@ export class GeneralComponent implements OnInit, OnDestroy {
189191
} as AMTFeaturesRequest)
190192
.pipe(
191193
finalize(() => {
192-
this.isUpdatingFeatures.set(false)
194+
this.pendingFeatureUpdates = Math.max(0, this.pendingFeatureUpdates - 1)
195+
this.isUpdatingFeatures.set(this.pendingFeatureUpdates > 0)
193196
})
194197
)
195198
.subscribe({

0 commit comments

Comments
 (0)