Skip to content

Commit 23ea7a0

Browse files
committed
Add basic attachment gallery tests
1 parent 33abce1 commit 23ea7a0

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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

‎test/src/test_helpers/editor_helpers.coffee‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@ helpers.extend
1717
getComposition().insertFile(file)
1818
render()
1919

20+
insertAttachment: (attachment) ->
21+
getComposition().insertAttachment(attachment)
22+
render()
23+
24+
insertAttachments: (attachments) ->
25+
getComposition().insertAttachments(attachments)
26+
render()
27+
2028
insertImageAttachment: (attributes) ->
29+
attachment = helpers.createImageAttachment(attributes)
30+
helpers.insertAttachment(attachment)
31+
32+
createImageAttachment: (attributes) ->
2133
attributes ?=
2234
url: TEST_IMAGE_URL
2335
width: 10
@@ -26,9 +38,7 @@ helpers.extend
2638
filesize: 35
2739
contentType: "image/gif"
2840

29-
attachment = new Trix.Attachment attributes
30-
text = Trix.Text.textForAttachmentWithAttributes(attachment)
31-
helpers.insertText(text)
41+
new Trix.Attachment attributes
3242

3343
replaceDocument: (document) ->
3444
getComposition().setDocument(document)

0 commit comments

Comments
 (0)