const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const { validateFutureExpectation, normalizeFutureExpectationOptions } = require('../utils/perillScore')

const method = (assessmentMethod, score) => ({
	assessmentMethod,
	answer: `${score}-分`,
	questionOption: [{ number: score, questionOption: `${score}-分` }]
})

assert.equal(validateFutureExpectation([method('1', 3), method('2', 4)]), '')
assert.equal(validateFutureExpectation([method('1', 3), method('2', 3)]), '')
assert.equal(
	validateFutureExpectation([method('1', 3), method('2', 2)]),
	'一年后期待分不得低于现状评分，请注意！'
)
assert.equal(
	validateFutureExpectation([
		{ assessmentMethod: '1', answer: '当前表现良好', questionOption: [{ number: 3, questionOption: '当前表现良好' }] },
		{ assessmentMethod: '2', answer: '一年后可达成表现优秀', questionOption: [{ number: 4, questionOption: '一年后可达成表现优秀' }] }
	]),
	''
)

const previewMethods = normalizeFutureExpectationOptions([
	{ assessmentMethod: '1', questionOption: [{ number: 1, questionOption: '1-强烈不同意(Strongly disagree)' }] },
	{ assessmentMethod: '2', questionOption: [{ number: 1, questionOption: '1-非常不重要(Very unimportant)' }] }
])
assert.equal(previewMethods[0].questionOption[0].questionOption, '1-强烈不同意(Strongly disagree)')
assert.equal(previewMethods[1].questionOption[0].questionOption, '1-强烈不同意(Strongly disagree)')

const questionnaireConfig = fs.readFileSync(
	path.join(__dirname, '../../ChuangHeng_new/src/views/modules/agent/questionnaireList.vue'),
	'utf8'
)
assert.doesNotMatch(questionnaireConfig, /<el-option label="重要性" :value="2"><\/el-option>/)

const questionnaireFill = fs.readFileSync(
	path.join(__dirname, '../pagesPublish/questionnaireFill.vue'),
	'utf8'
)
assert.match(questionnaireFill, /normalizeFutureExpectationOptions\(item\.userAnswer\)/)

console.log('perill score rules: PASS')
