Files
jackwener--opencli/clis/uiverse/_shared.test.js
T
wehub-resource-sync 9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

63 lines
2.3 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import {
UIVERSE_BASE_URL,
parseComponentInput,
parseHtmlRootSignature,
getPreviewFallbackTags,
inferLanguage,
getCodeLength,
} from './_shared.js';
describe('uiverse shared helpers', () => {
it('parses full URLs and author/slug identifiers', () => {
expect(parseComponentInput('Galahhad/strong-squid-82')).toEqual({
raw: 'Galahhad/strong-squid-82',
username: 'Galahhad',
slug: 'strong-squid-82',
url: `${UIVERSE_BASE_URL}/Galahhad/strong-squid-82`,
});
expect(parseComponentInput('https://uiverse.io/Galahhad/strong-squid-82')).toEqual({
raw: 'https://uiverse.io/Galahhad/strong-squid-82',
username: 'Galahhad',
slug: 'strong-squid-82',
url: `${UIVERSE_BASE_URL}/Galahhad/strong-squid-82`,
});
});
it('rejects unsupported hosts and malformed identifiers', () => {
expect(() => parseComponentInput('https://example.com/foo/bar')).toThrow('Unsupported non-Uiverse URL');
expect(() => parseComponentInput('only-author')).toThrow('Could not parse author/slug');
expect(() => parseComponentInput('a/b/c')).toThrow('Could not parse author/slug');
});
it('parses the HTML root signature', () => {
expect(parseHtmlRootSignature('<label id="x" class="theme-switch primary"></label>')).toEqual({
tag: 'label',
id: 'x',
classes: ['theme-switch', 'primary'],
});
expect(parseHtmlRootSignature('')).toEqual({ tag: null, id: null, classes: [] });
});
it('uses broader preview fallback tags for input roots', () => {
expect(getPreviewFallbackTags({ tag: 'input' })).toEqual(['input', 'label', 'button', 'a', 'div']);
expect(getPreviewFallbackTags({ tag: 'label' })).toEqual(['label']);
expect(getPreviewFallbackTags({ tag: null })).toEqual(['label', 'button', 'a', 'div']);
});
it('infers the language from target and metadata', () => {
expect(inferLanguage('react', {})).toBe('tsx');
expect(inferLanguage('vue', {})).toBe('vue');
expect(inferLanguage('html', { isTailwind: true })).toBe('html+tailwind');
expect(inferLanguage('css', {})).toBe('css');
expect(inferLanguage('unknown', {})).toBe('text');
});
it('returns the code length safely', () => {
expect(getCodeLength('abc')).toBe(3);
expect(getCodeLength('')).toBe(0);
expect(getCodeLength(null)).toBe(0);
});
});