test(client): drive the autocomplete reposition on the fake clock
Build / Build-and-ng-test (pull_request) Successful in 6m31s
Lighthouse Checks / lighthouse (pull_request) Successful in 21m12s
Build / Build-and-test-development (pull_request) Successful in 35m26s

The specs gated their assertions on a real setTimeout(..., 10) plus done,
which is wall-clock timing: a loaded runner can assert before the
component's own timer fires, and the negative case would then pass
vacuously. fakeAsync + tick order the assertion on the scheduler instead.

Also drops the stale half of the viewbox resize comment - the shared tail
no longer notifies listeners, it just persists and re-measures.
This commit is contained in:
dc committed 2026-11-02 10:26:35 +00:00
1 parent e40525e278
commit 0587f71273
2 files changed
+15 -16

No files matched your search

@@ -1,4 +1,5 @@
import { EventEmitter } from '@angular/core'
import { fakeAsync, tick } from '@angular/core/testing'
import { AutocompleteComponent } from './autocomplete.component'
/**
@@ -8,27 +9,28 @@ import { AutocompleteComponent } from './autocomplete.component'
* this subscription is the only thing keeping an open dropdown aligned.
*
* The component only needs ChangeDetectorRef and EventService, so it can be
* constructed directly - same approach as the sidebar spec.
* constructed directly - same approach as the sidebar spec. The work it
* schedules is on a timer, so the specs drive the fake clock rather than
* sleeping: a wall-clock wait would let a slow runner assert before the
* component ever ran.
*/
describe('AutocompleteComponent', () => {
const buildComponent = (eventService: any) =>
new AutocompleteComponent({ detectChanges: () => {} } as any, eventService)
it('repositions the dropdown when the sidebar toggles', (done) => {
it('repositions the dropdown when the sidebar toggles', fakeAsync(() => {
const eventService: any = { onSidebarToggle: new EventEmitter<any>() }
const component = buildComponent(eventService)
const reposition = spyOn(component, 'calculateInputPosition')
component.ngOnInit()
eventService.onSidebarToggle.emit({ open: false })
tick()
setTimeout(() => {
expect(reposition).toHaveBeenCalled()
done()
}, 10)
})
expect(reposition).toHaveBeenCalled()
}))
it('stops listening once destroyed', (done) => {
it('stops listening once destroyed', fakeAsync(() => {
const eventService: any = { onSidebarToggle: new EventEmitter<any>() }
const component = buildComponent(eventService)
const reposition = spyOn(component, 'calculateInputPosition')
@@ -36,10 +38,8 @@ describe('AutocompleteComponent', () => {
component.ngOnDestroy()
eventService.onSidebarToggle.emit({ open: false })
tick()
setTimeout(() => {
expect(reposition).not.toHaveBeenCalled()
done()
}, 10)
})
expect(reposition).not.toHaveBeenCalled()
}))
})
@@ -694,9 +694,8 @@ export class ViewboxesComponent implements OnInit, AfterViewInit, OnDestroy {
/**
* Shared debounced tail for every resize path (corner, single-edge,
* left-edge) - persists the new size/position, notifies listeners the
* viewport changed shape, and refreshes every viewbox's Handsontable
* instance to match.
* left-edge) - persists the new size/position, then refreshes every
* viewbox's Handsontable instance to match.
*/
private scheduleAfterResizeRefresh(): void {
this.helperService.debounceCall(1000, () => {