mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
test(backend): remove duplicate and useless tests (#2820)
This commit is contained in:
1 parent
deac653a9e
commit
56e04e7b53
102 files changed
+10
-15831
No files matched your search
@@ -1,40 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {decode} from 'html-entities';
|
||||
|
||||
export function decodeHTMLEntities(html?: string | null): string {
|
||||
if (!html) return '';
|
||||
return decode(html);
|
||||
}
|
||||
|
||||
export function stripHtmlTags(html?: string | null): string {
|
||||
if (!html) return '';
|
||||
return html.replace(/<[^>]*>/g, '');
|
||||
}
|
||||
|
||||
export function htmlToMarkdown(html?: string | null): string {
|
||||
if (!html) return '';
|
||||
let md = html
|
||||
.replace(/<p>/gi, '\n\n')
|
||||
.replace(/<\/p>/gi, '')
|
||||
.replace(/<br\s*\/?>/gi, '\n')
|
||||
.replace(/<h[1-6]>/gi, '\n\n**')
|
||||
.replace(/<\/h[1-6]>/gi, '**\n\n')
|
||||
.replace(/<li>/gi, '• ')
|
||||
.replace(/<\/li>/gi, '\n')
|
||||
.replace(/<ul>|<ol>/gi, '\n')
|
||||
.replace(/<\/ul>|<\/ol>/gi, '\n')
|
||||
.replace(/<pre><code>([\s\S]*?)<\/code><\/pre>/gi, (_, code) => `\`\`\`\n${code}\n\`\`\``)
|
||||
.replace(/<code>([\s\S]*?)<\/code>/gi, '`$1`')
|
||||
.replace(/<strong>([\s\S]*?)<\/strong>/gi, '**$1**')
|
||||
.replace(/<b>([\s\S]*?)<\/b>/gi, '**$1**')
|
||||
.replace(/<em>([\s\S]*?)<\/em>/gi, '_$1_')
|
||||
.replace(/<i>([\s\S]*?)<\/i>/gi, '_$1_')
|
||||
.replace(/<a\s+(?:[^>]*?\s+)?href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/gi, '[$2]($1)');
|
||||
md = stripHtmlTags(md);
|
||||
md = decodeHTMLEntities(md);
|
||||
return md
|
||||
.replace(/\n{3,}/g, '\n\n')
|
||||
.replace(/\s+$/, '')
|
||||
.trim();
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {decodeHTMLEntities, htmlToMarkdown, stripHtmlTags} from '@app/api/utils/DOMUtils';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
describe('decodeHTMLEntities', () => {
|
||||
it('returns empty string for null input', () => {
|
||||
expect(decodeHTMLEntities(null)).toBe('');
|
||||
});
|
||||
it('returns empty string for undefined input', () => {
|
||||
expect(decodeHTMLEntities(undefined)).toBe('');
|
||||
});
|
||||
it('returns empty string for empty string input', () => {
|
||||
expect(decodeHTMLEntities('')).toBe('');
|
||||
});
|
||||
it('decodes basic HTML entities', () => {
|
||||
expect(decodeHTMLEntities('&')).toBe('&');
|
||||
expect(decodeHTMLEntities('<')).toBe('<');
|
||||
expect(decodeHTMLEntities('>')).toBe('>');
|
||||
expect(decodeHTMLEntities('"')).toBe('"');
|
||||
expect(decodeHTMLEntities(''')).toBe("'");
|
||||
});
|
||||
it('decodes numeric HTML entities', () => {
|
||||
expect(decodeHTMLEntities('<')).toBe('<');
|
||||
expect(decodeHTMLEntities('<')).toBe('<');
|
||||
});
|
||||
it('decodes mixed content', () => {
|
||||
expect(decodeHTMLEntities('Hello & World')).toBe('Hello & World');
|
||||
expect(decodeHTMLEntities('<script>alert("xss")</script>')).toBe(
|
||||
'<script>alert("xss")</script>',
|
||||
);
|
||||
});
|
||||
it('preserves plain text without entities', () => {
|
||||
expect(decodeHTMLEntities('Hello World')).toBe('Hello World');
|
||||
});
|
||||
it('decodes special characters', () => {
|
||||
expect(decodeHTMLEntities(' ')).toBe('\u00A0');
|
||||
expect(decodeHTMLEntities('©')).toBe('\u00A9');
|
||||
expect(decodeHTMLEntities('€')).toBe('\u20AC');
|
||||
});
|
||||
});
|
||||
|
||||
describe('stripHtmlTags', () => {
|
||||
it('returns empty string for null input', () => {
|
||||
expect(stripHtmlTags(null)).toBe('');
|
||||
});
|
||||
it('returns empty string for undefined input', () => {
|
||||
expect(stripHtmlTags(undefined)).toBe('');
|
||||
});
|
||||
it('returns empty string for empty string input', () => {
|
||||
expect(stripHtmlTags('')).toBe('');
|
||||
});
|
||||
it('strips simple HTML tags', () => {
|
||||
expect(stripHtmlTags('<p>Hello</p>')).toBe('Hello');
|
||||
expect(stripHtmlTags('<div>World</div>')).toBe('World');
|
||||
});
|
||||
it('strips self-closing tags', () => {
|
||||
expect(stripHtmlTags('Hello<br/>World')).toBe('HelloWorld');
|
||||
expect(stripHtmlTags('Hello<br />World')).toBe('HelloWorld');
|
||||
});
|
||||
it('strips tags with attributes', () => {
|
||||
expect(stripHtmlTags('<a href="https://example.com">Link</a>')).toBe('Link');
|
||||
expect(stripHtmlTags('<img src="image.png" alt="Image"/>')).toBe('');
|
||||
});
|
||||
it('strips nested tags', () => {
|
||||
expect(stripHtmlTags('<div><p><span>Nested</span></p></div>')).toBe('Nested');
|
||||
});
|
||||
it('preserves plain text', () => {
|
||||
expect(stripHtmlTags('Hello World')).toBe('Hello World');
|
||||
});
|
||||
it('strips multiple tags', () => {
|
||||
expect(stripHtmlTags('<p>One</p><p>Two</p><p>Three</p>')).toBe('OneTwoThree');
|
||||
});
|
||||
it('handles malformed tags', () => {
|
||||
expect(stripHtmlTags('<div>Content<div>')).toBe('Content');
|
||||
});
|
||||
});
|
||||
|
||||
describe('htmlToMarkdown', () => {
|
||||
it('returns empty string for null input', () => {
|
||||
expect(htmlToMarkdown(null)).toBe('');
|
||||
});
|
||||
it('returns empty string for undefined input', () => {
|
||||
expect(htmlToMarkdown(undefined)).toBe('');
|
||||
});
|
||||
it('returns empty string for empty string input', () => {
|
||||
expect(htmlToMarkdown('')).toBe('');
|
||||
});
|
||||
it('converts paragraph tags', () => {
|
||||
expect(htmlToMarkdown('<p>First paragraph</p><p>Second paragraph</p>')).toBe('First paragraph\n\nSecond paragraph');
|
||||
});
|
||||
it('converts br tags to newlines', () => {
|
||||
expect(htmlToMarkdown('Line one<br>Line two')).toBe('Line one\nLine two');
|
||||
expect(htmlToMarkdown('Line one<br/>Line two')).toBe('Line one\nLine two');
|
||||
expect(htmlToMarkdown('Line one<br />Line two')).toBe('Line one\nLine two');
|
||||
});
|
||||
it('converts heading tags to bold', () => {
|
||||
expect(htmlToMarkdown('<h1>Heading</h1>')).toBe('**Heading**');
|
||||
expect(htmlToMarkdown('<h2>Heading</h2>')).toBe('**Heading**');
|
||||
expect(htmlToMarkdown('<h6>Heading</h6>')).toBe('**Heading**');
|
||||
});
|
||||
it('converts list items', () => {
|
||||
const html = '<ul><li>Item 1</li><li>Item 2</li></ul>';
|
||||
const result = htmlToMarkdown(html);
|
||||
expect(result).toContain('Item 1');
|
||||
expect(result).toContain('Item 2');
|
||||
});
|
||||
it('converts code blocks', () => {
|
||||
expect(htmlToMarkdown('<pre><code>const x = 1;</code></pre>')).toContain('```\nconst x = 1;\n```');
|
||||
});
|
||||
it('converts inline code', () => {
|
||||
expect(htmlToMarkdown('Use <code>npm install</code> to install')).toBe('Use `npm install` to install');
|
||||
});
|
||||
it('converts bold tags', () => {
|
||||
expect(htmlToMarkdown('<strong>Bold text</strong>')).toBe('**Bold text**');
|
||||
expect(htmlToMarkdown('<b>Bold text</b>')).toBe('**Bold text**');
|
||||
});
|
||||
it('converts italic tags', () => {
|
||||
expect(htmlToMarkdown('<em>Italic text</em>')).toBe('_Italic text_');
|
||||
expect(htmlToMarkdown('<i>Italic text</i>')).toBe('_Italic text_');
|
||||
});
|
||||
it('converts links', () => {
|
||||
expect(htmlToMarkdown('<a href="https://example.com">Example</a>')).toBe('[Example](https://example.com)');
|
||||
});
|
||||
it('collapses multiple newlines', () => {
|
||||
expect(htmlToMarkdown('<p>A</p><p></p><p></p><p>B</p>')).toBe('A\n\nB');
|
||||
});
|
||||
it('trims whitespace', () => {
|
||||
expect(htmlToMarkdown(' <p>Content</p> ')).toBe('Content');
|
||||
});
|
||||
it('decodes HTML entities in the result', () => {
|
||||
expect(htmlToMarkdown('<p>Hello & World</p>')).toBe('Hello & World');
|
||||
});
|
||||
it('handles complex mixed HTML', () => {
|
||||
const html =
|
||||
'<p>This is <strong>bold</strong> and <em>italic</em> with a <a href="https://example.com">link</a>.</p>';
|
||||
const expected = 'This is **bold** and _italic_ with a [link](https://example.com).';
|
||||
expect(htmlToMarkdown(html)).toBe(expected);
|
||||
});
|
||||
});
|
||||
@@ -1,114 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {calculateDistance, parseCoordinate} from '@app/api/utils/GeoUtils';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
describe('calculateDistance', () => {
|
||||
it('returns 0 for identical coordinates', () => {
|
||||
expect(calculateDistance(0, 0, 0, 0)).toBe(0);
|
||||
expect(calculateDistance(40.7128, -74.006, 40.7128, -74.006)).toBe(0);
|
||||
});
|
||||
it('calculates distance between New York and Los Angeles', () => {
|
||||
const nyLat = 40.7128;
|
||||
const nyLon = -74.006;
|
||||
const laLat = 34.0522;
|
||||
const laLon = -118.2437;
|
||||
const distance = calculateDistance(nyLat, nyLon, laLat, laLon);
|
||||
expect(distance).toBeGreaterThan(3900);
|
||||
expect(distance).toBeLessThan(4000);
|
||||
});
|
||||
it('calculates distance between London and Paris', () => {
|
||||
const londonLat = 51.5074;
|
||||
const londonLon = -0.1278;
|
||||
const parisLat = 48.8566;
|
||||
const parisLon = 2.3522;
|
||||
const distance = calculateDistance(londonLat, londonLon, parisLat, parisLon);
|
||||
expect(distance).toBeGreaterThan(330);
|
||||
expect(distance).toBeLessThan(350);
|
||||
});
|
||||
it('calculates distance across the equator', () => {
|
||||
const distance = calculateDistance(10, 0, -10, 0);
|
||||
expect(distance).toBeGreaterThan(2200);
|
||||
expect(distance).toBeLessThan(2250);
|
||||
});
|
||||
it('calculates distance across the prime meridian', () => {
|
||||
const distance = calculateDistance(51.5, -0.1, 51.5, 0.1);
|
||||
expect(distance).toBeGreaterThan(10);
|
||||
expect(distance).toBeLessThan(20);
|
||||
});
|
||||
it('calculates distance across the international date line', () => {
|
||||
const distance = calculateDistance(0, 179, 0, -179);
|
||||
expect(distance).toBeGreaterThan(200);
|
||||
expect(distance).toBeLessThan(250);
|
||||
});
|
||||
it('handles negative latitudes (Southern Hemisphere)', () => {
|
||||
const sydneyLat = -33.8688;
|
||||
const sydneyLon = 151.2093;
|
||||
const melbourneLat = -37.8136;
|
||||
const melbourneLon = 144.9631;
|
||||
const distance = calculateDistance(sydneyLat, sydneyLon, melbourneLat, melbourneLon);
|
||||
expect(distance).toBeGreaterThan(700);
|
||||
expect(distance).toBeLessThan(750);
|
||||
});
|
||||
it('handles extreme latitudes near poles', () => {
|
||||
const distance = calculateDistance(89, 0, 89, 180);
|
||||
expect(distance).toBeGreaterThan(0);
|
||||
expect(distance).toBeLessThan(250);
|
||||
});
|
||||
it('calculates short distances accurately', () => {
|
||||
const distance = calculateDistance(40.7128, -74.006, 40.713, -74.007);
|
||||
expect(distance).toBeLessThan(1);
|
||||
});
|
||||
it('calculates very long distances (antipodal points)', () => {
|
||||
const distance = calculateDistance(0, 0, 0, 180);
|
||||
expect(distance).toBeGreaterThan(20000);
|
||||
expect(distance).toBeLessThan(20050);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseCoordinate', () => {
|
||||
it('returns null for null input', () => {
|
||||
expect(parseCoordinate(null)).toBe(null);
|
||||
});
|
||||
it('returns null for undefined input', () => {
|
||||
expect(parseCoordinate(undefined)).toBe(null);
|
||||
});
|
||||
it('returns null for empty string', () => {
|
||||
expect(parseCoordinate('')).toBe(null);
|
||||
});
|
||||
it('parses positive integer coordinates', () => {
|
||||
expect(parseCoordinate('40')).toBe(40);
|
||||
expect(parseCoordinate('180')).toBe(180);
|
||||
});
|
||||
it('parses negative integer coordinates', () => {
|
||||
expect(parseCoordinate('-74')).toBe(-74);
|
||||
expect(parseCoordinate('-180')).toBe(-180);
|
||||
});
|
||||
it('parses positive decimal coordinates', () => {
|
||||
expect(parseCoordinate('40.7128')).toBe(40.7128);
|
||||
expect(parseCoordinate('0.5')).toBe(0.5);
|
||||
});
|
||||
it('parses negative decimal coordinates', () => {
|
||||
expect(parseCoordinate('-74.006')).toBe(-74.006);
|
||||
expect(parseCoordinate('-0.1278')).toBe(-0.1278);
|
||||
});
|
||||
it('parses zero', () => {
|
||||
expect(parseCoordinate('0')).toBe(0);
|
||||
expect(parseCoordinate('0.0')).toBe(0);
|
||||
});
|
||||
it('parses scientific notation', () => {
|
||||
expect(parseCoordinate('1e2')).toBe(100);
|
||||
expect(parseCoordinate('1.5e1')).toBe(15);
|
||||
});
|
||||
it('returns null for invalid strings', () => {
|
||||
expect(parseCoordinate('abc')).toBe(null);
|
||||
expect(parseCoordinate('NaN')).toBe(null);
|
||||
});
|
||||
it('returns null for Infinity', () => {
|
||||
expect(parseCoordinate('Infinity')).toBe(null);
|
||||
expect(parseCoordinate('-Infinity')).toBe(null);
|
||||
});
|
||||
it('parses coordinates with leading/trailing zeros', () => {
|
||||
expect(parseCoordinate('007.500')).toBe(7.5);
|
||||
});
|
||||
});
|
||||
@@ -1,78 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {escapeRegex} from '@app/api/utils/RegexUtils';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
describe('escapeRegex', () => {
|
||||
it('escapes hyphen', () => {
|
||||
expect(escapeRegex('-')).toBe('\\-');
|
||||
});
|
||||
it('escapes square brackets', () => {
|
||||
expect(escapeRegex('[')).toBe('\\[');
|
||||
expect(escapeRegex(']')).toBe('\\]');
|
||||
});
|
||||
it('escapes forward slash', () => {
|
||||
expect(escapeRegex('/')).toBe('\\/');
|
||||
});
|
||||
it('escapes curly braces', () => {
|
||||
expect(escapeRegex('{')).toBe('\\{');
|
||||
expect(escapeRegex('}')).toBe('\\}');
|
||||
});
|
||||
it('escapes parentheses', () => {
|
||||
expect(escapeRegex('(')).toBe('\\(');
|
||||
expect(escapeRegex(')')).toBe('\\)');
|
||||
});
|
||||
it('escapes asterisk', () => {
|
||||
expect(escapeRegex('*')).toBe('\\*');
|
||||
});
|
||||
it('escapes plus', () => {
|
||||
expect(escapeRegex('+')).toBe('\\+');
|
||||
});
|
||||
it('escapes question mark', () => {
|
||||
expect(escapeRegex('?')).toBe('\\?');
|
||||
});
|
||||
it('escapes period', () => {
|
||||
expect(escapeRegex('.')).toBe('\\.');
|
||||
});
|
||||
it('escapes backslash', () => {
|
||||
expect(escapeRegex('\\')).toBe('\\\\');
|
||||
});
|
||||
it('escapes caret', () => {
|
||||
expect(escapeRegex('^')).toBe('\\^');
|
||||
});
|
||||
it('escapes dollar sign', () => {
|
||||
expect(escapeRegex('$')).toBe('\\$');
|
||||
});
|
||||
it('escapes pipe', () => {
|
||||
expect(escapeRegex('|')).toBe('\\|');
|
||||
});
|
||||
it('returns empty string for empty input', () => {
|
||||
expect(escapeRegex('')).toBe('');
|
||||
});
|
||||
it('preserves normal characters', () => {
|
||||
expect(escapeRegex('abc')).toBe('abc');
|
||||
expect(escapeRegex('123')).toBe('123');
|
||||
expect(escapeRegex('Hello World')).toBe('Hello World');
|
||||
});
|
||||
it('escapes multiple special characters in a string', () => {
|
||||
expect(escapeRegex('[a-z]+')).toBe('\\[a\\-z\\]\\+');
|
||||
expect(escapeRegex('hello.*world')).toBe('hello\\.\\*world');
|
||||
});
|
||||
it('escapes URL patterns', () => {
|
||||
expect(escapeRegex('https://example.com/path?query=value')).toBe('https:\\/\\/example\\.com\\/path\\?query=value');
|
||||
});
|
||||
it('escapes regex character class patterns', () => {
|
||||
expect(escapeRegex('[^a-zA-Z0-9]')).toBe('\\[\\^a\\-zA\\-Z0\\-9\\]');
|
||||
});
|
||||
it('creates valid regex from escaped string', () => {
|
||||
const input = 'price: $10.00 (tax*)';
|
||||
const escaped = escapeRegex(input);
|
||||
const regex = new RegExp(escaped);
|
||||
expect(regex.test(input)).toBe(true);
|
||||
expect(regex.test('price: $1000 (tax)')).toBe(false);
|
||||
});
|
||||
it('handles repeated special characters', () => {
|
||||
expect(escapeRegex('...')).toBe('\\.\\.\\.');
|
||||
expect(escapeRegex('***')).toBe('\\*\\*\\*');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user