// #region BulkActionsTest [C:2] [TYPE Module] [SEMANTICS test, datasets, bulk, actions, component]
// @BRIEF Contract-focused unit tests for bulk actions in +page.svelte.
// @LAYER Test
import { describe, it, expect } from 'vitest';
import fs from 'node:fs';
import path from 'node:path';

const PAGE_PATH = path.resolve(process.cwd(), 'src/routes/datasets/+page.svelte');

describe('Bulk Actions', () => {
  it('panel appears at 2+ selected', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('selectedIds.size >= 2');
  });

  it('panel disappears at 0 selected', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    // Panel is hidden when selectedIds.size === 0 (via {#if selectedIds.size >= 2})
    expect(src).toContain('selectedIds.size');
    expect(src).toContain('SvelteSet');
  });

  it('map columns modal opens', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('showMapColumnsModal');
    expect(src).toContain('bulk_map_columns');
  });

  it('generate docs modal opens', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('showGenerateDocsModal');
    expect(src).toContain('bulk_docs_generation');
  });

  it('selected count displays correctly', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('selectedIds.size');
    expect(src).toContain('selected');
  });

  it('has clear/deselect button in panel', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('selectedIds');
    expect(src).toContain('SvelteSet');
  });

  it('opens task drawer on bulk action completion', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('openDrawerForTaskIfPreferred');
    expect(src).toContain('task_id');
  });
});
