clear.test.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import Plain from 'slate-plain-serializer';
  2. import ClearPlugin from './clear';
  3. describe('clear', () => {
  4. const handler = ClearPlugin().onKeyDown;
  5. it('does not change the empty value', () => {
  6. const change = Plain.deserialize('').change();
  7. const event = new window.KeyboardEvent('keydown', {
  8. key: 'k',
  9. ctrlKey: true,
  10. });
  11. handler(event, change);
  12. expect(Plain.serialize(change.value)).toEqual('');
  13. });
  14. it('clears to the end of the line', () => {
  15. const change = Plain.deserialize('foo').change();
  16. const event = new window.KeyboardEvent('keydown', {
  17. key: 'k',
  18. ctrlKey: true,
  19. });
  20. handler(event, change);
  21. expect(Plain.serialize(change.value)).toEqual('');
  22. });
  23. it('clears from the middle to the end of the line', () => {
  24. const change = Plain.deserialize('foo bar').change();
  25. change.move(4);
  26. const event = new window.KeyboardEvent('keydown', {
  27. key: 'k',
  28. ctrlKey: true,
  29. });
  30. handler(event, change);
  31. expect(Plain.serialize(change.value)).toEqual('foo ');
  32. });
  33. });