Files
Void-Homelab/tests/frontend/service_tile.test.js
root 3881334a7b test(health): use programmatic jsdom in node env to keep DB tests serial
A second vitest environment spins up a parallel worker pool that collides with the
DB-backed tests on the shared void_test database (fileParallelism only serializes
within one pool). Provide the DOM via jsdom directly instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 01:21:27 +10:00

43 lines
2.1 KiB
JavaScript

import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { JSDOM } from 'jsdom';
import { serviceTile } from '../../public/components/service_tile.js';
// Provide a DOM via jsdom WITHOUT switching this file to the `jsdom` vitest
// environment — a second environment makes vitest run a parallel worker pool that
// collides with the DB-backed node tests on the shared test database. We set the
// globals dom.js needs (document/Node) for this file only and tear them down after.
beforeAll(() => {
const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/' });
global.window = dom.window;
global.document = dom.window.document;
global.Node = dom.window.Node;
global.location = dom.window.location; // safeHref() resolves against location.origin
});
afterAll(() => {
delete global.window; delete global.document; delete global.Node; delete global.location;
});
const base = { id: 'gramps', name: 'Gramps', host: 'ct109', icon: 'gramps', status: 'ok',
url: 'http://192.168.1.99', external: 'https://gramps.hynesy.com' };
describe('serviceTile', () => {
it('local: primary link is the LAN url, alt link is the domain', () => {
const t = serviceTile(base, false);
expect(t.querySelector('.tile-link').getAttribute('href')).toBe('http://192.168.1.99/');
expect(t.querySelector('.tile-alt').getAttribute('href')).toBe('https://gramps.hynesy.com/');
expect(t.querySelectorAll('a').length).toBe(2);
});
it('remote: primary is the domain, alt is the LAN url', () => {
const t = serviceTile(base, true);
expect(t.querySelector('.tile-link').getAttribute('href')).toBe('https://gramps.hynesy.com/');
expect(t.querySelector('.tile-alt').getAttribute('href')).toBe('http://192.168.1.99/');
expect(t.classList.contains('lan-only')).toBe(false);
});
it('remote + no external: lan-only, no alt, badge present', () => {
const t = serviceTile({ ...base, external: undefined }, true);
expect(t.classList.contains('lan-only')).toBe(true);
expect(t.querySelector('.tile-alt')).toBeNull();
expect(t.querySelector('.tile-lan')).not.toBeNull();
});
});