|
| 1 | +import {Kit, setupNumbersKit, setupNumbersWithTombstonesKit} from '../../__tests__/setup'; |
| 2 | +import {MarkerOverlayPoint} from '../MarkerOverlayPoint'; |
| 3 | + |
| 4 | +const runMarkersTests = (setup: () => Kit) => { |
| 5 | + describe('.markers()', () => { |
| 6 | + test('returns empty set by default', () => { |
| 7 | + const {peritext} = setup(); |
| 8 | + peritext.overlay.refresh(); |
| 9 | + const list = [...peritext.overlay.markers()]; |
| 10 | + expect(list.length).toBe(0); |
| 11 | + }); |
| 12 | + |
| 13 | + test('returns a single marker', () => { |
| 14 | + const {peritext, editor} = setup(); |
| 15 | + editor.cursor.setAt(3); |
| 16 | + editor.saved.insMarker('<paragraph>'); |
| 17 | + peritext.overlay.refresh(); |
| 18 | + const list = [...peritext.overlay.markers()]; |
| 19 | + expect(list.length).toBe(1); |
| 20 | + expect(list[0] instanceof MarkerOverlayPoint).toBe(true); |
| 21 | + }); |
| 22 | + |
| 23 | + test('can iterate through multiple markers', () => { |
| 24 | + const {peritext, editor} = setup(); |
| 25 | + editor.cursor.setAt(5); |
| 26 | + const [m2] = editor.saved.insMarker('<p2>'); |
| 27 | + peritext.overlay.refresh(); |
| 28 | + editor.cursor.setAt(8); |
| 29 | + const [m3] = editor.local.insMarker('<p3>'); |
| 30 | + peritext.overlay.refresh(); |
| 31 | + editor.cursor.setAt(2); |
| 32 | + const [m1] = editor.local.insMarker('<p1>'); |
| 33 | + peritext.overlay.refresh(); |
| 34 | + const list = [...peritext.overlay.markers()]; |
| 35 | + expect(list.length).toBe(3); |
| 36 | + list.forEach(m => expect(m instanceof MarkerOverlayPoint).toBe(true)); |
| 37 | + expect(list[0].marker).toBe(m1); |
| 38 | + expect(list[1].marker).toBe(m2); |
| 39 | + expect(list[2].marker).toBe(m3); |
| 40 | + }); |
| 41 | + |
| 42 | + test('can delete markers', () => { |
| 43 | + const {peritext, editor} = setup(); |
| 44 | + editor.cursor.setAt(5); |
| 45 | + const [m2] = editor.extra.insMarker('<p2>'); |
| 46 | + editor.cursor.setAt(8); |
| 47 | + const [m3] = editor.local.insMarker('<p3>'); |
| 48 | + editor.cursor.setAt(2); |
| 49 | + const [m1] = editor.local.insMarker('<p1>'); |
| 50 | + peritext.overlay.refresh(); |
| 51 | + const list = [...peritext.overlay.markers()]; |
| 52 | + expect(list.length).toBe(3); |
| 53 | + editor.local.del(m3); |
| 54 | + peritext.overlay.refresh(); |
| 55 | + const list2 = [...peritext.overlay.markers()]; |
| 56 | + expect(list2.length).toBe(2); |
| 57 | + expect(list2[0].marker).toBe(m1); |
| 58 | + expect(list2[1].marker).toBe(m2); |
| 59 | + editor.local.del(m2); |
| 60 | + peritext.overlay.refresh(); |
| 61 | + const list3 = [...peritext.overlay.markers()]; |
| 62 | + expect(list3.length).toBe(2); |
| 63 | + expect(list3[0].marker).toBe(m1); |
| 64 | + expect(list3[1].marker).toBe(m2); |
| 65 | + editor.extra.del(m2); |
| 66 | + peritext.overlay.refresh(); |
| 67 | + const list4 = [...peritext.overlay.markers()]; |
| 68 | + expect(list4.length).toBe(1); |
| 69 | + expect(list4[0].marker).toBe(m1); |
| 70 | + editor.local.del(m1); |
| 71 | + editor.local.del(m1); |
| 72 | + editor.local.del(m1); |
| 73 | + peritext.overlay.refresh(); |
| 74 | + expect([...peritext.overlay.markers()].length).toBe(0); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}; |
| 78 | + |
| 79 | +describe('numbers "0123456789", no edits', () => { |
| 80 | + runMarkersTests(setupNumbersKit); |
| 81 | +}); |
| 82 | + |
| 83 | +describe('numbers "0123456789", with default schema and tombstones', () => { |
| 84 | + runMarkersTests(setupNumbersWithTombstonesKit); |
| 85 | +}); |
0 commit comments