page-header.test.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { markRaw } from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import { describe, expect, test } from 'vitest'
  4. import { ArrowLeft } from '@element-plus/icons-vue'
  5. import PageHeader from '../src/page-header.vue'
  6. const AXIOM = 'Rem is the best girl'
  7. describe('PageHeader.vue', () => {
  8. test('render test', () => {
  9. const wrapper = mount(() => <PageHeader content={AXIOM} />)
  10. expect(wrapper.find('.el-page-header__content').text()).toEqual(AXIOM)
  11. })
  12. test('should render icon props', () => {
  13. const icon = markRaw(ArrowLeft)
  14. const wrapper = mount(() => <PageHeader icon={icon} />)
  15. expect(wrapper.findComponent(icon).exists()).toBe(true)
  16. })
  17. test('should render icon slots', () => {
  18. const wrapper = mount(() => (
  19. <PageHeader
  20. v-slots={{
  21. icon: () => AXIOM,
  22. }}
  23. />
  24. ))
  25. expect(wrapper.find('.el-page-header__icon').text()).toEqual(AXIOM)
  26. })
  27. describe('slots', () => {
  28. test('content', () => {
  29. const wrapper = mount(() => (
  30. <PageHeader
  31. v-slots={{
  32. content: () => AXIOM,
  33. }}
  34. />
  35. ))
  36. expect(wrapper.find('.el-page-header__content').text()).toEqual(AXIOM)
  37. })
  38. test('breadcrumb', () => {
  39. const wrapper = mount(() => (
  40. <PageHeader
  41. v-slots={{
  42. breadcrumb: () => AXIOM,
  43. }}
  44. />
  45. ))
  46. expect(wrapper.find('.el-page-header__breadcrumb').exists()).toBe(true)
  47. expect(wrapper.classes()).toContain('el-page-header--has-breadcrumb')
  48. })
  49. test('extra', () => {
  50. const wrapper = mount(() => (
  51. <PageHeader
  52. v-slots={{
  53. extra: () => AXIOM,
  54. }}
  55. />
  56. ))
  57. expect(wrapper.find('.el-page-header__extra').exists()).toBe(true)
  58. expect(wrapper.classes()).toContain('el-page-header--has-extra')
  59. })
  60. test('default', () => {
  61. const wrapper = mount(() => (
  62. <PageHeader
  63. v-slots={{
  64. default: () => AXIOM,
  65. }}
  66. />
  67. ))
  68. expect(wrapper.find('.el-page-header__main').exists()).toBe(true)
  69. expect(wrapper.classes()).toContain('is-contentful')
  70. })
  71. })
  72. test('prop title', () => {
  73. const wrapper = mount(() => <PageHeader title={AXIOM} />)
  74. expect(wrapper.find('.el-page-header__title').text()).toEqual(AXIOM)
  75. })
  76. test('slot prop', () => {
  77. const wrapper = mount(() => (
  78. <PageHeader
  79. v-slots={{
  80. title: () => AXIOM,
  81. }}
  82. />
  83. ))
  84. expect(wrapper.find('.el-page-header__title').text()).toEqual(AXIOM)
  85. })
  86. test('event back', async () => {
  87. const wrapper = mount(() => <PageHeader content={AXIOM} />)
  88. const pageHeader = wrapper.findComponent(PageHeader)
  89. await pageHeader.find('.el-icon').trigger('click')
  90. expect(pageHeader.emitted('back')).toBeDefined()
  91. })
  92. })