mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-14 08:11:03 +00:00
fix(native): read a notice button's href without a weak type
An action button carries no href, so a parameter typed as only an optional href refused the notice DTO; the button type now names its kind as well.
This commit is contained in:
@@ -42,9 +42,10 @@ describe('in the native app', () => {
|
||||
|
||||
describe('noticeAsksForDonation', () => {
|
||||
it('looks at both buttons', () => {
|
||||
expect(noticeAsksForDonation({ cta: { href: 'https://ko-fi.com/x' } })).toBe(true);
|
||||
expect(noticeAsksForDonation({ secondaryCta: { href: 'https://buymeacoffee.com/x' } })).toBe(true);
|
||||
expect(noticeAsksForDonation({ cta: { href: '/settings' }, secondaryCta: null })).toBe(false);
|
||||
expect(noticeAsksForDonation({ cta: { kind: 'link', href: 'https://ko-fi.com/x' } })).toBe(true);
|
||||
expect(noticeAsksForDonation({ secondaryCta: { kind: 'link', href: 'https://buymeacoffee.com/x' } })).toBe(true);
|
||||
expect(noticeAsksForDonation({ cta: { kind: 'nav', href: '/settings' }, secondaryCta: null })).toBe(false);
|
||||
expect(noticeAsksForDonation({ cta: { kind: 'action' } })).toBe(false);
|
||||
expect(noticeAsksForDonation({})).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,10 +29,10 @@ export function withoutDonationsInApp<T extends { href: string }>(links: T[]): T
|
||||
return donationsShown() ? links : links.filter((link) => !isDonationLink(link.href));
|
||||
}
|
||||
|
||||
/** A notice button: a link or a navigation carries an href, an action does not. */
|
||||
type NoticeButton = { kind: string; href?: string } | null | undefined;
|
||||
|
||||
/** Whether a system notice asks for a donation through one of its buttons. */
|
||||
export function noticeAsksForDonation(notice: {
|
||||
cta?: { href?: string } | null;
|
||||
secondaryCta?: { href?: string } | null;
|
||||
}): boolean {
|
||||
export function noticeAsksForDonation(notice: { cta?: NoticeButton; secondaryCta?: NoticeButton }): boolean {
|
||||
return isDonationLink(notice.cta?.href) || isDonationLink(notice.secondaryCta?.href);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user