firstsun-dev_git-files-sync/tests/ui/SyncConflictModal.test.ts
Claude d896015765 fix(compat): support Obsidian down to 1.11.0
Release 1.2.0 raised minAppVersion to 1.13.0, pushing users still on
Obsidian 1.11/1.12 back to the older 1.1.2 build via versions.json. Only
three 1.13-era APIs were in use; two were already runtime-guarded, but
ButtonComponent.setDestructive() would throw on older Obsidian.

- Guard setDestructive() behind applyDestructiveStyle() (no-ops on < 1.13).
- Declare SettingDefinitionItem locally and read update() via a cast so the
  forward-compatible settings code type-checks against 1.11 typings.
- Ship 1.2.1 with minAppVersion 1.11.0 (manifest.json + versions.json).
- Add tsconfig.compat.json and `npm run typecheck:compat` to type-check src
  against the 1.11 API, plus regression tests for applyDestructiveStyle.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SSikT9ZAfQF8K4SE3DatD3
2026-07-07 01:53:28 +00:00

28 lines
1.1 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { applyDestructiveStyle } from '../../src/ui/SyncConflictModal';
// Guards the backward-compatibility fix that lets the plugin run on Obsidian
// down to minAppVersion 1.11.0. ButtonComponent.setDestructive() only exists on
// Obsidian >= 1.13; calling it unconditionally would throw on older versions.
describe('applyDestructiveStyle (Obsidian version compatibility)', () => {
it('applies the destructive style on Obsidian >= 1.13 (method present)', () => {
const setDestructive = vi.fn();
const btn = { setDestructive };
expect(applyDestructiveStyle(btn)).toBe(btn);
expect(setDestructive).toHaveBeenCalledOnce();
});
it('degrades gracefully on Obsidian < 1.13 (method absent) without throwing', () => {
const btn = {}; // an older ButtonComponent has no setDestructive()
expect(() => applyDestructiveStyle(btn)).not.toThrow();
expect(applyDestructiveStyle(btn)).toBe(btn);
});
it('ignores a non-function setDestructive rather than crashing', () => {
const btn = { setDestructive: 'nope' as unknown as () => unknown };
expect(() => applyDestructiveStyle(btn)).not.toThrow();
});
});