@@ -10,7 +10,7 @@ import Foundation
1010import XCResultKit
1111
1212enum AttachmentType : String {
13- case unknwown = " "
13+ case unknown = " "
1414 case data = " public.data "
1515 case html = " public.html "
1616 case jpeg = " public.jpeg "
@@ -27,6 +27,23 @@ enum AttachmentType: String {
2727 return " "
2828 }
2929 }
30+
31+ fileprivate var mimeType : String ? {
32+ switch self {
33+ case . png:
34+ return " image/png "
35+ case . jpeg:
36+ return " image/jpeg "
37+ case . text:
38+ return " text/plain "
39+ case . html:
40+ return " text/html "
41+ case . data:
42+ return " application/octet-stream "
43+ case . unknown:
44+ return nil
45+ }
46+ }
3047}
3148
3249enum AttachmentName : RawRepresentable {
@@ -60,19 +77,21 @@ struct Attachment: HTML
6077{
6178 let padding : Int
6279 let filename : String
63- let path : String
80+ let content : RenderingContent
6481 let type : AttachmentType
6582 let name : AttachmentName ?
6683
67- init ( attachment: ActionTestAttachment , file: ResultFile , padding: Int = 0 ) {
84+ init ( attachment: ActionTestAttachment , file: ResultFile , padding: Int = 0 , configuration : Configuration ) {
6885 self . filename = attachment. filename ?? " "
69- self . type = AttachmentType ( rawValue: attachment. uniformTypeIdentifier) ?? . unknwown
86+ self . type = AttachmentType ( rawValue: attachment. uniformTypeIdentifier) ?? . unknown
7087 self . name = attachment. name. map ( AttachmentName . init ( rawValue: ) )
71- if let id = attachment. payloadRef? . id,
72- let url = file. exportPayload ( id: id) {
73- self . path = url. relativePath
88+ if let id = attachment. payloadRef? . id {
89+ self . content = file. exportPayloadContent (
90+ id: id,
91+ renderingMode: renderingMode
92+ )
7493 } else {
75- self . path = " "
94+ self . content = . none
7695 }
7796 self . padding = padding
7897 }
@@ -83,11 +102,25 @@ struct Attachment: HTML
83102 return " Screenshot "
84103 case . text, . html, . data:
85104 return " File "
86- case . unknwown :
105+ case . unknown :
87106 return " Attachment "
88107 }
89108 }
90-
109+
110+ var source : String ? {
111+ switch content {
112+ case let . data( data) :
113+ guard let mimeType = type. mimeType else {
114+ return nil
115+ }
116+ return " data: \( mimeType) ;base64, \( data. base64EncodedString ( ) ) "
117+ case let . url( url) :
118+ return url. relativePath
119+ case . none:
120+ return nil
121+ }
122+ }
123+
91124 var displayName : String {
92125 switch name {
93126 case . some( . custom( let customName) ) :
@@ -101,7 +134,7 @@ struct Attachment: HTML
101134 switch type {
102135 case . png, . jpeg:
103136 return true
104- case . text, . html, . data, . unknwown :
137+ case . text, . html, . data, . unknown :
105138 return false
106139 }
107140 }
@@ -114,15 +147,15 @@ struct Attachment: HTML
114147 return HTMLTemplates . screenshot
115148 case . text, . html, . data:
116149 return HTMLTemplates . text
117- case . unknwown :
150+ case . unknown :
118151 return " "
119152 }
120153 }
121154
122155 var htmlPlaceholderValues : [ String : String ] {
123156 return [
124157 " PADDING " : String ( padding) ,
125- " PATH " : path ,
158+ " SOURCE " : source ?? " " ,
126159 " FILENAME " : filename,
127160 " NAME " : displayName
128161 ]
0 commit comments