Public Access
50 lines
2.1 KiB
React
50 lines
2.1 KiB
React
// @vitest-environment jsdom
|
|
import {afterEach, describe, expect, it, vi} from 'vitest';
|
|
import {cleanup, render, screen, within} from '@testing-library/react';
|
|
import BuildVersionCard from './BuildVersionCard.jsx';
|
|
|
|
vi.mock('react-i18next', () => import('../test/i18n-mock.js'));
|
|
// vite.config.js reads GIT_SHA from the shell; the test must not depend on it.
|
|
vi.mock('../utils/version.js', async (importOriginal) => ({
|
|
...await importOriginal(),
|
|
FRONTEND_VERSION: {commit: 'dev', builtAt: null},
|
|
}));
|
|
|
|
const AUTH_SHA = '4ec47f1aa0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5';
|
|
|
|
const row = (name) => screen.getByText(name).closest('li');
|
|
|
|
describe('BuildVersionCard', () => {
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.restoreAllMocks();
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
it('links the short hash of each backend and marks a service that does not answer', async () => {
|
|
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url) => (url.startsWith('http://auth')
|
|
? {ok: true, json: async () => ({commit: AUTH_SHA, builtAt: '2026-09-27T08:05:00Z'})}
|
|
: {ok: false, status: 502}));
|
|
vi.stubEnv('VITE_API_URL', 'http://auth');
|
|
vi.stubEnv('VITE_CORE_API_URL', 'http://core');
|
|
|
|
render(<BuildVersionCard/>);
|
|
|
|
const link = await within(row('Auth')).findByRole('link', {name: '4ec47f1'});
|
|
expect(link.getAttribute('href')).toBe(`https://git.andreas-dahm.eu/Lobo_Corp/ToBePlayed-Auth/commit/${AUTH_SHA}`);
|
|
expect(await within(row('Core')).findByText('SETTINGS.VERSION_UNKNOWN')).toBeTruthy();
|
|
expect(fetch).toHaveBeenCalledWith('http://auth/api/version');
|
|
expect(fetch).toHaveBeenCalledWith('http://core/api/version');
|
|
});
|
|
|
|
it('shows a local build as dev without a link', async () => {
|
|
vi.spyOn(globalThis, 'fetch').mockResolvedValue({ok: true, json: async () => ({commit: 'dev', builtAt: null})});
|
|
|
|
render(<BuildVersionCard/>);
|
|
|
|
expect(within(row('Frontend')).getByText('dev')).toBeTruthy();
|
|
expect(await within(row('Core')).findByText('dev')).toBeTruthy();
|
|
expect(screen.queryByRole('link')).toBeNull();
|
|
});
|
|
});
|