-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathMarkdownImageTests.swift
146 lines (118 loc) · 3.84 KB
/
MarkdownImageTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#if os(iOS)
import SnapshotTesting
import SwiftUI
import XCTest
import MarkdownUI
final class MarkdownImageTests: XCTestCase {
private let layout = SwiftUISnapshotLayout.device(config: .iPhone8)
override func setUpWithError() throws {
try XCTSkipIf(UIDevice.current.userInterfaceIdiom == .pad, "Skipping on Mac Catalyst")
}
func testFailingImage() {
let view = Markdown {
#"""
An image that fails to load:
![](https://picsum.photos/500/300)
― Photo by André Spieker
"""#
}
.border(Color.accentColor)
.padding()
assertSnapshot(of: view, as: .image(layout: layout))
}
func testRelativeImage() {
let view = Markdown(baseURL: URL(string: "https://example.com/picsum/")) {
#"""
500x300 image:
![](237-500x300)
― Photo by André Spieker
"""#
}
.border(Color.accentColor)
.padding()
.markdownImageProvider(
AssetImageProvider(
name: { url in
XCTAssertEqual(
URL(string: "237-500x300", relativeTo: URL(string: "https://example.com/picsum/"))!,
url
)
return url.lastPathComponent
},
bundle: .module
)
)
assertSnapshot(of: view, as: .image(layout: layout))
}
func testImageLink() {
let view = Markdown {
#"""
A link that contains an image instead of text:
[![](https://example.com/picsum/237-100x150)](https://example.com)
― Photo by André Spieker
"""#
}
.border(Color.accentColor)
.padding()
.markdownImageProvider(AssetImageProvider(bundle: .module))
assertSnapshot(of: view, as: .image(layout: layout))
}
func testMultipleImages() throws {
guard #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) else {
throw XCTSkip("Required API is not available for this test")
}
let view = Markdown {
#"""
[![](https://example.com/picsum/237-100x150)](https://example.com)
![](https://example.com/picsum/237-125x75)
![](https://example.com/picsum/237-500x300)
![](https://example.com/picsum/237-100x150)\#u{20}\#u{20}
![](https://example.com/picsum/237-125x75)
― Photo by André Spieker
"""#
}
.border(Color.accentColor)
.padding()
.markdownImageProvider(AssetImageProvider(bundle: .module))
assertSnapshot(of: view, as: .image(layout: layout))
}
func testMultipleImagesSize() throws {
guard #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) else {
throw XCTSkip("Required API is not available for this test")
}
let view = Markdown {
#"""
![](https://example.com/picsum/237-100x150)
![](https://example.com/picsum/237-125x75)
― Photo by André Spieker
"""#
}
.border(Color.accentColor)
.padding()
.markdownImageProvider(AssetImageProvider(bundle: .module))
assertSnapshot(of: view, as: .image(layout: layout))
}
func testColorScheme() {
let content = """
This image is contextualized for either dark or light mode:
![](https://example.com/picsum/237-100x150#gh-dark-mode-only)
![](https://example.com/picsum/237-125x75#gh-light-mode-only)
― Photo by André Spieker
"""
let view = VStack {
Markdown(content)
.background()
.colorScheme(.light)
.border(Color.accentColor)
.padding()
Markdown(content)
.background()
.colorScheme(.dark)
.border(Color.accentColor)
.padding()
}
.markdownImageProvider(AssetImageProvider(bundle: .module))
assertSnapshot(of: view, as: .image(layout: layout))
}
}
#endif