|
|
@@ -4,6 +4,30 @@ const path = require('node:path')
|
|
|
const { pathToFileURL } = require('node:url')
|
|
|
const vm = require('node:vm')
|
|
|
const rules = require('../utils/teamBackgroundFile')
|
|
|
+const backgroundSurveyRules = require('../utils/backgroundSurvey')
|
|
|
+
|
|
|
+const surveyQuestion = {
|
|
|
+ detailId: 101,
|
|
|
+ options: [
|
|
|
+ { code:'A', text:'固定选项', customAllowed:false },
|
|
|
+ { code:'F', text:'其他', customAllowed:true }
|
|
|
+ ]
|
|
|
+}
|
|
|
+assert.equal(backgroundSurveyRules.validateBackgroundAnswer(surveyQuestion, '', ''), '请选择当前题目的答案')
|
|
|
+assert.equal(backgroundSurveyRules.validateBackgroundAnswer(surveyQuestion, 'F', ''), '请填写其他选项的具体内容')
|
|
|
+assert.equal(backgroundSurveyRules.validateBackgroundAnswer(surveyQuestion, 'A', '忽略内容'), '')
|
|
|
+assert.deepEqual(
|
|
|
+ backgroundSurveyRules.createBackgroundAnswerPayload(surveyQuestion, 'A', '忽略内容'),
|
|
|
+ { detailId:101, optionCode:'A', customText:'' }
|
|
|
+)
|
|
|
+assert.deepEqual(
|
|
|
+ backgroundSurveyRules.createBackgroundAnswerPayload(surveyQuestion, 'F', ' 自定义答案 '),
|
|
|
+ { detailId:101, optionCode:'F', customText:'自定义答案' }
|
|
|
+)
|
|
|
+assert.equal(
|
|
|
+ backgroundSurveyRules.backgroundIntroUrl({ teamQuestionnaireId:12, title:'团队 A' }),
|
|
|
+ '/pagesPublish/backgroundSurveyIntro?stage=background&teamQuestionnaireId=12&title=%E5%9B%A2%E9%98%9F%20A'
|
|
|
+)
|
|
|
|
|
|
assert.equal(rules.validateEnterpriseWebsite(' 无 '), '')
|
|
|
assert.equal(rules.validateEnterpriseWebsite('https://example.com'), '')
|
|
|
@@ -99,6 +123,8 @@ assert.deepEqual(creationState, {
|
|
|
stage: 'idle',
|
|
|
completed: false,
|
|
|
teamPayloadSnapshot: '',
|
|
|
+ backgroundSurveyId: '',
|
|
|
+ backgroundSurveyStatus: 'DRAFT',
|
|
|
teamQuestionnaireId: '',
|
|
|
publishResult: null,
|
|
|
resumeStage: ''
|
|
|
@@ -617,7 +643,8 @@ function readSfcScript(filePath) {
|
|
|
}
|
|
|
|
|
|
async function loadVueComponent(filePath, {
|
|
|
- http = {}, uni = {}, wx = {}, apiRules = rules, timers = {}
|
|
|
+ http = {}, uni = {}, wx = {}, apiRules = rules,
|
|
|
+ backgroundRules = backgroundSurveyRules, timers = {}
|
|
|
} = {}) {
|
|
|
const context = vm.createContext({
|
|
|
uni,
|
|
|
@@ -640,6 +667,9 @@ async function loadVueComponent(filePath, {
|
|
|
const rulesStub = new vm.SyntheticModule(['default'], function () {
|
|
|
this.setExport('default', apiRules)
|
|
|
}, { context, identifier: 'test:team-background-rules' })
|
|
|
+ const backgroundRulesStub = new vm.SyntheticModule(['default'], function () {
|
|
|
+ this.setExport('default', backgroundRules)
|
|
|
+ }, { context, identifier: 'test:background-survey-rules' })
|
|
|
const httpNames = [
|
|
|
'createTeamBackgroundSession',
|
|
|
'disableTeamBackgroundFile',
|
|
|
@@ -659,6 +689,7 @@ async function loadVueComponent(filePath, {
|
|
|
await componentModule.link(specifier => {
|
|
|
if (specifier === '@/http/teamBackgroundFile.js') return httpStub
|
|
|
if (specifier === '@/utils/teamBackgroundFile.js') return rulesStub
|
|
|
+ if (specifier === '@/utils/backgroundSurvey.js') return backgroundRulesStub
|
|
|
if (specifier.endsWith('.vue')) return vueStub
|
|
|
throw new Error(`unexpected component import: ${specifier}`)
|
|
|
})
|
|
|
@@ -725,6 +756,17 @@ const createTeamPagePath = path.join(__dirname, '../pagesPublish/fillTeamInfo.vu
|
|
|
const createListComponentPath = path.join(__dirname, '../pagesHome/components/createList.vue')
|
|
|
const teamEditPagePath = path.join(__dirname, '../pagesMy/teamEdit.vue')
|
|
|
const headerComponentPath = path.join(__dirname, '../components/CusHeader/index.vue')
|
|
|
+const backgroundSurveyPagePath = path.join(__dirname, '../pagesPublish/backgroundSurvey.vue')
|
|
|
+const backgroundSurveyIntroPagePath = path.join(__dirname, '../pagesPublish/backgroundSurveyIntro.vue')
|
|
|
+
|
|
|
+async function testBackgroundSurveyPagesLoad() {
|
|
|
+ const survey = await loadVueComponent(backgroundSurveyPagePath)
|
|
|
+ const intro = await loadVueComponent(backgroundSurveyIntroPagePath)
|
|
|
+ assert.equal(typeof survey.methods.loadSurvey, 'function')
|
|
|
+ assert.equal(typeof survey.methods.saveCurrent, 'function')
|
|
|
+ assert.equal(typeof survey.methods.next, 'function')
|
|
|
+ assert.equal(typeof intro.methods.start, 'function')
|
|
|
+}
|
|
|
|
|
|
async function testDeferredPcSelectionSurvivesSessionFailure() {
|
|
|
let createCalls = 0
|
|
|
@@ -1307,9 +1349,10 @@ async function testCreatedTeamNavigationIsAwaitableAndResumable() {
|
|
|
}
|
|
|
assert.equal(url, '/core/team/questionnaire/publish')
|
|
|
assert.deepEqual(Object.keys(payload).sort(), [
|
|
|
- 'answerSetting', 'coachId', 'endTime', 'questionnaireId',
|
|
|
+ 'answerSetting', 'backgroundSurveyId', 'coachId', 'endTime', 'questionnaireId',
|
|
|
'startTime', 'teamId', 'type'
|
|
|
].sort())
|
|
|
+ assert.equal(payload.backgroundSurveyId, 456)
|
|
|
publishCalls += 1
|
|
|
return Promise.resolve({ data: { code: 0, data: 321 } })
|
|
|
},
|
|
|
@@ -1334,6 +1377,8 @@ async function testCreatedTeamNavigationIsAwaitableAndResumable() {
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
+ instance.creationState.backgroundSurveyId = 456
|
|
|
+ instance.creationState.backgroundSurveyStatus = 'COMPLETED'
|
|
|
|
|
|
const first = instance.handleConfirm({
|
|
|
teamName: '团队', enterpriseWebsite: 'https://old.example'
|
|
|
@@ -1394,6 +1439,63 @@ async function testCreatedTeamNavigationIsAwaitableAndResumable() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+async function testCreatedTeamRequiresCoachSurveyBeforePublish() {
|
|
|
+ let navigationOptions
|
|
|
+ let publishCalls = 0
|
|
|
+ const uni = {
|
|
|
+ getStorageSync: () => JSON.stringify({ id: 7 }),
|
|
|
+ navigateTo(options) {
|
|
|
+ navigationOptions = options
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const component = await loadVueComponent(createTeamPagePath, { uni })
|
|
|
+ const instance = instantiateComponent(component, {
|
|
|
+ next:'1',
|
|
|
+ type:'1',
|
|
|
+ title:'PERILL',
|
|
|
+ questionnaireId:66,
|
|
|
+ $api:{
|
|
|
+ post(url) {
|
|
|
+ assert.equal(url, '/core/user/team')
|
|
|
+ return Promise.resolve({ data:{ code:0, data:{ teamId:88 } } })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ $showToast() {},
|
|
|
+ $showModal: () => Promise.resolve(),
|
|
|
+ $refs:{
|
|
|
+ teamRef:{
|
|
|
+ flushBackgroundFiles: () => Promise.resolve({ success:0, failed:0 }),
|
|
|
+ hasUnresolvedBackgroundFiles: () => false,
|
|
|
+ hasDeferredPcUpload: () => false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ let continuedTeamId
|
|
|
+ instance.continueAfterTeamCreated = async teamId => {
|
|
|
+ continuedTeamId = teamId
|
|
|
+ }
|
|
|
+ instance.publishQuestionnaire = async teamId => {
|
|
|
+ assert.equal(teamId, 88)
|
|
|
+ assert.equal(instance.creationState.backgroundSurveyId, 456)
|
|
|
+ publishCalls += 1
|
|
|
+ return { code:0, data:321 }
|
|
|
+ }
|
|
|
+
|
|
|
+ await instance.handleConfirm({ teamName:'团队', enterpriseWebsite:'无' })
|
|
|
+ assert.equal(publishCalls, 0, 'publishing must wait for the coach background survey')
|
|
|
+ assert.match(navigationOptions.url, /backgroundSurvey\?mode=coach/)
|
|
|
+ assert.equal(instance.creationState.stage, 'coachSurvey')
|
|
|
+ navigationOptions.events.backgroundSurveyReady({ surveyId:456, status:'DRAFT' })
|
|
|
+ assert.equal(instance.creationState.backgroundSurveyId, 456)
|
|
|
+ navigationOptions.events.backgroundSurveyCompleted({ surveyId:456, status:'COMPLETED' })
|
|
|
+ component.onShow.call(instance)
|
|
|
+ await flushPromises()
|
|
|
+ assert.equal(publishCalls, 1)
|
|
|
+ assert.equal(instance.creationState.teamQuestionnaireId, 321)
|
|
|
+ assert.equal(continuedTeamId, 88)
|
|
|
+ assert.equal(instance.creationState.completed, true)
|
|
|
+}
|
|
|
+
|
|
|
async function testCreatedTeamUnloadCancelsLateNavigation() {
|
|
|
const timers = createFakeTimers()
|
|
|
let navigateBackCalls = 0
|
|
|
@@ -1600,6 +1702,7 @@ async function main() {
|
|
|
await testUploadTransport()
|
|
|
await testApiTransport()
|
|
|
await testDownloadTransport()
|
|
|
+ await testBackgroundSurveyPagesLoad()
|
|
|
await testDeferredPcSelectionSurvivesSessionFailure()
|
|
|
await testSessionRefreshFailureKeepsOldTimer()
|
|
|
await testPcSessionCreationIsSingleFlightPerTeam()
|
|
|
@@ -1616,6 +1719,7 @@ async function main() {
|
|
|
await testTeamFillFlushesBeforeEmitAndLocks()
|
|
|
await testCreatedTeamResumeAndSubmitLock()
|
|
|
await testCreatedTeamNavigationIsAwaitableAndResumable()
|
|
|
+ await testCreatedTeamRequiresCoachSurveyBeforePublish()
|
|
|
await testCreatedTeamUnloadCancelsLateNavigation()
|
|
|
await testTeamEditRedirectIsLockedAndResumable()
|
|
|
await testTeamEditUnloadCancelsLateRedirect()
|