Files
TREK/client/src/utils/donations.test.ts
T
Maurice bcdcd69a64 feat(notices): 5.2.0 release modal and Patreon for monthly support
The release modal now shows 5.2.0: booking mails that land in the trip,
live flight status and the new trip PDF, each with its own drawn card,
and links the 5.2.0 release notes. The maintainer note and the support
block are rewritten, shorter and without the sponsor wording.

Patreon joins Buy Me a Coffee and Ko-fi as the monthly way to support
TREK: a full-width button in the release and thank-you notices (a new
optional tertiaryCta on the notice contract), a tile in About and in the
admin GitHub panel on desktop and phone, the README badges and
FUNDING.yml. Like the other donation links it stays hidden inside the
native apps.
2026-11-23 21:15:54 +01:00

54 lines
2.2 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
import { isNativeApp } from '../native/platform';
import { donationsShown, isDonationLink, noticeAsksForDonation, withoutDonationsInApp } from './donations';
vi.mock('../native/platform', () => ({ isNativeApp: vi.fn() }));
const links = [{ href: 'https://ko-fi.com/mauriceboe' }, { href: 'https://discord.gg/x' }];
beforeEach(() => {
vi.mocked(isNativeApp).mockReturnValue(false);
});
describe('isDonationLink', () => {
it('knows the donation pages, their subdomains too', () => {
expect(isDonationLink('https://ko-fi.com/mauriceboe')).toBe(true);
expect(isDonationLink('https://www.BuyMeACoffee.com/mauriceboe')).toBe(true);
expect(isDonationLink('https://www.patreon.com/cw/mauriceboe')).toBe(true);
});
it('is false for anything else, a missing href or one that is no URL', () => {
expect(isDonationLink('https://github.com/liketrek/TREK')).toBe(false);
expect(isDonationLink('https://notko-fi.com/x')).toBe(false);
expect(isDonationLink(undefined)).toBe(false);
expect(isDonationLink('not a url')).toBe(false);
});
});
describe('in a browser', () => {
it('keeps every link and every notice', () => {
expect(donationsShown()).toBe(true);
expect(withoutDonationsInApp(links)).toEqual(links);
});
});
describe('in the native app', () => {
it('drops the donation links', () => {
vi.mocked(isNativeApp).mockReturnValue(true);
expect(donationsShown()).toBe(false);
expect(withoutDonationsInApp(links)).toEqual([{ href: 'https://discord.gg/x' }]);
});
});
describe('noticeAsksForDonation', () => {
it('looks at all three buttons', () => {
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({ tertiaryCta: { kind: 'link', href: 'https://www.patreon.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);
});
});