You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
2.1 KiB
31 lines
2.1 KiB
import { mount, createLocalVue } from '@vue/test-utils'
|
|
import ElementUI from 'element-ui'
|
|
import StatsField from '@/views/survey/components/SurveyStatsField.vue'
|
|
import Results from '@/views/survey/components/SurveyResultsDialog.vue'
|
|
import { textAnswers } from '@/api/survey/evaluationForm'
|
|
jest.mock('@/api/survey/evaluationForm', () => ({ statistics: jest.fn(), index: jest.fn(), show: jest.fn(), destroy: jest.fn(), textAnswers: jest.fn() }))
|
|
const localVue = createLocalVue()
|
|
localVue.use(ElementUI)
|
|
const flush = () => new Promise(resolve => setTimeout(resolve, 0))
|
|
|
|
describe('Option supplement results', () => {
|
|
it('opens the selected option supplement rather than a generic text list', async() => {
|
|
const field = { edit_input: 'checkbox', stats: { valid_count: 2, average: null, other_count: 0, options: [{ key: 'tax', label: '财税会场', count: 2, percentage: 100, note_count: 1 }, { key: 'legal', label: '法律会场', count: 1, percentage: 50, note_count: 0 }] } }
|
|
const wrapper = mount(StatsField, { localVue, propsData: { field } })
|
|
await flush()
|
|
const button = wrapper.findAll('button').wrappers.find(item => item.text().includes('查看补充内容'))
|
|
expect(button).toBeTruthy()
|
|
button.trigger('click')
|
|
expect(wrapper.emitted('texts')[0]).toEqual(['option', 'tax'])
|
|
wrapper.destroy()
|
|
})
|
|
it('sends the option key and keeps each respondent identity in the result', async() => {
|
|
textAnswers.mockResolvedValue({ data: [{ id: 7, text: '税务咨询', respondent: { name: '甲学员', company_name: '甲公司' } }], total: 1 })
|
|
const state = { epoch: 1, surveyData: { id: 10 }, textQuestion: { id: 66, name: '会场', select_item: [{ key: 'tax', value: '财税会场' }] }, textKind: 'option', textOptionKey: 'tax', textPage: 1 }
|
|
await Results.methods.loadTexts.call(state)
|
|
expect(textAnswers).toHaveBeenLastCalledWith({ course_content_evaluation_id: 10, question_id: 66, kind: 'option', option_key: 'tax', page: 1, page_size: 20 })
|
|
expect(state.texts[0].respondent.name).toBe('甲学员')
|
|
expect(Results.computed.textTitle.call(state)).toBe('会场 · 财税会场 · 补充内容')
|
|
})
|
|
})
|