|
| 1 | +{assert, createImageAttachment, insertAttachments, moveCursor, pressKey, test, testGroup, typeCharacters} = Trix.TestHelpers |
| 2 | + |
| 3 | +ORC = Trix.OBJECT_REPLACEMENT_CHARACTER |
| 4 | + |
| 5 | +testGroup "Attachment galleries", template: "editor_empty", -> |
| 6 | + test "inserting more than one image attachment creates a gallery block", (expectDocument) -> |
| 7 | + insertAttachments(createImageAttachments(2)) |
| 8 | + assert.blockAttributes([0, 2], ["attachmentGallery"]) |
| 9 | + expectDocument "#{ORC}#{ORC}\n" |
| 10 | + |
| 11 | + test "gallery formatting is removed from blocks containing less than two image attachments", (expectDocument) -> |
| 12 | + insertAttachments(createImageAttachments(2)) |
| 13 | + assert.blockAttributes([0, 2], ["attachmentGallery"]) |
| 14 | + getEditor().setSelectedRange([1, 2]) |
| 15 | + pressKey "backspace", -> |
| 16 | + assert.blockAttributes([0, 2], []) |
| 17 | + expectDocument "#{ORC}\n" |
| 18 | + |
| 19 | + test "typing in an attachment gallery block splits it", (expectDocument) -> |
| 20 | + insertAttachments(createImageAttachments(4)) |
| 21 | + getEditor().setSelectedRange(2) |
| 22 | + typeCharacters "a", -> |
| 23 | + assert.blockAttributes([0, 2], ["attachmentGallery"]) |
| 24 | + assert.blockAttributes([3, 4], []) |
| 25 | + assert.blockAttributes([5, 7], ["attachmentGallery"]) |
| 26 | + expectDocument "#{ORC}#{ORC}\na\n#{ORC}#{ORC}\n" |
| 27 | + |
| 28 | +createImageAttachments = (num = 1) -> |
| 29 | + attachments = [] |
| 30 | + while attachments.length < num |
| 31 | + attachments.push(createImageAttachment()) |
| 32 | + attachments |
0 commit comments