diff --git a/src/app/core/layout/store-layout/store-header/store-header.component.html b/src/app/core/layout/store-layout/store-header/store-header.component.html index cbb9f3b..5c31172 100644 --- a/src/app/core/layout/store-layout/store-header/store-header.component.html +++ b/src/app/core/layout/store-layout/store-header/store-header.component.html @@ -21,7 +21,7 @@
- @if (ticketsMenu(); as menu) { = 2) { diff --git a/src/app/core/layout/store-layout/store-layout.component.spec.ts b/src/app/core/layout/store-layout/store-layout.component.spec.ts index 3a498c9..cd64a86 100644 --- a/src/app/core/layout/store-layout/store-layout.component.spec.ts +++ b/src/app/core/layout/store-layout/store-layout.component.spec.ts @@ -218,17 +218,17 @@ describe('StoreLayoutComponent', () => { expect(compiled.querySelector('.fa-linkedin-in')).not.toBeNull(); }); - it('navigates to search results when the search form is submitted', () => { + it('navigates to search results when the search button is clicked', () => { const router = TestBed.inject(Router); vi.spyOn(router, 'navigate'); const fixture = TestBed.createComponent(StoreLayoutComponent); fixture.detectChanges(); const header = fixture.debugElement.query(By.directive(StoreHeaderComponent)); - const form = header.query(By.css('form[role="search"]')); + const searchButton = header.query(By.css('.store-layout__search-button')); (header.componentInstance as any).searchControl.setValue(' zapatillas '); - form.triggerEventHandler('ngSubmit'); + searchButton.triggerEventHandler('click'); fixture.detectChanges(); expect(router.navigate).toHaveBeenCalledWith(['/buscar'], { @@ -236,6 +236,27 @@ describe('StoreLayoutComponent', () => { }); }); + it('prevents the native submit and searches when Enter is pressed', () => { + const router = TestBed.inject(Router); + vi.spyOn(router, 'navigate'); + const fixture = TestBed.createComponent(StoreLayoutComponent); + fixture.detectChanges(); + + const header = fixture.debugElement.query(By.directive(StoreHeaderComponent)); + const input = header.query(By.css('#store-search-input')); + const keyboardEvent = { + preventDefault: vi.fn(), + }; + + (header.componentInstance as any).searchControl.setValue('remera'); + input.triggerEventHandler('keydown.enter', keyboardEvent); + + expect(keyboardEvent.preventDefault).toHaveBeenCalled(); + expect(router.navigate).toHaveBeenCalledWith(['/buscar'], { + queryParams: { q: 'remera', page: 1 }, + }); + }); + it('renders the primary tickets action when the tenant has the tickets menu', () => { const router = TestBed.inject(Router); vi.spyOn(router, 'navigate');