CommonDateTime.spec.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { nextTick } from 'vue'
  3. import { renderComponent } from '#tests/support/components/index.ts'
  4. import { useApplicationStore } from '#shared/stores/application.ts'
  5. import CommonDateTime, { type Props } from '../CommonDateTime.vue'
  6. vi.hoisted(() => {
  7. vi.useFakeTimers().setSystemTime(new Date('2020-10-11T10:10:10Z'))
  8. })
  9. const dateTime = '2020-10-10T10:10:10Z'
  10. const renderDateTime = (props: Props) => {
  11. return renderComponent(CommonDateTime, {
  12. props: {
  13. ...props,
  14. },
  15. store: true,
  16. })
  17. }
  18. describe('CommonDateTime.vue', () => {
  19. it('renders with type relative', async () => {
  20. const view = renderDateTime({ dateTime, type: 'relative' })
  21. expect(view.container).toHaveTextContent('1 day ago')
  22. })
  23. it('renders with type absolute + absolute format "datetime" (default)', async () => {
  24. const view = renderDateTime({
  25. dateTime,
  26. type: 'absolute',
  27. })
  28. expect(view.container).toHaveTextContent('2020-10-10 10:10')
  29. })
  30. it('renders with type absolute + absolute format "datetime" (set via prop)', async () => {
  31. const view = renderDateTime({
  32. dateTime,
  33. type: 'absolute',
  34. absoluteFormat: 'datetime',
  35. })
  36. expect(view.container).toHaveTextContent('2020-10-10 10:10')
  37. })
  38. it('renders with type absolute + absolute format "date"', async () => {
  39. const view = renderDateTime({
  40. dateTime,
  41. type: 'absolute',
  42. absoluteFormat: 'date',
  43. })
  44. expect(view.container).toHaveTextContent('2020-10-10')
  45. })
  46. it('renders with type absolute (application store)', async () => {
  47. const view = renderDateTime({ dateTime, type: 'absolute' })
  48. useApplicationStore().config.pretty_date_format = 'absolute'
  49. await nextTick()
  50. expect(view.container).toHaveTextContent('2020-10-10')
  51. })
  52. it('renders with type configured + absolute format "date" (application store)', async () => {
  53. const view = renderDateTime({ dateTime, type: 'configured' })
  54. useApplicationStore().config.pretty_date_format = 'absolute'
  55. await nextTick()
  56. expect(view.container).toHaveTextContent('2020-10-10')
  57. })
  58. it('renders with type timestamp (application store)', async () => {
  59. const view = renderDateTime({ dateTime, type: 'configured' })
  60. useApplicationStore().config.pretty_date_format = 'timestamp'
  61. await nextTick()
  62. expect(view.container).toHaveTextContent('2020-10-10 10:10')
  63. })
  64. it('renders with type relative (application store)', async () => {
  65. const view = renderDateTime({ dateTime, type: 'configured' })
  66. useApplicationStore().config.pretty_date_format = 'relative'
  67. await nextTick()
  68. expect(view.container).toHaveTextContent('1 day ago')
  69. })
  70. })