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

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

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

assert(
  personalCreateDialog.includes('label="贷款用途"') && personalCreateDialog.includes('prop="loanPurpose"'),
  '个人新增弹窗缺少贷款用途字段'
)

assert(
  personalCreateDialog.includes('label="借款期限(年)"') && personalCreateDialog.includes('prop="loanTerm"'),
  '个人新增弹窗缺少借款期限字段'
)

assert(
  personalCreateDialog.includes("value=\"consumer\"") && personalCreateDialog.includes("value=\"business\""),
  '个人新增弹窗缺少贷款用途选项'
)

assert(
  personalCreateDialog.includes('loanTermOptions') &&
    personalCreateDialog.includes("'1'") &&
    personalCreateDialog.includes("'6'") &&
    !personalCreateDialog.includes("'7'"),
  '个人新增弹窗借款期限选项应限制为 1-6 年'
)

assert(
  personalCreateDialog.includes('v-if="isCollateralGuarantee"') &&
    personalCreateDialog.includes("this.form.guarType === '抵押' || this.form.guarType === '质押'") &&
    personalCreateDialog.includes('resetCollateralFields()'),
  '个人新增弹窗抵质押信息未按担保方式显示并清空'
)

assert(
  personalCreateDialog.includes('collateralTypeOptions') &&
    personalCreateDialog.includes("return ['一类', '二类', '三类', '四类', '其他']") &&
    personalCreateDialog.includes("return ['存单质押', '其他']") &&
    !personalCreateDialog.includes('label="一线"'),
  '个人新增弹窗抵质押类型选项未按担保方式动态切换'
)

assert(
  !personalCreateDialog.includes('{required: true, message: "请选择抵质押类型", trigger: "change"}'),
  '个人新增弹窗仍将抵质押类型设为必填'
)

assert(
  personalCreateDialog.includes("bizProof: this.form.bizProof ? '1' : '0'") &&
    personalCreateDialog.includes("loanLoop: this.form.loanLoop ? '1' : '0'") &&
    personalCreateDialog.includes("data.collThirdParty = this.form.collThirdParty ? '1' : '0'") &&
    personalCreateDialog.includes('delete data.collType') &&
    personalCreateDialog.includes('delete data.collThirdParty'),
  '个人新增弹窗开关字段或非抵质押提交字段处理不正确'
)

assert(
  personalDetail.includes('label="贷款用途"') && personalDetail.includes('detailData.loanPurpose'),
  '个人详情页缺少贷款用途展示'
)

assert(
  personalDetail.includes("value === '1'") && personalDetail.includes("value === '0'"),
  '个人详情页布尔格式化未兼容 1/0'
)

console.log('personal create input params assertions passed')
