import {afterEach,expect,it} from 'vitest'
import {mount} from '@vue/test-utils'
import Content from '@/components/NoticeContent/index.vue'
let w
afterEach(()=>w?.unmount())
it('preserves ordered steps, bullet points, indentation and inline emphasis from the editor',()=>{
w=mount(Content,{props:{html:'
使用说明:
第一步 第二步 子步骤 '}})
expect(w.classes()).toContain('ql-editor');expect(w.findAll('ol>li')).toHaveLength(3);expect(w.findAll('ul>li')).toHaveLength(1);expect(w.find('li.ql-indent-1').text()).toBe('子步骤');expect(w.find('strong').text()).toBe('使用说明:')
})
it('preserves Quill mixed-list markers and checklist metadata',()=>{
w=mount(Content,{props:{html:' 编号圆点 '}})
expect(w.find('li[data-list="ordered"]').exists()).toBe(true);expect(w.find('li[data-list="bullet"]').exists()).toBe(true);expect(w.find('ul[data-checked="true"]').exists()).toBe(true)
})
it('removes executable elements, event handlers and unsafe links while retaining the readable formatting',()=>{
w=mount(Content,{props:{html:'正文
坏链接 '}})
expect(w.find('script,iframe,svg,form,input,[onclick],[onerror],[onload]').exists()).toBe(false);expect(w.find('a').attributes('href')).toBeUndefined();expect(w.text()).toContain('正文');expect(w.text()).not.toContain('hidden')
})
it('retains editor colors and alignment but excludes page layout CSS and unrelated classes',()=>{
w=mount(Content,{props:{html:'彩色说明
说明链接 '}})
const p=w.find('p');expect(p.classes()).toEqual(['ql-align-center']);expect(p.element.style.color).toBe('red');expect(p.element.style.fontSize).toBe('16px');expect(p.element.style.position).toBe('');expect(p.element.style.backgroundImage).toBe('');expect(w.find('a').attributes()).toMatchObject({target:'_blank',rel:'noopener noreferrer'})
})
it('keeps plain text paragraphs usable and handles empty notices',()=>{
w=mount(Content,{props:{html:'第一行\n第二行'}});expect(w.text()).toContain('第一行\n第二行');w.unmount();w=mount(Content,{props:{html:''}});expect(w.text()).toBe('暂无正文')
})