<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5"><el-button type="primary" icon="el-icon-video-play" size="mini" :loading="running" @click="runAll">运行全部测试</el-button></el-col>
      <el-col :span="1.5"><el-button plain icon="el-icon-cpu" size="mini" @click="runModule('node-types')">节点类型</el-button></el-col>
      <el-col :span="1.5"><el-button plain icon="el-icon-connection" size="mini" @click="runModule('dynamic-executor')">动态执行器</el-button></el-col>
    </el-row>

    <el-alert v-if="summary.message" :title="summary.message" :type="summary.passed ? 'success' : 'error'" show-icon class="mb8" />

    <el-table border :data="details" size="small">
      <el-table-column prop="line" label="测试结果" show-overflow-tooltip />
    </el-table>
  </div>
</template>
<script>
import { runIntegrationTests, testNodeTypes, testDynamicExecutor } from '@/api/workflow/lobster'
export default {
  name: 'LobsterIntegrationTest',
  data() { return { running: false, summary: {}, details: [] } },
  methods: {
    showResult(data) {
      this.summary = data || {}
      const lines = (data && data.details) || []
      this.details = lines.map(line => ({ line }))
    },
    runAll() {
      this.running = true
      runIntegrationTests().then(res => { this.showResult(res.data); this.$message.success('测试完成') })
        .finally(() => { this.running = false })
    },
    runModule(type) {
      const fn = type === 'node-types' ? testNodeTypes : testDynamicExecutor
      fn().then(res => {
        const r = res.data || {}
        this.summary = { passed: r.passed, message: r.message }
        this.details = (r.details || []).map(line => ({ line }))
      })
    }
  }
}
</script>
