Files
MeshChatX/tests/frontend/LinkUtils.test.js
T
Sudo-Ivan ee9ed05338 Add property-based tests for display name parsing and fuzzing
- Introduced new test suite for `parse_lxmf_display_name`, `parse_nomadnetwork_node_display_name`, and related functions using Hypothesis for property-based testing.
- Added various strategies to generate diverse input data, including edge cases for invalid and long names.
- Implemented tests to ensure robustness against invalid base64 inputs and to verify expected behavior with valid and corrupted data.
- Created smoke tests for frontend components including BotsPage, ForwarderPage, and others to ensure proper rendering and functionality.
2026-01-16 08:51:48 -06:00

72 lines
3.3 KiB
JavaScript

import { describe, it, expect } from "vitest";
import LinkUtils from "@/js/LinkUtils";
describe("LinkUtils.js", () => {
describe("renderReticulumLinks", () => {
it("detects nomadnet:// links with hash and path", () => {
const text = "nomadnet://1dfeb0d794963579bd21ac8f153c77a4:/page/index.mu";
const result = LinkUtils.renderReticulumLinks(text);
expect(result).toContain('class="nomadnet-link');
expect(result).toContain('data-nomadnet-url="1dfeb0d794963579bd21ac8f153c77a4:/page/index.mu"');
});
it("detects nomadnet@ links", () => {
const text = "nomadnet@1dfeb0d794963579bd21ac8f153c77a4";
const result = LinkUtils.renderReticulumLinks(text);
expect(result).toContain('class="nomadnet-link');
expect(result).toContain('data-nomadnet-url="1dfeb0d794963579bd21ac8f153c77a4:/page/index.mu"');
});
it("detects bare hash and path links as nomadnet", () => {
const text = "1dfeb0d794963579bd21ac8f153c77a4:/page/index.mu";
const result = LinkUtils.renderReticulumLinks(text);
expect(result).toContain('class="nomadnet-link');
expect(result).toContain('data-nomadnet-url="1dfeb0d794963579bd21ac8f153c77a4:/page/index.mu"');
});
it("detects bare hash as lxmf", () => {
const text = "1dfeb0d794963579bd21ac8f153c77a4";
const result = LinkUtils.renderReticulumLinks(text);
expect(result).toContain('class="lxmf-link');
expect(result).toContain('data-lxmf-address="1dfeb0d794963579bd21ac8f153c77a4"');
});
it("detects lxmf:// links", () => {
const text = "lxmf://1dfeb0d794963579bd21ac8f153c77a4";
const result = LinkUtils.renderReticulumLinks(text);
expect(result).toContain('class="lxmf-link');
expect(result).toContain('data-lxmf-address="1dfeb0d794963579bd21ac8f153c77a4"');
});
it("detects lxmf@ links", () => {
const text = "lxmf@1dfeb0d794963579bd21ac8f153c77a4";
const result = LinkUtils.renderReticulumLinks(text);
expect(result).toContain('class="lxmf-link');
expect(result).toContain('data-lxmf-address="1dfeb0d794963579bd21ac8f153c77a4"');
});
});
describe("renderStandardLinks", () => {
it("detects http links", () => {
const text = "visit http://example.com";
const result = LinkUtils.renderStandardLinks(text);
expect(result).toContain('<a href="http://example.com"');
});
it("detects https links", () => {
const text = "visit https://example.com/path?query=1";
const result = LinkUtils.renderStandardLinks(text);
expect(result).toContain('<a href="https://example.com/path?query=1"');
});
});
describe("renderAllLinks", () => {
it("detects both types of links", () => {
const text = "Check https://google.com and nomadnet://1dfeb0d794963579bd21ac8f153c77a4";
const result = LinkUtils.renderAllLinks(text);
expect(result).toContain('href="https://google.com"');
expect(result).toContain('data-nomadnet-url="1dfeb0d794963579bd21ac8f153c77a4:/page/index.mu"');
});
});
});