import fs from 'node:fs'
import path from 'node:path'

const root = process.cwd()
const previewPath = path.join(root, 'src/views/dataset/DatasetPreviewView.vue')
const mockPath = path.join(root, 'src/mock/data.ts')
const source = fs.readFileSync(previewPath, 'utf8')
const mockSource = fs.readFileSync(mockPath, 'utf8')

function expect(condition, message) {
  if (!condition) throw new Error(message)
}

expect(source.includes('class="preview-workspace"'), '预览页应使用文件与内容双栏工作区')
expect(source.includes('class="code-line"'), '内容查看器应提供逐行展示')
expect(source.includes('class="line-number"'), '内容查看器应显示行号')
expect(source.includes('previewLoading'), '切换文件时应提供独立加载状态')
expect(source.includes('previewError'), '内容加载失败时应提供错误状态')
expect(source.includes('aria-current'), '文件选中态应向辅助技术暴露')
expect(!source.includes('handleDownloadAll'), '页面不应保留整包下载逻辑')
expect(!source.includes('handleDelete'), '页面不应保留删除逻辑')
expect(!source.includes('router.back()'), '页面不应保留页头返回逻辑')
expect(mockSource.includes('files: ['), 'Mock 数据集应包含可验收的文件列表')
expect(mockSource.includes('mockDatasetPreviews'), 'Mock 数据应包含文件预览内容')
expect(mockSource.includes("'mock-jsonl'"), 'Mock 数据应为通用数据集提供模拟样本')
expect(mockSource.includes("'mock-readme'"), 'Mock 数据应为通用数据集提供模拟说明')
expect(mockSource.includes('.map((dataset)'), '所有 Mock 数据集都应自动补齐预览文件')

console.log('dataset preview regression checks passed')
