| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import test from 'node:test'
- import assert from 'node:assert/strict'
- import { readFileSync } from 'node:fs'
- import ts from 'typescript'
- import { computed, nextTick, reactive, ref, watch } from 'vue'
- const source = readFileSync(new URL('../src/components/WarningActionDrawer.vue', import.meta.url), 'utf8')
- const script = ts.transpileModule(source.match(/<script setup lang="ts">([\s\S]*?)<\/script>/)[1]
- .replace(/^import .*\r?\n/gm, ''), { compilerOptions: { target: ts.ScriptTarget.ES2020 } }).outputText
- function setup(reviewers) {
- const props = reactive({ modelValue: false, action: 'PUBLISH', handlers: [{ userName: 'handler' }], reviewers })
- const events = [], messages = []
- const state = new Function('computed', 'ref', 'watch', 'useUserStore', 'defineProps', 'withDefaults', 'defineEmits', 'uni',
- `${script}; return { handlerIndex, reviewerIndex, selectIndex, submit }`)(computed, ref, watch,
- () => ({ profile: { userName: 'current' } }), () => props, p => p,
- () => (...args) => events.push(args), { showToast: message => messages.push(message) })
- return { ...state, props, events, messages }
- }
- test('移动端仅对服务端返回的合格核验候选默认当前账户', async () => {
- for (const eligible of [true, false]) {
- const s = setup(eligible ? [{ userName: 'current' }, { userName: 'other' }] : [{ userName: 'other' }])
- s.props.modelValue = true
- await nextTick()
- assert.equal(s.handlerIndex.value, -1)
- assert.equal(s.reviewerIndex.value, eligible ? 0 : -1)
- s.submit()
- assert.equal(s.events.length, 0)
- assert.equal(s.messages.length, 1)
- }
- })
- test('首位候选可以明确选中,核验人支持改选其他人员', async () => {
- const s = setup([{ userName: 'current' }, { userName: 'other' }])
- s.props.modelValue = true
- await nextTick()
- s.selectIndex({ detail: { value: '1' } }, 'handler')
- s.selectIndex({ detail: { value: '2' } }, 'reviewer')
- s.submit()
- assert.equal(s.events[0][0], 'submit')
- assert.equal(s.events[0][1].handler, 'handler')
- assert.equal(s.events[0][1].reviewer, 'other')
- s.selectIndex({ detail: { value: '0' } }, 'reviewer')
- s.submit()
- assert.equal(s.events.length, 1)
- })
|