panel-version.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import { describe, it, expect } from 'vitest';
  2. import { 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. });