fix(portals): label the year chip with the year it navigates to

`facetYear()` reads the first four-digit run so a day-first provider date
resolves, but the templates still sliced the first four characters — so
`31-03-1999` rendered as `31-0` while the click opened 1999. The label
now comes from the same parser as the destination (`yearLabel`), and the
informational chip keeps its previous rendering only when no year parses.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
4grayandClaude Fable 5 committed 2026-08-16 10:07:58 +02:00
1 parent b9dfc12994
commit 0bd02deb4f
5 files changed
+38 -6

No files matched your search

@@ -78,6 +78,24 @@ describe('createDiscoverFacetNavigation', () => {
}
});
it('labels the chip with the year it navigates to', () => {
const discover = create(xtreamMovie);
// The label and the destination must not disagree: slicing the
// first four characters of a day-first date renders '31-0'
expect(discover.yearLabel('31-03-1999')).toBe('1999');
expect(discover.yearLabel('1999-03-31')).toBe('1999');
expect(discover.yearLabel('1976')).toBe('1976');
});
it('has no label for a date stating no usable year', () => {
const discover = create(xtreamMovie);
expect(discover.yearLabel('0000-00-00')).toBeNull();
expect(discover.yearLabel('unknown')).toBeNull();
expect(discover.yearLabel(undefined)).toBeNull();
});
it('refuses the year facet when the target cannot be reached', () => {
// Hosts return null when enrichment is off, and Discover reads its
// results from TMDB — a year chip must not promise an empty page
@@ -20,6 +20,13 @@ export interface DiscoverFacetTarget {
}
export interface DiscoverFacetNavigation {
/**
* The year a chip should DISPLAY, so its label and its destination
* cannot disagree — a day-first `31-03-1999` navigates to 1999 and
* must not render as the first four characters. `null` when the date
* states no usable year; the caller then keeps its own rendering.
*/
yearLabel(releaseDate: string | null | undefined): string | null;
canOpenYear(releaseDate: string | null | undefined): boolean;
openYear(releaseDate: string | null | undefined): void;
openGenre(genre: TmdbGenreFacet): void;
@@ -76,6 +83,10 @@ export function createDiscoverFacetNavigation(
target() !== null && facetYear(releaseDate) !== null;
return {
yearLabel(releaseDate) {
const year = facetYear(releaseDate);
return year === null ? null : String(year);
},
canOpenYear,
openYear(releaseDate) {
const year = facetYear(releaseDate);
@@ -22,11 +22,12 @@
class="details__tag details__tag--clickable"
(click)="discover.openYear(serial.info.releasedate)"
>
{{ serial.info.releasedate }}
{{ discover.yearLabel(serial.info.releasedate) }}
</button>
} @else {
<span class="details__tag">{{
serial.info.releasedate
discover.yearLabel(serial.info.releasedate) ??
serial.info.releasedate
}}</span>
}
}
@@ -23,11 +23,12 @@
class="details__tag details__tag--clickable"
(click)="discover.openYear(info.releaseDate)"
>
{{ info.releaseDate | slice: 0 : 4 }}
{{ discover.yearLabel(info.releaseDate) }}
</button>
} @else {
<span class="details__tag">{{
info.releaseDate | slice: 0 : 4
discover.yearLabel(info.releaseDate) ??
(info.releaseDate | slice: 0 : 4)
}}</span>
}
}
@@ -301,11 +301,12 @@
class="details__tag details__tag--clickable"
(click)="discover.openYear(info.releasedate)"
>
{{ info.releasedate | slice: 0 : 4 }}
{{ discover.yearLabel(info.releasedate) }}
</button>
} @else {
<span class="details__tag">{{
info.releasedate | slice: 0 : 4
discover.yearLabel(info.releasedate) ??
(info.releasedate | slice: 0 : 4)
}}</span>
}
}