feat(download): two-button page with the jar served by our backend

This commit is contained in:
Loki 2026-09-29 18:39:40 +02:00
parent 54af71589a
commit fc440f0c91
Signed by: boba
GPG key ID: 253067914055423B
11 changed files with 105 additions and 37 deletions

View file

@ -3,6 +3,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { afterEach, expect, test, vi } from 'vitest'
import { DownloadButton } from '../DownloadButton'
import { ReleaseNotes } from '../ReleaseNotes'
import DownloadPage from '../../../pages/download/DownloadPage'
function withQuery(ui: React.ReactElement) {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
@ -20,13 +21,28 @@ const release = (body: string) => ({
afterEach(() => vi.restoreAllMocks())
test('DownloadButton links straight to the latest lovisual.jar', () => {
test('DownloadButton links straight to the latest lovisual.jar on our own backend', () => {
const { container } = withQuery(<DownloadButton />)
const link = container.querySelector('a')
expect(link?.getAttribute('href')).toBe('/downloads/lovisual.jar')
expect(link?.getAttribute('href')).toBe('/api/downloads/lovisual.jar')
expect(link?.hasAttribute('download')).toBe(true)
})
test('the page offers both paths: our jar and a GitHub button locked behind a ribbon', async () => {
vi.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('offline'))
withQuery(<DownloadPage />)
const direct = await screen.findByRole('link', { name: 'Скачать бесплатно' })
expect(direct).toHaveAttribute('href', '/api/downloads/lovisual.jar')
expect(direct).toHaveAttribute('download')
// The GitHub path is visible but not a link, and says why.
const gh = screen.getByText('Код на GitHub')
expect(gh.closest('a')).toBeNull()
expect(gh).toHaveAttribute('aria-disabled', 'true')
expect(screen.getByText('временно не работает')).toBeInTheDocument()
})
test('ReleaseNotes renders Markdown but never raw HTML from a release body', async () => {
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,