clear.test.ts 1.1 KB

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