panel-version.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { describe, it, expect } from 'vitest';
  2. import { formatPanelVersion, isPanelUpdateAvailable } from '@/lib/panel-version';
  3. // Parity with web/service/panel.go isNewerVersion.
  4. describe('isPanelUpdateAvailable', () => {
  5. it('flags a strictly newer latest', () => {
  6. expect(isPanelUpdateAvailable('2.6.5', '2.6.4')).toBe(true);
  7. expect(isPanelUpdateAvailable('v2.7.0', 'v2.6.9')).toBe(true);
  8. expect(isPanelUpdateAvailable('3.0.0', '2.9.9')).toBe(true);
  9. });
  10. it('returns false when equal or the node is ahead', () => {
  11. expect(isPanelUpdateAvailable('2.6.4', '2.6.4')).toBe(false);
  12. expect(isPanelUpdateAvailable('v2.6.4', '2.6.4')).toBe(false);
  13. expect(isPanelUpdateAvailable('2.6.4', '2.6.5')).toBe(false);
  14. });
  15. it('ignores a leading v on either side', () => {
  16. expect(isPanelUpdateAvailable('v2.6.5', '2.6.4')).toBe(true);
  17. expect(isPanelUpdateAvailable('2.6.5', 'v2.6.4')).toBe(true);
  18. });
  19. it('never flags when a version is unknown', () => {
  20. expect(isPanelUpdateAvailable('', '2.6.4')).toBe(false);
  21. expect(isPanelUpdateAvailable('2.6.5', '')).toBe(false);
  22. });
  23. it('falls back to string inequality for non-semver tags', () => {
  24. expect(isPanelUpdateAvailable('nightly-2', 'nightly-1')).toBe(true);
  25. expect(isPanelUpdateAvailable('nightly-1', 'nightly-1')).toBe(false);
  26. });
  27. it('compares dev builds by commit and never across channels', () => {
  28. expect(isPanelUpdateAvailable('dev+1a2b3c4d', 'dev+0f0f0f0f')).toBe(true);
  29. expect(isPanelUpdateAvailable('dev+1a2b3c4d', 'dev+1a2b3c4d')).toBe(false);
  30. expect(isPanelUpdateAvailable('v3.5.0', 'dev+1a2b3c4d')).toBe(false);
  31. expect(isPanelUpdateAvailable('dev+1a2b3c4d', '3.5.0')).toBe(false);
  32. });
  33. });
  34. describe('formatPanelVersion', () => {
  35. it('adds a single v prefix to bare semantic versions', () => {
  36. expect(formatPanelVersion('3.4.0')).toBe('v3.4.0');
  37. expect(formatPanelVersion('2.6.5')).toBe('v2.6.5');
  38. });
  39. it('does not double up the v on already-prefixed tags', () => {
  40. expect(formatPanelVersion('v3.4.0')).toBe('v3.4.0');
  41. expect(formatPanelVersion('V3.4.0')).toBe('v3.4.0');
  42. });
  43. it('shows dev builds verbatim without a v prefix', () => {
  44. expect(formatPanelVersion('dev+1a2b3c4d')).toBe('dev+1a2b3c4d');
  45. expect(formatPanelVersion('dev')).toBe('dev');
  46. });
  47. it('returns empty for blank input and leaves unknown markers untouched', () => {
  48. expect(formatPanelVersion('')).toBe('');
  49. expect(formatPanelVersion(undefined)).toBe('');
  50. expect(formatPanelVersion('?')).toBe('?');
  51. });
  52. });