usePrintMode.spec.ts 863 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { usePrintMode } from '../usePrintMode.ts'
  3. describe('usePrintMode', () => {
  4. it('supports printing current page', () => {
  5. const { printPage } = usePrintMode()
  6. Object.defineProperty(window, 'print', {
  7. value: vi.fn(),
  8. })
  9. printPage()
  10. expect(window.print).toHaveBeenCalledOnce()
  11. })
  12. it('supports toggling print mode', () => {
  13. const { turnOnPrintMode, turnOffPrintMode } = usePrintMode()
  14. expect(document.querySelector(':root')).not.toHaveAttribute(
  15. 'data-print-mode',
  16. )
  17. turnOnPrintMode()
  18. expect(document.querySelector(':root')).toHaveAttribute(
  19. 'data-print-mode',
  20. 'true',
  21. )
  22. turnOffPrintMode()
  23. expect(document.querySelector(':root')).not.toHaveAttribute(
  24. 'data-print-mode',
  25. )
  26. })
  27. })