import { describe, it, expect } from 'vitest';
import * as fs from 'fs';
import * as path from 'path';

describe('fullscreen form dirty subtitle', () => {
  const vaultSrc = fs.readFileSync(
    path.resolve(__dirname, '../vault-form-wrapper.ts'),
    'utf-8',
  );

  it('contains renderFormWrapped function', () => {
    expect(vaultSrc).toContain('function renderFormWrapped');
  });

  it('starts pristine: renders "no changes" subtitle', () => {
    expect(vaultSrc).toContain("'no changes'");
  });

  it('switches to dirty on first input event', () => {
    expect(vaultSrc).toContain("'unsaved · esc to cancel'");
  });

  it('listens on input and change events on the scroll element', () => {
    expect(vaultSrc).toContain("scrollEl.addEventListener('input', markDirty, true)");
    expect(vaultSrc).toContain("scrollEl.addEventListener('change', markDirty, true)");
  });

  it('marks clean on save', () => {
    expect(vaultSrc).toContain('markClean()');
  });

  it('contains platform-aware SAVE_HINT', () => {
    expect(vaultSrc).toContain('SAVE_HINT');
    expect(vaultSrc).toContain('⌘+S to save');
    expect(vaultSrc).toContain('Ctrl+S to save');
  });

  it('renders fullscreen-form-header element', () => {
    expect(vaultSrc).toContain('fullscreen-form-header');
  });

  it('renders form-dirty-sub element', () => {
    expect(vaultSrc).toContain('form-dirty-sub');
  });
});
