Compare commits
6 Commits
f70b93922e
...
feature/sh
| Author | SHA1 | Date | |
|---|---|---|---|
| 663d65a480 | |||
| 96e51b060e | |||
| 1edbd84be6 | |||
| b6ab36437b | |||
| d9bf729a96 | |||
| c851272ebe |
@@ -1,39 +1,52 @@
|
||||
@if (open() && categories().length) {
|
||||
<section class="dropdown-menu show p-2 category-dropdown" role="menu" aria-label="Categorías">
|
||||
@for (category of categories(); track category.id) {
|
||||
<div class="dropdown-submenu">
|
||||
<section
|
||||
class="dropdown-menu show p-2 category-dropdown"
|
||||
role="menu"
|
||||
aria-label="Categorías"
|
||||
(pointerleave)="onPointerLeave($event)"
|
||||
>
|
||||
<ng-container
|
||||
*ngTemplateOutlet="categoryTree; context: { $implicit: categories(), depth: 0 }"
|
||||
/>
|
||||
</section>
|
||||
}
|
||||
|
||||
<ng-template #categoryTree let-nodes let-depth="depth">
|
||||
@for (category of nodes; track category.id) {
|
||||
<div class="dropdown-submenu" (pointerenter)="onPointerEnter($event, category, depth)">
|
||||
<button
|
||||
type="button"
|
||||
class="dropdown-item d-flex align-items-center justify-content-between gap-3"
|
||||
[class.active]="activeCategory()?.id === category.id"
|
||||
[class.active]="isExpanded(category, depth)"
|
||||
role="menuitem"
|
||||
[attr.aria-expanded]="category.subcategories.length ? activeCategory()?.id === category.id : null"
|
||||
[attr.aria-expanded]="category.subcategories.length ? isExpanded(category, depth) : null"
|
||||
[attr.aria-controls]="
|
||||
category.subcategories.length ? 'store-category-submenu-' + category.id : null
|
||||
"
|
||||
(focus)="onFocus(category, depth)"
|
||||
(click)="selectCategory(category)"
|
||||
>
|
||||
<span>{{ category.nombre }}</span>
|
||||
@if (category.subcategories.length) {
|
||||
<i class="fa-solid fa-chevron-right" aria-hidden="true"></i>
|
||||
<i class="fa-solid fa-chevron-right d-none d-md-inline" aria-hidden="true"></i>
|
||||
}
|
||||
</button>
|
||||
|
||||
@if (activeCategory()?.id === category.id && subcategories().length) {
|
||||
<div class="dropdown-menu show p-2 category-dropdown__submenu">
|
||||
@for (subcategory of subcategories(); track subcategory.id) {
|
||||
<button
|
||||
type="button"
|
||||
class="dropdown-item d-flex align-items-center justify-content-between gap-3"
|
||||
role="menuitem"
|
||||
(click)="categorySelect.emit(subcategory)"
|
||||
@if (isExpanded(category, depth) && category.subcategories.length) {
|
||||
<div
|
||||
class="dropdown-menu show p-2 category-dropdown__submenu"
|
||||
role="menu"
|
||||
[id]="'store-category-submenu-' + category.id"
|
||||
[attr.aria-label]="'Subcategorías de ' + category.nombre"
|
||||
>
|
||||
<span>{{ subcategory.nombre }}</span>
|
||||
@if (subcategory.subcategories.length) {
|
||||
<i class="fa-solid fa-chevron-right" aria-hidden="true"></i>
|
||||
}
|
||||
</button>
|
||||
}
|
||||
<ng-container
|
||||
*ngTemplateOutlet="
|
||||
categoryTree;
|
||||
context: { $implicit: category.subcategories, depth: depth + 1 }
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
</ng-template>
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { CategoryDropdownComponent } from './category-dropdown.component';
|
||||
import { Category } from '../../../../services/tenant.interface';
|
||||
|
||||
describe('CategoryDropdownComponent', () => {
|
||||
const parent: Category = {
|
||||
id: 1,
|
||||
nombre: 'Indumentaria',
|
||||
subcategories: [
|
||||
{
|
||||
id: 2,
|
||||
nombre: 'Buzos',
|
||||
subcategories: [{ id: 3, nombre: 'Con capucha', subcategories: [] }],
|
||||
},
|
||||
],
|
||||
};
|
||||
const leaf: Category = { id: 4, nombre: 'Accesorios', subcategories: [] };
|
||||
|
||||
beforeEach(() => TestBed.configureTestingModule({ imports: [CategoryDropdownComponent] }));
|
||||
|
||||
function create() {
|
||||
const fixture = TestBed.createComponent(CategoryDropdownComponent);
|
||||
fixture.componentRef.setInput('categories', [parent, leaf]);
|
||||
fixture.componentRef.setInput('open', true);
|
||||
fixture.detectChanges();
|
||||
return fixture;
|
||||
}
|
||||
|
||||
function pointer(element: Element, type: string) {
|
||||
const event = new Event(type);
|
||||
Object.defineProperty(event, 'pointerType', { value: 'mouse' });
|
||||
element.dispatchEvent(event);
|
||||
}
|
||||
|
||||
it('opens subcategories on hover and navigates to the parent on click', () => {
|
||||
const fixture = create();
|
||||
const element = fixture.nativeElement as HTMLElement;
|
||||
const select = vi.fn();
|
||||
fixture.componentInstance.categorySelect.subscribe(select);
|
||||
expect(element.querySelector('.category-dropdown__submenu')).toBeNull();
|
||||
pointer(element.querySelector('.dropdown-submenu')!, 'pointerenter');
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('.category-dropdown__submenu')?.textContent).toContain('Buzos');
|
||||
expect(select).not.toHaveBeenCalled();
|
||||
element.querySelector<HTMLButtonElement>('.dropdown-item')!.click();
|
||||
expect(select).toHaveBeenCalledWith(parent);
|
||||
});
|
||||
|
||||
it('supports nested hover menus and closes them when leaving the dropdown', () => {
|
||||
const fixture = create();
|
||||
const element = fixture.nativeElement as HTMLElement;
|
||||
pointer(element.querySelector('.dropdown-submenu')!, 'pointerenter');
|
||||
fixture.detectChanges();
|
||||
pointer(
|
||||
element.querySelector('.category-dropdown__submenu .dropdown-submenu')!,
|
||||
'pointerenter',
|
||||
);
|
||||
fixture.detectChanges();
|
||||
expect(element.textContent).toContain('Con capucha');
|
||||
pointer(element.querySelector('.category-dropdown')!, 'pointerleave');
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('.category-dropdown__submenu')).toBeNull();
|
||||
});
|
||||
|
||||
it('opens subcategories with keyboard focus and navigates leaf categories', () => {
|
||||
const fixture = create();
|
||||
const element = fixture.nativeElement as HTMLElement;
|
||||
element.querySelector('.dropdown-item')!.dispatchEvent(new Event('focus'));
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('.category-dropdown__submenu')).not.toBeNull();
|
||||
const select = vi.fn();
|
||||
fixture.componentInstance.categorySelect.subscribe(select);
|
||||
const buttons = Array.from(element.querySelectorAll<HTMLButtonElement>('.dropdown-item'));
|
||||
buttons.find((button) => button.textContent?.trim() === 'Accesorios')!.click();
|
||||
expect(select).toHaveBeenCalledWith(leaf);
|
||||
});
|
||||
|
||||
it('clears expanded menus when closed or when their category is removed', () => {
|
||||
const fixture = create();
|
||||
const element = fixture.nativeElement as HTMLElement;
|
||||
pointer(element.querySelector('.dropdown-submenu')!, 'pointerenter');
|
||||
fixture.detectChanges();
|
||||
fixture.componentRef.setInput('open', false);
|
||||
fixture.detectChanges();
|
||||
fixture.componentRef.setInput('open', true);
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('.category-dropdown__submenu')).toBeNull();
|
||||
pointer(element.querySelector('.dropdown-submenu')!, 'pointerenter');
|
||||
fixture.detectChanges();
|
||||
fixture.componentRef.setInput('categories', [leaf]);
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('.category-dropdown__submenu')).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,12 @@
|
||||
import { ChangeDetectionStrategy, Component, computed, effect, input, output, signal } from '@angular/core';
|
||||
import { NgTemplateOutlet } from '@angular/common';
|
||||
import { ChangeDetectionStrategy, Component, effect, input, output, signal } from '@angular/core';
|
||||
|
||||
import { Category } from '../../../../services/tenant.interface';
|
||||
|
||||
@Component({
|
||||
selector: 'app-category-dropdown',
|
||||
standalone: true,
|
||||
imports: [NgTemplateOutlet],
|
||||
templateUrl: './category-dropdown.component.html',
|
||||
styleUrl: './category-dropdown.component.scss',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
@@ -14,33 +16,53 @@ export class CategoryDropdownComponent {
|
||||
readonly open = input(false);
|
||||
readonly categorySelect = output<Category>();
|
||||
|
||||
protected readonly activeCategory = signal<Category | null>(null);
|
||||
protected readonly subcategories = computed(() => this.activeCategory()?.subcategories ?? []);
|
||||
protected readonly expandedPath = signal<readonly number[]>([]);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const categories = this.categories();
|
||||
const activeCategory = this.activeCategory();
|
||||
|
||||
if (!this.open()) {
|
||||
this.activeCategory.set(null);
|
||||
this.expandedPath.set([]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeCategory && !categories.some((category) => category.id === activeCategory.id)) {
|
||||
this.activeCategory.set(null);
|
||||
let nodes: readonly Category[] = categories;
|
||||
const validPath: number[] = [];
|
||||
for (const id of this.expandedPath()) {
|
||||
const category = nodes.find((node) => node.id === id);
|
||||
if (!category?.subcategories.length) break;
|
||||
validPath.push(id);
|
||||
nodes = category.subcategories;
|
||||
}
|
||||
if (validPath.length !== this.expandedPath().length) {
|
||||
this.expandedPath.set(validPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected selectCategory(category: Category): void {
|
||||
if (category.subcategories.length) {
|
||||
this.activeCategory.update((activeCategory) =>
|
||||
activeCategory?.id === category.id ? null : category,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this.categorySelect.emit(category);
|
||||
}
|
||||
|
||||
protected isExpanded(category: Category, depth: number): boolean {
|
||||
return this.expandedPath()[depth] === category.id;
|
||||
}
|
||||
|
||||
protected expand(category: Category, depth: number): void {
|
||||
this.expandedPath.update((path) => [
|
||||
...path.slice(0, depth),
|
||||
...(category.subcategories.length ? [category.id] : []),
|
||||
]);
|
||||
}
|
||||
|
||||
protected onPointerEnter(event: PointerEvent, category: Category, depth: number): void {
|
||||
if (event.pointerType === 'mouse') this.expand(category, depth);
|
||||
}
|
||||
|
||||
protected onPointerLeave(event: PointerEvent): void {
|
||||
if (event.pointerType === 'mouse') this.expandedPath.set([]);
|
||||
}
|
||||
|
||||
protected onFocus(category: Category, depth: number): void {
|
||||
this.expand(category, depth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@
|
||||
<app-store-footer
|
||||
[currentYear]="currentYear"
|
||||
[footerSections]="footerSections()"
|
||||
[socialMedia]="tenant()?.social_media ?? []"
|
||||
[socialMedia]="tenant()?.tenant_social_media ?? tenant()?.social_media ?? []"
|
||||
[logoUrl]="tenant()?.footer_logo ?? null"
|
||||
[backgroundImageUrl]="tenant()?.footer_bg_image ?? null"
|
||||
[storeName]="tenant()?.nombre ?? null"
|
||||
[address]="tenant()?.address ?? null"
|
||||
[phone]="tenant()?.phone ?? null"
|
||||
[address]="tenant()?.main_address?.address_text ?? null"
|
||||
[phone]="tenant()?.main_phone_number?.number ?? null"
|
||||
(logoutClick)="onLogoutClick()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -35,7 +35,9 @@ 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',
|
||||
main_phone_number: { id: 1, label: 'Principal', number: '+54 341 555 1234', tel_url: 'tel:+543415551234' },
|
||||
primary_color: '#6376F3',
|
||||
secondary_color: '#A0A0A0',
|
||||
danger_color: '#FF8888',
|
||||
@@ -563,6 +565,50 @@ 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('uses commerce social networks in the footer and respects an empty collection', () => {
|
||||
tenantState.set({ ...tenant, tenant_social_media: [
|
||||
{ ...tenant.social_media![0], url: 'https://instagram.com/commerce-contact' },
|
||||
] });
|
||||
const fixture = TestBed.createComponent(StoreLayoutComponent);
|
||||
fixture.detectChanges();
|
||||
const footer = fixture.nativeElement.querySelector('app-store-footer') as HTMLElement;
|
||||
expect(footer.querySelector('a[href="https://instagram.com/commerce-contact"]')).not.toBeNull();
|
||||
tenantState.set({ ...tenant, tenant_social_media: [] });
|
||||
fixture.detectChanges();
|
||||
expect(footer.querySelector('a[href="https://instagram.com/commerce-contact"]')).toBeNull();
|
||||
expect(footer.querySelector('a[href="' + tenant.social_media![0].url + '"]')).toBeNull();
|
||||
});
|
||||
|
||||
it('uses only the main phone number in the footer', () => {
|
||||
tenantState.set({ ...tenant, main_phone_number: {
|
||||
id: 10, label: 'Principal', number: '3411234567', tel_url: 'tel:3411234567',
|
||||
} });
|
||||
const fixture = TestBed.createComponent(StoreLayoutComponent);
|
||||
fixture.detectChanges();
|
||||
const footer = fixture.nativeElement.querySelector('app-store-footer') as HTMLElement;
|
||||
expect(footer.textContent).toContain('3411234567');
|
||||
expect(footer.textContent).not.toContain(tenant.phone);
|
||||
tenantState.set({ ...tenant, main_phone_number: null });
|
||||
fixture.detectChanges();
|
||||
expect(footer.textContent).not.toContain('3411234567');
|
||||
expect(footer.textContent).not.toContain(tenant.phone);
|
||||
});
|
||||
|
||||
it('navigates to search results when the search button is clicked', () => {
|
||||
const router = TestBed.inject(Router);
|
||||
vi.spyOn(router, 'navigate');
|
||||
|
||||
11
src/app/core/services/address.interface.ts
Normal file
11
src/app/core/services/address.interface.ts
Normal file
@@ -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;
|
||||
}
|
||||
@@ -170,6 +170,7 @@ export interface CatalogCategory {
|
||||
id: number;
|
||||
nombre: string;
|
||||
categoria_id: number | null;
|
||||
banner_url?: string | null;
|
||||
}
|
||||
|
||||
export interface CategoryItemsResponse extends ApiPaginatedResponse<CatalogFeaturedItem[]> {
|
||||
|
||||
@@ -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;
|
||||
|
||||
10
src/app/core/services/phone-number.interface.ts
Normal file
10
src/app/core/services/phone-number.interface.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface PhoneNumber {
|
||||
id: number;
|
||||
label: string;
|
||||
number: string;
|
||||
tel_url: string;
|
||||
}
|
||||
|
||||
export interface TenantPhoneNumber extends PhoneNumber {
|
||||
is_main: boolean;
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { ApiResponse } from './api-response.interface';
|
||||
import { Address, TenantAddress } from './address.interface';
|
||||
import { PhoneNumber, TenantPhoneNumber } from './phone-number.interface';
|
||||
|
||||
export type CartEditingPolicyCode = 'disabled' | 'quantity_and_remove' | 'full';
|
||||
|
||||
@@ -69,13 +71,14 @@ export interface TenantEvent {
|
||||
subtitle: string | null;
|
||||
description: string | null;
|
||||
location: string | null;
|
||||
address?: Address | null;
|
||||
date_text: string | null;
|
||||
dates: ActiveEventDate[];
|
||||
social_media: SocialMedia[];
|
||||
}
|
||||
|
||||
export interface WebsiteExtras {
|
||||
carousel?: string[];
|
||||
carousel?: (string | { desktop: string; mobile: string })[];
|
||||
immersiveHeroCarousel?: string[];
|
||||
immersiveHero?: {
|
||||
eyebrow: string;
|
||||
@@ -121,7 +124,11 @@ export interface Tenant {
|
||||
site_title?: string | null;
|
||||
asset_url?: string | null;
|
||||
address?: string | null;
|
||||
addresses?: TenantAddress[];
|
||||
main_address?: Address | null;
|
||||
phone?: string | null;
|
||||
phone_numbers?: TenantPhoneNumber[];
|
||||
main_phone_number?: PhoneNumber | null;
|
||||
favicon?: string | null;
|
||||
primary_color: string;
|
||||
secondary_color: string;
|
||||
@@ -154,6 +161,7 @@ export interface Tenant {
|
||||
allow_ticket_partial_refund?: boolean;
|
||||
ticket_partial_refund_percentage?: string;
|
||||
social_media?: SocialMedia[];
|
||||
tenant_social_media?: SocialMedia[];
|
||||
menues?: Menu[];
|
||||
categories?: Category[];
|
||||
event_categories?: Category[];
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
@if (event().date_text) {
|
||||
<p class="event-card__meta"><i class="fa-regular fa-calendar" aria-hidden="true"></i>{{ event().date_text }}</p>
|
||||
}
|
||||
@if (event().location) {
|
||||
<p class="event-card__meta"><i class="fa-solid fa-location-dot" aria-hidden="true"></i>{{ event().location }}</p>
|
||||
@if (event().address?.address_text; as location) {
|
||||
<p class="event-card__meta"><i class="fa-solid fa-location-dot" aria-hidden="true"></i>{{ location }}</p>
|
||||
}
|
||||
</div>
|
||||
</a>
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
@if (error()) {
|
||||
<p class="alert text-center mb-0 category-items__alert-error">{{ error() }}</p>
|
||||
} @else if (results(); as categoryResults) {
|
||||
<header class="category-items__header mb-5">
|
||||
@if (categoryResults.category.banner_url; as bannerUrl) {
|
||||
<img
|
||||
class="category-items__banner"
|
||||
[src]="bannerUrl"
|
||||
[alt]="'Banner de ' + categoryResults.category.nombre"
|
||||
/>
|
||||
}
|
||||
<header class="category-items__header">
|
||||
<h1 id="category-items-title" class="category-items__title mb-0">
|
||||
{{ categoryResults.category.nombre }}
|
||||
</h1>
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
app-category-items-page {
|
||||
display: block;
|
||||
}
|
||||
|
||||
// Override the layout's Bootstrap padding only while this page is mounted.
|
||||
app-store-layout main > section.py-5:has(app-category-items-page) {
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
|
||||
.category-items__banner {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 170px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.category-items__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 16px 28px;
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.category-items__title {
|
||||
font-size: 24px;
|
||||
font-size: 15px;
|
||||
font-weight: bold;
|
||||
line-height: 1.2;
|
||||
text-align: center;
|
||||
color:var(--bs-primary)
|
||||
text-align: left;
|
||||
text-transform: uppercase;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.category-items__alert-error {
|
||||
|
||||
@@ -106,6 +106,30 @@ describe('CategoryItemsPageComponent', () => {
|
||||
expect(productList.layout()).toBe('row');
|
||||
expect(productList.groupLayout()).toBe('paginated');
|
||||
expect(Array.isArray(productList.items())).toBe(false);
|
||||
expect(fixture.nativeElement.querySelector('.category-items__banner')).toBeNull();
|
||||
});
|
||||
|
||||
it('renders the category banner above the title when the API returns its URL', () => {
|
||||
getCategoryItems.mockReturnValue(
|
||||
of({
|
||||
category: {
|
||||
id: 7,
|
||||
nombre: 'Remeras',
|
||||
categoria_id: null,
|
||||
banner_url: 'https://example.com/banner.jpg',
|
||||
},
|
||||
data: [],
|
||||
}),
|
||||
);
|
||||
|
||||
const fixture = TestBed.createComponent(CategoryItemsPageComponent);
|
||||
fixture.detectChanges();
|
||||
|
||||
const element = fixture.nativeElement as HTMLElement;
|
||||
const banner = element.querySelector<HTMLImageElement>('.category-items__banner');
|
||||
expect(banner?.getAttribute('src')).toBe('https://example.com/banner.jpg');
|
||||
expect(banner?.alt).toBe('Banner de Remeras');
|
||||
expect(banner?.nextElementSibling?.querySelector('h1')?.textContent).toContain('Remeras');
|
||||
});
|
||||
|
||||
it('reloads the current category page when catalog availability changes', () => {
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
Component,
|
||||
DestroyRef,
|
||||
Injector,
|
||||
ViewEncapsulation,
|
||||
inject,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
@@ -51,6 +52,7 @@ interface CategoryRouteState {
|
||||
imports: [ProductListComponent],
|
||||
templateUrl: './category-items-page.component.html',
|
||||
styleUrl: './category-items-page.component.scss',
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class CategoryItemsPageComponent {
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
{{ item.date_text }}@if (item.dates?.length === 1 && item.start_time) { · {{ item.start_time.slice(0, 5) }} h }
|
||||
</p>
|
||||
}
|
||||
@if (item.location) {
|
||||
<p><i class="fa-solid fa-location-dot" aria-hidden="true"></i>{{ item.location }}</p>
|
||||
@if (item.address?.address_text; as location) {
|
||||
<p><i class="fa-solid fa-location-dot" aria-hidden="true"></i>{{ location }}</p>
|
||||
}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -41,15 +41,15 @@ export class EventDetailPageComponent {
|
||||
protected readonly submitting = signal(false);
|
||||
protected readonly mapLocations = computed<MapLocation[]>(() => {
|
||||
const event = this.event();
|
||||
const coordinates = event?.exact_location;
|
||||
if (!event || !coordinates) return [];
|
||||
const address = event?.address;
|
||||
if (!event || !address || address.latitude === null || address.longitude === null) return [];
|
||||
|
||||
return [{
|
||||
id: event.id,
|
||||
label: event.title,
|
||||
latitude: coordinates.latitude,
|
||||
longitude: coordinates.longitude,
|
||||
address: event.location ?? undefined,
|
||||
id: address.id,
|
||||
label: address.label,
|
||||
latitude: address.latitude,
|
||||
longitude: address.longitude,
|
||||
address: address.address_text,
|
||||
}];
|
||||
});
|
||||
protected readonly total = computed(() => (this.event()?.catalog_items ?? []).reduce((sum, product) => {
|
||||
|
||||
@@ -1,22 +1,34 @@
|
||||
<app-menu-content-section menuCode="help.contact" titleId="contact-page-title">
|
||||
<div class="contact-page">
|
||||
<div class="contact-page__details">
|
||||
@if (contact().whatsappUrl && contact().whatsappLabel) {
|
||||
@for (whatsapp of contact().whatsapp; track whatsapp.code) {
|
||||
<a
|
||||
class="contact-page__contact-link"
|
||||
[href]="contact().whatsappUrl"
|
||||
[href]="whatsapp.url"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<i class="fa-brands fa-whatsapp" aria-hidden="true"></i>
|
||||
<span>{{ contact().whatsappLabel }}</span>
|
||||
<i [class]="whatsapp.icon" aria-hidden="true"></i>
|
||||
<span>{{ whatsapp.name }}</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (contact().phone; as phone) {
|
||||
<a class="contact-page__contact-link" [href]="phoneUrl(phone)">
|
||||
@for (social of contact().socialMedia; track social.code) {
|
||||
<a
|
||||
class="contact-page__contact-link"
|
||||
[href]="social.url"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<i [class]="social.icon" aria-hidden="true"></i>
|
||||
<span>{{ social.name }}</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@for (phone of contact().phones; track phone.id) {
|
||||
<a class="contact-page__contact-link" [href]="phone.tel_url">
|
||||
<i class="fa-solid fa-phone" aria-hidden="true"></i>
|
||||
<span>{{ phone }}</span>
|
||||
<span>{{ phone.label }}: {{ phone.number }}</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@@ -35,7 +47,12 @@
|
||||
</article>
|
||||
}
|
||||
|
||||
@if (!contact().whatsappUrl && !contact().phone && contact().locations.length === 0) {
|
||||
@if (
|
||||
contact().whatsapp.length === 0 &&
|
||||
contact().socialMedia.length === 0 &&
|
||||
contact().phones.length === 0 &&
|
||||
contact().locations.length === 0
|
||||
) {
|
||||
<p class="contact-page__empty">No hay datos de contacto disponibles.</p>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -19,6 +19,56 @@ const tenant: Tenant = {
|
||||
header_logo: '',
|
||||
footer_logo: '',
|
||||
categories: [],
|
||||
social_media: [
|
||||
{
|
||||
code: 'whatsapp',
|
||||
name: 'WhatsApp',
|
||||
icon: 'fa-brands fa-whatsapp',
|
||||
url: 'https://wa.me/543412602222',
|
||||
},
|
||||
{
|
||||
code: 'instagram',
|
||||
name: 'Instagram',
|
||||
icon: 'fa-brands fa-instagram',
|
||||
url: 'https://www.instagram.com/comercio',
|
||||
},
|
||||
],
|
||||
phone_numbers: [
|
||||
{
|
||||
id: 1,
|
||||
label: 'Principal',
|
||||
number: '+54 9 (0341) 6658247',
|
||||
tel_url: 'tel:+54903416658247',
|
||||
is_main: true,
|
||||
},
|
||||
{ id: 2, label: 'Ventas', number: '3411234567', tel_url: 'tel:3411234567', is_main: false },
|
||||
],
|
||||
addresses: [
|
||||
{
|
||||
id: 1,
|
||||
label: 'Gigante de Arroyito',
|
||||
address_text: 'Av. Génova 640, Rosario',
|
||||
latitude: -32.913997,
|
||||
longitude: -60.674567,
|
||||
is_main: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
label: 'Telepagos',
|
||||
address_text: 'Rioja 1150, piso 12, dpto. 3, Rosario',
|
||||
latitude: -32.94682,
|
||||
longitude: -60.63932,
|
||||
is_main: false,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: 'San Martín 2450',
|
||||
address_text: 'San Martín 2450, Santa Fe',
|
||||
latitude: -31.63333,
|
||||
longitude: -60.7,
|
||||
is_main: false,
|
||||
},
|
||||
],
|
||||
menues: [
|
||||
{
|
||||
id: 1,
|
||||
@@ -33,42 +83,8 @@ const tenant: Tenant = {
|
||||
code: 'help.contact',
|
||||
label: 'Contacto',
|
||||
parent_menu_code: 'help',
|
||||
content_type: 'static',
|
||||
content_type: 'dynamic',
|
||||
route: '/ayuda/contacto',
|
||||
static_content: {
|
||||
whatsapp: {
|
||||
whatsapp_url: 'https://wa.me/543412602222',
|
||||
whatsapp_label: 'Chatea con nosotros',
|
||||
},
|
||||
phone: '+54 9 (0341) 6658247',
|
||||
locations: {
|
||||
rosario: {
|
||||
label: 'Rosario',
|
||||
addresses: [
|
||||
{
|
||||
label: 'Gigante de Arroyito',
|
||||
address: 'Av. Génova 640, Rosario',
|
||||
coordinates: [-32.913997, -60.674567],
|
||||
},
|
||||
{
|
||||
label: 'Telepagos',
|
||||
address: 'Rioja 1150, piso 12, dpto. 3, Rosario',
|
||||
coordinates: [-32.94682, -60.63932],
|
||||
},
|
||||
],
|
||||
},
|
||||
santa_fe: {
|
||||
label: 'Santa Fe',
|
||||
addresses: [
|
||||
{
|
||||
label: 'San Martín 2450',
|
||||
address: 'San Martín 2450, Santa Fe',
|
||||
coordinates: [-31.63333, -60.7],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
submenues: [],
|
||||
},
|
||||
],
|
||||
@@ -78,15 +94,17 @@ const tenant: Tenant = {
|
||||
|
||||
describe('ContactPage', () => {
|
||||
let fixture: ComponentFixture<ContactPage>;
|
||||
let tenantState = signal<Tenant | null>(tenant);
|
||||
|
||||
beforeEach(async () => {
|
||||
tenantState = signal<Tenant | null>(tenant);
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ContactPage],
|
||||
providers: [
|
||||
{
|
||||
provide: TenantService,
|
||||
useValue: {
|
||||
tenant: signal<Tenant | null>(tenant).asReadonly(),
|
||||
tenant: tenantState.asReadonly(),
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -104,7 +122,10 @@ describe('ContactPage', () => {
|
||||
const phone = element.querySelector<HTMLAnchorElement>('a[href="tel:+54903416658247"]');
|
||||
|
||||
expect(element.textContent).toContain('CONTACTO');
|
||||
expect(whatsapp?.textContent).toContain('Chatea con nosotros');
|
||||
expect(whatsapp?.textContent).toContain('WhatsApp');
|
||||
expect(
|
||||
element.querySelector('a[href="https://www.instagram.com/comercio"]')?.textContent,
|
||||
).toContain('Instagram');
|
||||
expect(phone?.textContent).toContain('+54 9 (0341) 6658247');
|
||||
expect(element.textContent).toContain('Rosario');
|
||||
expect(element.textContent).toContain('Gigante de Arroyito');
|
||||
@@ -112,11 +133,27 @@ describe('ContactPage', () => {
|
||||
expect(element.querySelector('.contact-page__addresses')?.textContent).toContain(
|
||||
'Av. Génova 640, Rosario',
|
||||
);
|
||||
expect(element.querySelector('.contact-page__addresses')?.textContent).toContain(
|
||||
'Rioja 1150, piso 12, dpto. 3, Rosario',
|
||||
);
|
||||
expect(element.textContent).not.toContain('Santa Fe');
|
||||
expect(element.textContent).not.toContain('San Martín 2450');
|
||||
expect(element.textContent).toContain('Rioja 1150, piso 12, dpto. 3, Rosario');
|
||||
expect(element.textContent).toContain('Santa Fe');
|
||||
expect(element.textContent).toContain('San Martín 2450');
|
||||
});
|
||||
|
||||
it('uses commerce networks even when the active event has different networks', () => {
|
||||
tenantState.set({
|
||||
...tenant,
|
||||
tenant_social_media: [{ ...tenant.social_media![0], url: 'https://wa.me/commerce' }],
|
||||
social_media: [{ ...tenant.social_media![0], url: 'https://wa.me/event' }],
|
||||
});
|
||||
fixture.detectChanges();
|
||||
const element = fixture.nativeElement as HTMLElement;
|
||||
expect(element.querySelector('a[href="https://wa.me/commerce"]')).not.toBeNull();
|
||||
expect(element.querySelector('a[href="https://wa.me/event"]')).toBeNull();
|
||||
});
|
||||
|
||||
it('does not restore event networks after all commerce networks are removed', () => {
|
||||
tenantState.set({ ...tenant, tenant_social_media: [] });
|
||||
fixture.detectChanges();
|
||||
expect((fixture.nativeElement as HTMLElement).querySelector('a[href="https://wa.me/543412602222"]')).toBeNull();
|
||||
});
|
||||
|
||||
it('passes the tenant map coordinates to the reusable map component', () => {
|
||||
@@ -129,12 +166,147 @@ describe('ContactPage', () => {
|
||||
|
||||
expect(map).not.toBeNull();
|
||||
expect(map?.getAttribute('mapstyle')).toBe('standard');
|
||||
expect(accessibleLocations).toHaveLength(2);
|
||||
expect(accessibleLocations).toHaveLength(3);
|
||||
expect(map?.textContent).toContain('Gigante de Arroyito');
|
||||
expect(map?.textContent).toContain('Telepagos');
|
||||
expect(map?.textContent).toContain('Av. Génova 640, Rosario');
|
||||
expect(map?.textContent).toContain('Rioja 1150, piso 12, dpto. 3, Rosario');
|
||||
expect(directionsLinks).toHaveLength(2);
|
||||
expect(map?.textContent).not.toContain('San Martín 2450');
|
||||
expect(directionsLinks).toHaveLength(3);
|
||||
expect(map?.textContent).toContain('San Martín 2450');
|
||||
});
|
||||
|
||||
it('renders canonical numbers with the main first and never restores legacy numbers', () => {
|
||||
const element = fixture.nativeElement as HTMLElement;
|
||||
expect(element.querySelectorAll('a[href^="tel:"]')).toHaveLength(2);
|
||||
expect(element.querySelector('a[href^="tel:"]')?.textContent).toContain('Principal');
|
||||
tenantState.set({ ...tenant, phone: '999999', phone_numbers: [] });
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelectorAll('a[href^="tel:"]')).toHaveLength(0);
|
||||
expect(element.textContent).not.toContain('999999');
|
||||
expect(element.textContent).not.toContain('+54 9 (0341) 6658247');
|
||||
});
|
||||
|
||||
it('shows every canonical address and maps only addresses with coordinates', () => {
|
||||
tenantState.set({
|
||||
...tenant,
|
||||
addresses: [
|
||||
{
|
||||
id: 10,
|
||||
label: 'Principal',
|
||||
address_text: 'Nueva sede 123',
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
is_main: true,
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
label: 'Sucursal sin mapa',
|
||||
address_text: 'Otra calle 456',
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
is_main: false,
|
||||
},
|
||||
{
|
||||
id: 12,
|
||||
label: 'Otra ciudad',
|
||||
address_text: 'Tercera 789',
|
||||
latitude: -31,
|
||||
longitude: -60,
|
||||
is_main: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
fixture.detectChanges();
|
||||
const element = fixture.nativeElement as HTMLElement;
|
||||
expect(element.textContent).toContain('Nueva sede 123');
|
||||
expect(element.textContent).toContain('Otra calle 456');
|
||||
expect(element.textContent).toContain('Tercera 789');
|
||||
expect(element.textContent).not.toContain('Av. Génova 640');
|
||||
expect(element.querySelectorAll('.contact-page__location')).toHaveLength(3);
|
||||
expect(element.querySelectorAll('app-location-map .visually-hidden li')).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('does not restore old menu addresses when the canonical list is empty', () => {
|
||||
tenantState.set({ ...tenant, addresses: [] });
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelectorAll('.contact-page__location')).toHaveLength(0);
|
||||
expect(fixture.nativeElement.querySelector('app-location-map')).toBeNull();
|
||||
});
|
||||
|
||||
it('does not read old menu addresses when the address list is absent', () => {
|
||||
tenantState.set({ ...tenant, addresses: undefined });
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelectorAll('.contact-page__location')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('updates contact when the resolved social media changes to the active event channels', () => {
|
||||
tenantState.set({
|
||||
...tenant,
|
||||
social_media: [
|
||||
{
|
||||
code: 'whatsapp',
|
||||
name: 'WhatsApp del evento',
|
||||
icon: 'fa-brands fa-whatsapp',
|
||||
url: 'https://wa.me/541111111111',
|
||||
},
|
||||
],
|
||||
});
|
||||
fixture.detectChanges();
|
||||
const element = fixture.nativeElement as HTMLElement;
|
||||
expect(element.querySelector('a[href="https://wa.me/541111111111"]')?.textContent).toContain(
|
||||
'WhatsApp del evento',
|
||||
);
|
||||
expect(element.querySelector('a[href="https://wa.me/543412602222"]')).toBeNull();
|
||||
expect(element.textContent).not.toContain('Instagram');
|
||||
});
|
||||
|
||||
it('shows the main address first without reordering tenant data', () => {
|
||||
const addresses = [...tenant.addresses!].reverse();
|
||||
tenantState.set({ ...tenant, addresses });
|
||||
fixture.detectChanges();
|
||||
expect(
|
||||
fixture.nativeElement.querySelector('.contact-page__location-title')?.textContent,
|
||||
).toContain('Gigante de Arroyito');
|
||||
expect(addresses[0].id).toBe(3);
|
||||
});
|
||||
|
||||
it('ignores legacy static content and shows the empty state when no canonical data exists', () => {
|
||||
tenantState.set({
|
||||
...tenant,
|
||||
addresses: [],
|
||||
phone_numbers: [],
|
||||
social_media: [],
|
||||
menues: [
|
||||
{
|
||||
...tenant.menues![0].submenues[0],
|
||||
static_content: {
|
||||
whatsapp: {
|
||||
whatsapp_url: 'https://wa.me/549999999999',
|
||||
whatsapp_label: 'Legacy WhatsApp',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.textContent).toContain('No hay datos de contacto disponibles.');
|
||||
expect(fixture.nativeElement.textContent).not.toContain('Legacy WhatsApp');
|
||||
expect(fixture.nativeElement.querySelector('a')).toBeNull();
|
||||
expect(fixture.nativeElement.querySelector('app-location-map')).toBeNull();
|
||||
});
|
||||
|
||||
it('shows social-only contact and ignores blank social URLs', () => {
|
||||
tenantState.set({
|
||||
...tenant,
|
||||
addresses: [],
|
||||
phone_numbers: [],
|
||||
social_media: [tenant.social_media![1], { ...tenant.social_media![0], url: ' ' }],
|
||||
});
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.textContent).toContain('Instagram');
|
||||
expect(fixture.nativeElement.textContent).not.toContain(
|
||||
'No hay datos de contacto disponibles.',
|
||||
);
|
||||
expect(fixture.nativeElement.textContent).not.toContain('WhatsApp');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
|
||||
import { findMenu } from '../../../../../../core/services/menu.utils';
|
||||
import { TenantService } from '../../../../../../core/services/tenant.service';
|
||||
import { TenantPhoneNumber } from '../../../../../../core/services/phone-number.interface';
|
||||
import { SocialMedia } from '../../../../../../core/services/tenant.interface';
|
||||
import { MenuContentSectionComponent } from '../../../../components/menu-content-section/menu-content-section.component';
|
||||
import {
|
||||
LocationMapComponent,
|
||||
@@ -18,13 +19,13 @@ type ContactAddress = {
|
||||
id: string;
|
||||
label: string;
|
||||
address: string;
|
||||
coordinates: [number, number];
|
||||
coordinates: [number, number] | null;
|
||||
};
|
||||
|
||||
type ContactContent = {
|
||||
whatsappUrl: string | null;
|
||||
whatsappLabel: string | null;
|
||||
phone: string | null;
|
||||
whatsapp: SocialMedia[];
|
||||
socialMedia: SocialMedia[];
|
||||
phones: TenantPhoneNumber[];
|
||||
locations: ContactLocation[];
|
||||
mapLocations: MapLocation[];
|
||||
};
|
||||
@@ -42,108 +43,52 @@ export class ContactPage {
|
||||
() => this.tenantService.tenant()?.primary_color ?? '#6376f3',
|
||||
);
|
||||
|
||||
protected readonly contact = computed(() =>
|
||||
this.parseContactContent(
|
||||
findMenu(this.tenantService.tenant()?.menues ?? [], 'help.contact')?.static_content,
|
||||
),
|
||||
protected readonly contact = computed(() => this.buildContactContent());
|
||||
|
||||
private buildContactContent(): ContactContent {
|
||||
const tenant = this.tenantService.tenant();
|
||||
const socialMedia = (tenant?.tenant_social_media ?? tenant?.social_media ?? []).filter((social) => social.url.trim());
|
||||
const addresses = [...(tenant?.addresses ?? [])].sort(
|
||||
(a, b) => Number(b.is_main) - Number(a.is_main),
|
||||
);
|
||||
|
||||
protected phoneUrl(phone: string): string {
|
||||
const normalizedPhone = phone.replace(/[^\d+]/g, '');
|
||||
return `tel:${normalizedPhone}`;
|
||||
}
|
||||
|
||||
private parseContactContent(value: unknown): ContactContent {
|
||||
const empty: ContactContent = {
|
||||
whatsappUrl: null,
|
||||
whatsappLabel: null,
|
||||
phone: null,
|
||||
locations: [],
|
||||
mapLocations: [],
|
||||
};
|
||||
|
||||
if (!this.isRecord(value)) {
|
||||
return empty;
|
||||
}
|
||||
|
||||
const whatsapp = this.isRecord(value['whatsapp']) ? value['whatsapp'] : null;
|
||||
const locations = this.parseLocations(value['locations']).slice(0, 1);
|
||||
const locations: ContactLocation[] = addresses.map((address) => ({
|
||||
id: String(address.id),
|
||||
label: address.label,
|
||||
addresses: [
|
||||
{
|
||||
id: String(address.id),
|
||||
label: address.label,
|
||||
address: address.address_text,
|
||||
coordinates:
|
||||
address.latitude !== null && address.longitude !== null
|
||||
? [address.latitude, address.longitude]
|
||||
: null,
|
||||
},
|
||||
],
|
||||
}));
|
||||
|
||||
return {
|
||||
whatsappUrl: whatsapp ? this.stringValue(whatsapp['whatsapp_url']) : null,
|
||||
whatsappLabel: whatsapp ? this.stringValue(whatsapp['whatsapp_label']) : null,
|
||||
phone: this.stringValue(value['phone']),
|
||||
whatsapp: socialMedia.filter((social) => social.code === 'whatsapp'),
|
||||
socialMedia: socialMedia.filter((social) => social.code !== 'whatsapp'),
|
||||
phones: [...(tenant?.phone_numbers ?? [])].sort(
|
||||
(a, b) => Number(b.is_main) - Number(a.is_main),
|
||||
),
|
||||
locations,
|
||||
mapLocations: locations.flatMap((location) =>
|
||||
location.addresses.map(
|
||||
(address): MapLocation => ({
|
||||
location.addresses.flatMap((address): MapLocation[] =>
|
||||
address.coordinates === null
|
||||
? []
|
||||
: [
|
||||
{
|
||||
id: address.id,
|
||||
label: address.label,
|
||||
latitude: address.coordinates[0],
|
||||
longitude: address.coordinates[1],
|
||||
address: address.address,
|
||||
}),
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
private parseLocations(value: unknown): ContactLocation[] {
|
||||
return this.recordEntries(value).flatMap(([id, item]): ContactLocation[] => {
|
||||
if (!this.isRecord(item)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const label = this.stringValue(item['label']);
|
||||
const addresses: ContactAddress[] = Array.isArray(item['addresses'])
|
||||
? item['addresses'].flatMap((address, index): ContactAddress[] => {
|
||||
if (!this.isRecord(address)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const addressLabel = this.stringValue(address['label']);
|
||||
const addressText = this.stringValue(address['address']);
|
||||
const coordinates = address['coordinates'];
|
||||
|
||||
if (
|
||||
!addressLabel ||
|
||||
!addressText ||
|
||||
!Array.isArray(coordinates) ||
|
||||
coordinates.length !== 2 ||
|
||||
typeof coordinates[0] !== 'number' ||
|
||||
typeof coordinates[1] !== 'number'
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
id: `${id}-${index}`,
|
||||
label: addressLabel,
|
||||
address: addressText,
|
||||
coordinates: [coordinates[0], coordinates[1]],
|
||||
},
|
||||
];
|
||||
})
|
||||
: [];
|
||||
|
||||
return label && addresses.length > 0 ? [{ id, label, addresses }] : [];
|
||||
});
|
||||
}
|
||||
|
||||
private recordEntries(value: unknown): [string, unknown][] {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item, index) => [String(index), item]);
|
||||
}
|
||||
|
||||
return this.isRecord(value) ? Object.entries(value) : [];
|
||||
}
|
||||
|
||||
private stringValue(value: unknown): string | null {
|
||||
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
||||
}
|
||||
|
||||
private isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
||||
return {
|
||||
id: event.id,
|
||||
title: event.title,
|
||||
location: event.location,
|
||||
location: event.address?.address_text ?? null,
|
||||
dates_text: event.date_text,
|
||||
dates: event.dates.map((eventDate) => ({
|
||||
id: eventDate.id,
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
>
|
||||
<div class="main-carousel__viewport" aria-live="off">
|
||||
@for (image of images(); track $index; let index = $index) {
|
||||
<picture>
|
||||
<source media="(max-width: 576px)" [attr.srcset]="mobileImageSource(image, index)" />
|
||||
<img
|
||||
class="main-carousel__image"
|
||||
[class.main-carousel__image--active]="index === activeIndex()"
|
||||
@@ -24,6 +26,7 @@
|
||||
(load)="handleImageLoad(index)"
|
||||
(error)="handleImageError(index)"
|
||||
/>
|
||||
</picture>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
&__viewport {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
aspect-ratio: 4 / 1;
|
||||
min-height: 9rem;
|
||||
max-height: 25rem;
|
||||
aspect-ratio: 355 / 90;
|
||||
}
|
||||
|
||||
&__image {
|
||||
|
||||
@@ -18,12 +18,20 @@ class TestHostComponent {
|
||||
readonly images = ['/images/one.webp', '/images/two.webp', '/images/three.webp'];
|
||||
}
|
||||
|
||||
@Component({
|
||||
imports: [MainCarouselComponent],
|
||||
template: `<app-main-carousel [images]="images" />`,
|
||||
})
|
||||
class ResponsiveTestHostComponent {
|
||||
readonly images = [{ desktop: '/images/desktop.webp', mobile: '/images/mobile.webp' }];
|
||||
}
|
||||
|
||||
describe('MainCarouselComponent', () => {
|
||||
let fixture: ComponentFixture<TestHostComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TestHostComponent],
|
||||
imports: [TestHostComponent, ResponsiveTestHostComponent],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(TestHostComponent);
|
||||
@@ -41,6 +49,19 @@ describe('MainCarouselComponent', () => {
|
||||
expect(images[0].classList).toContain('main-carousel__image--active');
|
||||
});
|
||||
|
||||
it('usa la variante móvil del crop cuando está disponible', () => {
|
||||
const responsiveFixture = TestBed.createComponent(ResponsiveTestHostComponent);
|
||||
responsiveFixture.detectChanges();
|
||||
|
||||
const picture = responsiveFixture.nativeElement.querySelector('picture') as HTMLPictureElement;
|
||||
const source = picture.querySelector('source') as HTMLSourceElement;
|
||||
const image = picture.querySelector('img') as HTMLImageElement;
|
||||
|
||||
expect(source.getAttribute('media')).toBe('(max-width: 576px)');
|
||||
expect(source.getAttribute('srcset')).toBe('/images/mobile.webp');
|
||||
expect(image.getAttribute('src')).toBe('/images/desktop.webp');
|
||||
});
|
||||
|
||||
it('carga las imágenes secuencialmente y prioriza la imagen visible', () => {
|
||||
const images = fixture.nativeElement.querySelectorAll(
|
||||
'.main-carousel__image',
|
||||
|
||||
@@ -11,6 +11,9 @@ import {
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { isPlatformBrowser } from '@angular/common';
|
||||
import type { WebsiteExtras } from '../../../core/services/tenant.interface';
|
||||
|
||||
type CarouselImage = NonNullable<WebsiteExtras['carousel']>[number];
|
||||
|
||||
@Component({
|
||||
selector: 'app-main-carousel',
|
||||
@@ -26,7 +29,7 @@ export class MainCarouselComponent {
|
||||
private readonly settledIndexes = signal<ReadonlySet<number>>(new Set());
|
||||
private firstImageReadyEmitted = false;
|
||||
|
||||
readonly images = input.required<readonly string[]>();
|
||||
readonly images = input.required<readonly CarouselImage[]>();
|
||||
readonly imageAlts = input<readonly string[]>([]);
|
||||
readonly autoSlideInterval = input(5000);
|
||||
readonly ariaLabel = input('Imágenes destacadas');
|
||||
@@ -91,13 +94,21 @@ export class MainCarouselComponent {
|
||||
this.paused.set(paused);
|
||||
}
|
||||
|
||||
protected imageSource(image: string, index: number): string | null {
|
||||
protected imageSource(image: CarouselImage, index: number): string | null {
|
||||
const shouldLoad =
|
||||
this.loadedIndexes().has(index) ||
|
||||
index === this.sequentialLoadIndex() ||
|
||||
index === this.activeIndex();
|
||||
|
||||
return shouldLoad ? image : null;
|
||||
return shouldLoad ? (typeof image === 'string' ? image : image.desktop) : null;
|
||||
}
|
||||
|
||||
protected mobileImageSource(image: CarouselImage, index: number): string | null {
|
||||
if (typeof image === 'string' || this.imageSource(image, index) === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return image.mobile;
|
||||
}
|
||||
|
||||
protected handleImageLoad(index: number): void {
|
||||
|
||||
Reference in New Issue
Block a user