link-label.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829
  1. import { describe, it, expect } from 'vitest';
  2. import { parseLinkParts, linkMetaText } from '@/lib/xray/link-label';
  3. // The panel shows the subscription's remark verbatim. Per-client traffic/expiry
  4. // info is rendered only into the body a client app imports (backend, first link
  5. // only), so the panel's display links are already clean — nothing is stripped.
  6. describe('link-label parseLinkParts', () => {
  7. const linkWith = (remark: string) =>
  8. `vless://[email protected]:443?type=tcp&security=tls#${encodeURIComponent(remark)}`;
  9. it('parses protocol / network / security and keeps the remark verbatim', () => {
  10. const parts = parseLinkParts(linkWith('[email protected]'));
  11. expect(parts?.protocol).toBe('Vless');
  12. expect(parts?.network).toBe('TCP');
  13. expect(parts?.security).toBe('TLS');
  14. expect(parts?.remark).toBe('[email protected]');
  15. expect(parts?.port).toBe('443');
  16. });
  17. it('linkMetaText joins the remark with the port', () => {
  18. const parts = parseLinkParts(linkWith('[email protected]'));
  19. expect(parts && linkMetaText(parts)).toBe('[email protected]:443');
  20. });
  21. it('returns null for an unparseable scheme', () => {
  22. expect(parseLinkParts('not-a-link')).toBeNull();
  23. });
  24. });