useCheckBodyAttachmentReference.spec.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { i18n } from '#shared/i18n.ts'
  3. import { useCheckBodyAttachmentReference } from '../useCheckBodyAttachmentReference.ts'
  4. describe('useCheckBodyAttachmentReference', () => {
  5. it('check for missing body attachment reference', () => {
  6. const { missingBodyAttachmentReference } = useCheckBodyAttachmentReference()
  7. expect(missingBodyAttachmentReference('I attached a file.')).toBeTruthy()
  8. })
  9. it('check for existing attachment and body reference', () => {
  10. const { missingBodyAttachmentReference } = useCheckBodyAttachmentReference()
  11. expect(
  12. missingBodyAttachmentReference('I attached a file.', [
  13. { id: '123', name: 'filename.png' },
  14. ]),
  15. ).toBeFalsy()
  16. })
  17. it('not attachment reference in body', () => {
  18. const { missingBodyAttachmentReference } = useCheckBodyAttachmentReference()
  19. expect(
  20. missingBodyAttachmentReference('I worked on the problem.'),
  21. ).toBeFalsy()
  22. })
  23. it('ignore attachment match words in quoted body parts', () => {
  24. const { missingBodyAttachmentReference } = useCheckBodyAttachmentReference()
  25. expect(
  26. missingBodyAttachmentReference(
  27. '<p>Yes I did already a first look.</p><blockquote type="cite" data-marker="signature-before"><p>I attached a file did you saw id?</p></blockquote>',
  28. ),
  29. ).toBeFalsy()
  30. })
  31. it('ignore attachment match words in signatures', () => {
  32. const { missingBodyAttachmentReference } = useCheckBodyAttachmentReference()
  33. expect(
  34. missingBodyAttachmentReference(
  35. '<p>Yes I did already a first look.</p><div data-signature="true"><p>I attached a file did you saw id?</p></div>',
  36. ),
  37. ).toBeFalsy()
  38. })
  39. it('ignore attachment match words when match word is not a single word', () => {
  40. i18n.setTranslationMap(
  41. new Map([['attachment,attached,enclosed,enclosure', 'Anlage']]),
  42. )
  43. const { missingBodyAttachmentReference } = useCheckBodyAttachmentReference()
  44. expect(
  45. missingBodyAttachmentReference(
  46. '<p>Siehe Screenshot der Telefonanlage</p>',
  47. ),
  48. ).toBeFalsy()
  49. })
  50. })