diff --git a/src/app/core/layout/store-layout/store-layout.component.html b/src/app/core/layout/store-layout/store-layout.component.html index e559ac9..6a4aa73 100644 --- a/src/app/core/layout/store-layout/store-layout.component.html +++ b/src/app/core/layout/store-layout/store-layout.component.html @@ -73,7 +73,7 @@ [logoUrl]="tenant()?.footer_logo ?? null" [backgroundImageUrl]="tenant()?.footer_bg_image ?? null" [storeName]="tenant()?.nombre ?? null" - [address]="tenant()?.address ?? null" + [address]="tenant()?.main_address?.address_text ?? null" [phone]="tenant()?.phone ?? null" (logoutClick)="onLogoutClick()" /> 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 a667b3a..6dace09 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 @@ -35,6 +35,7 @@ const tenant: Tenant = { nombre: 'Test Tenant', dominio: 'localhost', address: 'Calle Test 123, Rosario', + main_address: { id: 1, label: 'Principal', address_text: 'Calle Test 123, Rosario', latitude: null, longitude: null }, phone: '+54 341 555 1234', primary_color: '#6376F3', secondary_color: '#A0A0A0', @@ -563,6 +564,21 @@ describe('StoreLayoutComponent', () => { ); }); + it('uses only the main address in the footer', () => { + tenantState.set({ ...tenant, main_address: { + id: 10, label: 'Principal', address_text: 'Sede principal 456', latitude: null, longitude: null, + } }); + const fixture = TestBed.createComponent(StoreLayoutComponent); + fixture.detectChanges(); + const footer = fixture.nativeElement.querySelector('app-store-footer') as HTMLElement; + expect(footer.textContent).toContain('Sede principal 456'); + expect(footer.textContent).not.toContain(tenant.address); + tenantState.set({ ...tenant, main_address: null }); + fixture.detectChanges(); + expect(footer.textContent).not.toContain('Sede principal 456'); + expect(footer.textContent).not.toContain(tenant.address); + }); + it('navigates to search results when the search button is clicked', () => { const router = TestBed.inject(Router); vi.spyOn(router, 'navigate'); diff --git a/src/app/core/services/address.interface.ts b/src/app/core/services/address.interface.ts new file mode 100644 index 0000000..2e5777e --- /dev/null +++ b/src/app/core/services/address.interface.ts @@ -0,0 +1,11 @@ +export interface Address { + id: number; + label: string; + address_text: string; + latitude: number | null; + longitude: number | null; +} + +export interface TenantAddress extends Address { + is_main: boolean; +} diff --git a/src/app/core/services/event/event.interface.ts b/src/app/core/services/event/event.interface.ts index a51cce6..90abf79 100644 --- a/src/app/core/services/event/event.interface.ts +++ b/src/app/core/services/event/event.interface.ts @@ -1,4 +1,5 @@ import { ApiPaginatedResponse } from '../api-paginated-response.interface'; +import { Address } from '../address.interface'; export interface StoreEvent { id: number; @@ -8,6 +9,7 @@ export interface StoreEvent { subtitle: string | null; description: string | null; location: string | null; + address?: Address | null; exact_location: { latitude: number; longitude: number } | null; date_text: string | null; start_time?: string | null; diff --git a/src/app/core/services/tenant.interface.ts b/src/app/core/services/tenant.interface.ts index e7f00e6..0ba6c3e 100644 --- a/src/app/core/services/tenant.interface.ts +++ b/src/app/core/services/tenant.interface.ts @@ -1,4 +1,5 @@ import { ApiResponse } from './api-response.interface'; +import { Address, TenantAddress } from './address.interface'; export type CartEditingPolicyCode = 'disabled' | 'quantity_and_remove' | 'full'; @@ -69,6 +70,7 @@ export interface TenantEvent { subtitle: string | null; description: string | null; location: string | null; + address?: Address | null; date_text: string | null; dates: ActiveEventDate[]; social_media: SocialMedia[]; @@ -121,6 +123,8 @@ export interface Tenant { site_title?: string | null; asset_url?: string | null; address?: string | null; + addresses?: TenantAddress[]; + main_address?: Address | null; phone?: string | null; favicon?: string | null; primary_color: string; diff --git a/src/app/features/store/components/event-card/event-card.component.html b/src/app/features/store/components/event-card/event-card.component.html index 3c64eaa..59f9f93 100644 --- a/src/app/features/store/components/event-card/event-card.component.html +++ b/src/app/features/store/components/event-card/event-card.component.html @@ -12,8 +12,8 @@ @if (event().date_text) {
} - @if (event().location) { - + @if (event().address?.address_text; as location) { + } diff --git a/src/app/features/store/pages/event-detail-page/event-detail-page.component.html b/src/app/features/store/pages/event-detail-page/event-detail-page.component.html index 57ce4a7..a6b122e 100644 --- a/src/app/features/store/pages/event-detail-page/event-detail-page.component.html +++ b/src/app/features/store/pages/event-detail-page/event-detail-page.component.html @@ -24,8 +24,8 @@ {{ item.date_text }}@if (item.dates?.length === 1 && item.start_time) { · {{ item.start_time.slice(0, 5) }} h } } - @if (item.location) { -{{ item.location }}
+ @if (item.address?.address_text; as location) { +{{ location }}
} diff --git a/src/app/features/store/pages/event-detail-page/event-detail-page.component.spec.ts b/src/app/features/store/pages/event-detail-page/event-detail-page.component.spec.ts new file mode 100644 index 0000000..ccc845f --- /dev/null +++ b/src/app/features/store/pages/event-detail-page/event-detail-page.component.spec.ts @@ -0,0 +1,67 @@ +import { signal } from '@angular/core'; +import { TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { ActivatedRoute, convertToParamMap, provideRouter } from '@angular/router'; +import { of } from 'rxjs'; +import { beforeEach, describe, expect, it } from 'vitest'; + +import { AuthService } from '../../../../core/services/auth/auth.service'; +import { CheckoutService } from '../../../../core/services/checkout.service'; +import { StoreEvent } from '../../../../core/services/event/event.interface'; +import { EventService } from '../../../../core/services/event/event.service'; +import { TenantService } from '../../../../core/services/tenant.service'; +import { ToastService } from '../../../../core/services/toast.service'; +import { LocationMapComponent } from '../../../../shared/components/location-map/location-map.component'; +import { EventDetailPageComponent } from './event-detail-page.component'; + +const event: StoreEvent = { + id: 1, slug: 'festival', title: 'Festival', event_category_id: null, + subtitle: null, description: null, location: 'Ubicación anterior', + exact_location: { latitude: 10, longitude: 20 }, date_text: null, + attachment_id: null, image: null, + address: { id: 20, label: 'Predio', address_text: 'Dirección del evento 123', latitude: 0, longitude: -60 }, +}; + +describe('EventDetailPageComponent address', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [EventDetailPageComponent], + providers: [ + provideRouter([]), + { provide: ActivatedRoute, useValue: { paramMap: of(convertToParamMap({ slug: 'festival' })) } }, + { provide: EventService, useValue: { get: () => of({ data: event }) } }, + { provide: AuthService, useValue: {} }, + { provide: CheckoutService, useValue: {} }, + { provide: TenantService, useValue: { tenant: signal(null) } }, + { provide: ToastService, useValue: {} }, + ], + }).compileComponents(); + }); + + it('uses the event address for its text and map including zero coordinates', () => { + const fixture = TestBed.createComponent(EventDetailPageComponent); + fixture.detectChanges(); + expect(fixture.nativeElement.textContent).toContain('Dirección del evento 123'); + expect(fixture.nativeElement.textContent).not.toContain('Ubicación anterior'); + const map = fixture.debugElement.query(By.directive(LocationMapComponent)).componentInstance as LocationMapComponent; + expect(map.locations).toEqual([{ id: 20, label: 'Predio', latitude: 0, longitude: -60, address: 'Dirección del evento 123' }]); + }); + + it('shows address text without using old map coordinates when the new address has none', () => { + TestBed.overrideProvider(EventService, { useValue: { get: () => of({ data: { + ...event, address: { ...event.address!, latitude: null, longitude: null }, + } }) } }); + const fixture = TestBed.createComponent(EventDetailPageComponent); + fixture.detectChanges(); + expect(fixture.nativeElement.textContent).toContain('Dirección del evento 123'); + expect(fixture.nativeElement.querySelector('app-location-map')).toBeNull(); + }); + + it('does not use old location fields when the event has no address', () => { + TestBed.overrideProvider(EventService, { useValue: { get: () => of({ data: { ...event, address: null } }) } }); + const fixture = TestBed.createComponent(EventDetailPageComponent); + fixture.detectChanges(); + expect(fixture.nativeElement.textContent).not.toContain('Ubicación anterior'); + expect(fixture.nativeElement.querySelector('app-location-map')).toBeNull(); + }); +}); diff --git a/src/app/features/store/pages/event-detail-page/event-detail-page.component.ts b/src/app/features/store/pages/event-detail-page/event-detail-page.component.ts index e2fc382..7ff7264 100644 --- a/src/app/features/store/pages/event-detail-page/event-detail-page.component.ts +++ b/src/app/features/store/pages/event-detail-page/event-detail-page.component.ts @@ -41,15 +41,15 @@ export class EventDetailPageComponent { protected readonly submitting = signal(false); protected readonly mapLocations = computed