const fs = require('fs')
const path = require('path')
const assert = require('assert')

function read(relativePath) {
  return fs.readFileSync(path.join(__dirname, '..', relativePath), 'utf8')
}

const personalDetail = read('src/views/loanPricing/workflow/components/PersonalWorkflowDetail.vue')
const modelOutput = read('src/views/loanPricing/workflow/components/ModelOutputDisplay.vue')

assert(
  personalDetail.includes('label="借款期限"') && personalDetail.includes('detailData.loanTerm'),
  '个人详情页缺少借款期限展示'
)

const requiredRetailFields = [
  'retailOutput.greyBlackCust',
  'retailOutput.loanRateHistory',
  'retailOutput.minRateProduct',
  'retailOutput.smoothRange',
  'retailOutput.finalCalculateRate',
  'retailOutput.referenceRate'
]

requiredRetailFields.forEach((field) => {
  assert(modelOutput.includes(field), `模型输出缺少字段展示: ${field}`)
})

assert(
  modelOutput.indexOf('label="灰黑名单客户"') > modelOutput.indexOf('<h4 class="section-title">基本信息</h4>')
    && modelOutput.indexOf('label="灰黑名单客户"') < modelOutput.indexOf('<h4 class="section-title">测算结果</h4>'),
  '灰黑名单客户未展示在个人模型输出基础信息中'
)

console.log('retail display fields assertions passed')
