Skip to content

Commit 20192a3

Browse files
committed
test elevation init and apply methods
1 parent ae2c005 commit 20192a3

File tree

1 file changed

+89
-2
lines changed

1 file changed

+89
-2
lines changed

Tests/YCoreUITests/Components/ElevationTests.swift

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,95 @@
99
import XCTest
1010
@testable import YCoreUI
1111

12+
struct Elevation {
13+
let offset: CGSize
14+
let blur: CGFloat
15+
let spread: CGFloat
16+
let color: UIColor
17+
let opacity: CGFloat
18+
let useShadowPath: Bool
19+
20+
init(
21+
offset: CGSize,
22+
blur: CGFloat,
23+
spread: CGFloat,
24+
color: UIColor,
25+
opacity: CGFloat,
26+
useShadowPath: Bool = true
27+
) {
28+
self.offset = offset
29+
self.blur = blur
30+
self.spread = spread
31+
self.color = color
32+
self.opacity = opacity
33+
self.useShadowPath = useShadowPath
34+
}
35+
36+
func apply(layer: CALayer) {
37+
guard useShadowPath else { return }
38+
39+
layer.shadowPath = UIBezierPath().cgPath
40+
}
41+
}
42+
1243
final class ElevationTests: XCTestCase {
13-
func test_failure() {
14-
XCTFail("Failed")
44+
func test_init_deliversGivenValues() {
45+
let sut = makeSUT()
46+
47+
XCTAssertEqual(sut.offset, CGSize(width: 1, height: 1))
48+
XCTAssertEqual(sut.blur, 2)
49+
XCTAssertEqual(sut.spread, 3)
50+
XCTAssertEqual(sut.color, .red)
51+
XCTAssertEqual(sut.opacity, 5)
52+
XCTAssertEqual(sut.useShadowPath, true)
53+
}
54+
55+
func test_init_defaultValue() {
56+
let sut = Elevation(
57+
offset: CGSize(width: 1, height: 1),
58+
blur: 2,
59+
spread: 3,
60+
color: .red,
61+
opacity: 5
62+
)
63+
64+
XCTAssertEqual(sut.useShadowPath, true)
65+
}
66+
67+
func test_apply_doesNotAddShadowPathWhenUseShadowPathIsFalse() {
68+
let sut = makeSUT(useShadowPath: false)
69+
70+
let layer = CALayer()
71+
72+
sut.apply(layer: layer)
73+
74+
XCTAssertNil(layer.shadowPath)
75+
}
76+
77+
func test_apply_addsShadowPathWhenUseShadowPathIsTrue() {
78+
let sut = makeSUT(useShadowPath: true)
79+
80+
let layer = CALayer()
81+
82+
sut.apply(layer: layer)
83+
84+
XCTAssertNotNil(layer.shadowPath)
85+
}
86+
87+
func makeSUT(offset: CGSize = CGSize(width: 1, height: 1),
88+
blur: CGFloat = 2,
89+
spread: CGFloat = 3,
90+
color: UIColor = .red,
91+
opacity: CGFloat = 5,
92+
useShadowPath: Bool = true
93+
) -> Elevation {
94+
Elevation(
95+
offset: offset,
96+
blur: blur,
97+
spread: spread,
98+
color: color,
99+
opacity: opacity,
100+
useShadowPath: useShadowPath
101+
)
15102
}
16103
}

0 commit comments

Comments
 (0)