firstsun-dev_git-files-sync/tests/ui/DiffPanel.test.ts
ClaudiaFang a77e0150a1 test(ui): add interaction tests for ActionBar, FileListItem, and DiffPanel
Adds comprehensive UI component test coverage with 54 new test cases across three components to close issue #23. Includes JSDOM setup polyfills and tooltip mock utilities for DOM-dependent component testing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 05:25:13 +00:00

54 lines
2.1 KiB
TypeScript

import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
import { renderDiffPanel } from '../../src/ui/components/DiffPanel';
import { setupObsidianDOM, createContainer } from './setup-dom';
beforeAll(() => { setupObsidianDOM(); });
describe('renderDiffPanel', () => {
let container: HTMLElement;
beforeEach(() => {
container = createContainer();
});
it('returns the diff element with ssv-diff class', () => {
const el = renderDiffPanel(container, '', '');
expect(el.classList.contains('ssv-diff')).toBe(true);
});
it('renders Remote and Local column headers', () => {
renderDiffPanel(container, 'a', 'b');
const headers = container.querySelectorAll('.ssv-diff-hd');
expect(headers[0]?.textContent).toBe('Remote');
expect(headers[1]?.textContent).toBe('Local');
});
it('renders unchanged lines with unchanged class in both columns', () => {
renderDiffPanel(container, 'same', 'same');
const cells = container.querySelectorAll('.ssv-diff-cell.unchanged');
expect(cells.length).toBeGreaterThanOrEqual(2);
});
it('renders added line in unified view', () => {
renderDiffPanel(container, '', 'new line');
const added = container.querySelector('.ssv-u-line.added');
expect(added?.textContent).toContain('new line');
});
it('renders removed line in unified view', () => {
renderDiffPanel(container, 'old line', '');
const removed = container.querySelector('.ssv-u-line.removed');
expect(removed?.textContent).toContain('old line');
});
it('renders both removed and added lines for a replacement', () => {
renderDiffPanel(container, 'before', 'after');
expect(container.querySelector('.ssv-u-line.removed')).not.toBeNull();
expect(container.querySelector('.ssv-u-line.added')).not.toBeNull();
});
it('renders unchanged lines in unified view for identical content', () => {
renderDiffPanel(container, 'context', 'context');
expect(container.querySelector('.ssv-u-line.unchanged')).not.toBeNull();
});
});