@@ -6,6 +6,37 @@ import { Attachment } from '../../../src/components/gherkin'
6
6
import { render } from '../utils'
7
7
8
8
describe ( '<Attachment>' , ( ) => {
9
+ it ( 'renders a video' , ( ) => {
10
+ const binary = new Uint8Array ( 10 )
11
+ binary . fill ( 255 , 0 , binary . length )
12
+ const attachment : messages . Attachment = {
13
+ mediaType : 'video/mp4' ,
14
+ body : 'fake-base64' ,
15
+ contentEncoding : messages . AttachmentContentEncoding . BASE64 ,
16
+ }
17
+ const { container } = render ( < Attachment attachment = { attachment } /> )
18
+ const summary = container . querySelector ( 'details summary' )
19
+ const video = container . querySelector ( 'video source' )
20
+ assert . strictEqual ( summary ! . textContent , 'Attached Video (video/mp4)' )
21
+ assert . strictEqual ( video ! . getAttribute ( 'src' ) , 'data:video/mp4;base64,fake-base64' )
22
+ } )
23
+
24
+ it ( 'renders a video with a name' , ( ) => {
25
+ const binary = new Uint8Array ( 10 )
26
+ binary . fill ( 255 , 0 , binary . length )
27
+ const attachment : messages . Attachment = {
28
+ mediaType : 'video/mp4' ,
29
+ fileName : 'the attachment name' ,
30
+ body : 'fake-base64' ,
31
+ contentEncoding : messages . AttachmentContentEncoding . BASE64 ,
32
+ }
33
+ const { container } = render ( < Attachment attachment = { attachment } /> )
34
+ const summary = container . querySelector ( 'details summary' )
35
+ const video = container . querySelector ( 'video source' )
36
+ assert . strictEqual ( summary ! . textContent , 'the attachment name' )
37
+ assert . strictEqual ( video ! . getAttribute ( 'src' ) , 'data:video/mp4;base64,fake-base64' )
38
+ } )
39
+
9
40
it ( 'renders an image' , ( ) => {
10
41
const binary = new Uint8Array ( 10 )
11
42
binary . fill ( 255 , 0 , binary . length )
@@ -15,7 +46,25 @@ describe('<Attachment>', () => {
15
46
contentEncoding : messages . AttachmentContentEncoding . BASE64 ,
16
47
}
17
48
const { container } = render ( < Attachment attachment = { attachment } /> )
49
+ const summary = container . querySelector ( 'details summary' )
18
50
const img = container . querySelector ( 'img' )
51
+ assert . strictEqual ( summary ! . textContent , 'Attached Image (image/png)' )
52
+ assert . strictEqual ( img ! . getAttribute ( 'src' ) , 'data:image/png;base64,fake-base64' )
53
+ } )
54
+
55
+ it ( 'renders an image with a name' , ( ) => {
56
+ const binary = new Uint8Array ( 10 )
57
+ binary . fill ( 255 , 0 , binary . length )
58
+ const attachment : messages . Attachment = {
59
+ mediaType : 'image/png' ,
60
+ fileName : 'the attachment name' ,
61
+ body : 'fake-base64' ,
62
+ contentEncoding : messages . AttachmentContentEncoding . BASE64 ,
63
+ }
64
+ const { container } = render ( < Attachment attachment = { attachment } /> )
65
+ const summary = container . querySelector ( 'details summary' )
66
+ const img = container . querySelector ( 'img' )
67
+ assert . strictEqual ( summary ! . textContent , 'the attachment name' )
19
68
assert . strictEqual ( img ! . getAttribute ( 'src' ) , 'data:image/png;base64,fake-base64' )
20
69
} )
21
70
@@ -26,8 +75,24 @@ describe('<Attachment>', () => {
26
75
contentEncoding : messages . AttachmentContentEncoding . BASE64 ,
27
76
}
28
77
const { container } = render ( < Attachment attachment = { attachment } /> )
29
- const pre = container . querySelector ( 'pre' )
30
- assert . strictEqual ( pre ! . textContent , 'hello' )
78
+ const summary = container . querySelector ( 'details summary' )
79
+ const data = container . querySelector ( 'details pre span' )
80
+ assert . strictEqual ( summary ! . textContent , 'Attached Text (text/plain)' )
81
+ assert . strictEqual ( data ! . textContent , 'hello' )
82
+ } )
83
+
84
+ it ( 'renders base64 encoded plaintext with a name' , ( ) => {
85
+ const attachment : messages . Attachment = {
86
+ mediaType : 'text/plain' ,
87
+ fileName : 'the attachment name' ,
88
+ body : Buffer . from ( 'hello' ) . toString ( 'base64' ) ,
89
+ contentEncoding : messages . AttachmentContentEncoding . BASE64 ,
90
+ }
91
+ const { container } = render ( < Attachment attachment = { attachment } /> )
92
+ const summary = container . querySelector ( 'details summary' )
93
+ const data = container . querySelector ( 'details pre span' )
94
+ assert . strictEqual ( summary ! . textContent , 'the attachment name' )
95
+ assert . strictEqual ( data ! . textContent , 'hello' )
31
96
} )
32
97
33
98
it ( 'correctly renders ANSI characters' , ( ) => {
@@ -37,9 +102,28 @@ describe('<Attachment>', () => {
37
102
contentEncoding : messages . AttachmentContentEncoding . IDENTITY ,
38
103
}
39
104
const { container } = render ( < Attachment attachment = { attachment } /> )
40
- const span = container . querySelector ( 'pre > span' )
105
+ const summary = container . querySelector ( 'details summary' )
106
+ const data = container . querySelector ( 'details > pre > span' )
107
+ assert . strictEqual ( summary ! . textContent , 'Attached Text (text/x.cucumber.log+plain)' )
108
+ assert . strictEqual (
109
+ data ! . innerHTML ,
110
+ '<span style="color:#000">black<span style="color:#AAA">white</span></span>'
111
+ )
112
+ } )
113
+
114
+ it ( 'correctly renders ANSI characters with a name' , ( ) => {
115
+ const attachment : messages . Attachment = {
116
+ mediaType : 'text/x.cucumber.log+plain' ,
117
+ fileName : 'the attachment name' ,
118
+ body : '\x1b[30mblack\x1b[37mwhite' ,
119
+ contentEncoding : messages . AttachmentContentEncoding . IDENTITY ,
120
+ }
121
+ const { container } = render ( < Attachment attachment = { attachment } /> )
122
+ const summary = container . querySelector ( 'details summary' )
123
+ const data = container . querySelector ( 'details > pre > span' )
124
+ assert . strictEqual ( summary ! . textContent , 'the attachment name' )
41
125
assert . strictEqual (
42
- span ! . innerHTML ,
126
+ data ! . innerHTML ,
43
127
'<span style="color:#000">black<span style="color:#AAA">white</span></span>'
44
128
)
45
129
} )
0 commit comments