diff --git a/client/src/utils/donations.test.ts b/client/src/utils/donations.test.ts index bf7f25823..612b428b8 100644 --- a/client/src/utils/donations.test.ts +++ b/client/src/utils/donations.test.ts @@ -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); }); }); diff --git a/client/src/utils/donations.ts b/client/src/utils/donations.ts index 547dff238..41da203ff 100644 --- a/client/src/utils/donations.ts +++ b/client/src/utils/donations.ts @@ -29,10 +29,10 @@ export function withoutDonationsInApp(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); }