@@ -6,9 +6,10 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
66import { provideRouter } from '@angular/router' ;
77import { page } from 'vitest/browser' ;
88
9- import { provideLanguageService } from '../../../shared/util-common/language' ;
109import { createTestFlight } from '../../../../testing/create-test-flight' ;
1110import { provideTestConfig } from '../../../../testing/provide-test-config' ;
11+ import { appSettings } from '../../../shared/util-common/app-settings' ;
12+ import { provideLanguageService } from '../../../shared/util-common/language' ;
1213import { FlightSearch } from './flight-search' ;
1314import { FlightStore } from './flight-store' ;
1415
@@ -28,6 +29,9 @@ describe('flight-search', () => {
2829 ] ,
2930 } ) . compileComponents ( ) ;
3031
32+ // Turn off debouncing so the form propagates changes immediately
33+ vi . spyOn ( appSettings , 'debounceTimeMs' , 'get' ) . mockReturnValue ( 0 ) ;
34+
3135 fixture = TestBed . createComponent ( FlightSearch ) ;
3236 component = fixture . componentInstance ;
3337
@@ -36,9 +40,11 @@ describe('flight-search', () => {
3640 // Await the initial data loading (from = Graz, to = Hamburg)
3741 const request = await vi . waitFor (
3842 ( ) => ctrl . expectOne ( '/flight?from=Graz&to=Hamburg' ) ,
39- { interval : 50 , timeout : 1000 } ,
43+ { interval : 0 } ,
4044 ) ;
4145 request . flush ( [ ] ) ;
46+
47+ await fixture . whenStable ( ) ;
4248 } ) ;
4349
4450 afterEach ( ( ) => {
@@ -57,34 +63,37 @@ describe('flight-search', () => {
5763 await expect . element ( button ) . toBeDisabled ( ) ;
5864 } ) ;
5965
60- it ( 'enables the search button when from and to are given' , async ( ) => {
61- await page . getByLabelText ( 'From' ) . fill ( 'Paris' ) ;
66+ it ( 'loads flights when the search criteria change' , async ( ) => {
6267 await page . getByLabelText ( 'To' ) . fill ( 'London' ) ;
6368
64- const button = page . getByRole ( 'button' , { name : 'Search' } ) ;
65- await expect . element ( button ) . toBeEnabled ( ) ;
69+ const request = await vi . waitFor (
70+ ( ) => ctrl . expectOne ( '/flight?from=Graz&to=London' ) ,
71+ { interval : 0 } ,
72+ ) ;
73+
74+ request . flush ( [
75+ createTestFlight ( 1 ) ,
76+ createTestFlight ( 2 ) ,
77+ createTestFlight ( 3 ) ,
78+ ] ) ;
79+
80+ await fixture . whenStable ( ) ;
6681 } ) ;
6782
68- it ( 'searches for flights when the search button is clicked ' , async ( ) => {
83+ it ( 'delegates the filter changes to the store ' , async ( ) => {
6984 const store = TestBed . inject ( FlightStore ) ;
7085 vi . spyOn ( store , 'updateFilter' ) ;
7186
72- await page . getByLabelText ( 'From' ) . fill ( 'Paris' ) ;
7387 await page . getByLabelText ( 'To' ) . fill ( 'London' ) ;
7488
75- const button = page . getByRole ( 'button' , { name : 'Search' } ) ;
76- await button . click ( ) ;
77-
78- const request = await vi . waitFor ( ( ) =>
79- ctrl . expectOne ( '/flight?from=Paris&to=London' ) ,
89+ const request = await vi . waitFor (
90+ ( ) => ctrl . expectOne ( '/flight?from=Graz&to=London' ) ,
91+ { interval : 0 } ,
8092 ) ;
93+ request . flush ( [ ] ) ;
8194
82- request . flush ( [
83- createTestFlight ( 1 ) ,
84- createTestFlight ( 2 ) ,
85- createTestFlight ( 3 ) ,
86- ] ) ;
95+ await fixture . whenStable ( ) ;
8796
88- expect ( store . updateFilter ) . toBeCalledWith ( 'Paris ' , 'London' ) ;
97+ expect ( store . updateFilter ) . toBeCalledWith ( 'Graz ' , 'London' ) ;
8998 } ) ;
9099} ) ;
0 commit comments