focus.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { CLASS_FOCUS_IN } from '../../../constants/classes';
  2. import { fire, init } from '../../../test';
  3. describe( 'Focus', () => {
  4. test( 'can add the status class to the root when focus comes into it by a key.', () => {
  5. const splide = init( {}, { arrows: true } );
  6. fire( document, 'keydown' );
  7. fire( splide.root, 'focusin' );
  8. expect( splide.root.classList.contains( CLASS_FOCUS_IN ) ).toBe( true );
  9. } );
  10. test( 'can remove the status class from the root when detecting pointerdown.', () => {
  11. const splide = init( {}, { arrows: true } );
  12. fire( document, 'keydown' );
  13. fire( splide.root, 'focusin' );
  14. expect( splide.root.classList.contains( CLASS_FOCUS_IN ) ).toBe( true );
  15. fire( splide.root, 'mousedown' );
  16. fire( splide.root, 'focusin' );
  17. expect( splide.root.classList.contains( CLASS_FOCUS_IN ) ).toBe( false );
  18. } );
  19. test( 'should not add the status class when focus comes into the root by pointing devices.', () => {
  20. const splide = init( {}, { arrows: true } );
  21. fire( document, 'mousedown' );
  22. fire( splide.root, 'focusin' );
  23. expect( splide.root.classList.contains( CLASS_FOCUS_IN ) ).toBe( false );
  24. } );
  25. } );