panel-version.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. });
  28. describe('formatPanelVersion', () => {
  29. it('adds a single v prefix to bare semantic versions', () => {
  30. expect(formatPanelVersion('3.4.0')).toBe('v3.4.0');
  31. expect(formatPanelVersion('2.6.5')).toBe('v2.6.5');
  32. });
  33. it('does not double up the v on already-prefixed tags', () => {
  34. expect(formatPanelVersion('v3.4.0')).toBe('v3.4.0');
  35. expect(formatPanelVersion('V3.4.0')).toBe('v3.4.0');
  36. });
  37. it('shows dev builds verbatim without a v prefix', () => {
  38. expect(formatPanelVersion('dev+1a2b3c4d')).toBe('dev+1a2b3c4d');
  39. expect(formatPanelVersion('dev')).toBe('dev');
  40. });
  41. it('returns empty for blank input and leaves unknown markers untouched', () => {
  42. expect(formatPanelVersion('')).toBe('');
  43. expect(formatPanelVersion(undefined)).toBe('');
  44. expect(formatPanelVersion('?')).toBe('?');
  45. });
  46. });