Skip to content

Commit 1892e75

Browse files
committed
Added some basic snapshot tests
1 parent ffd439b commit 1892e75

13 files changed

+113
-31
lines changed

Package.swift

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@ let package = Package(
77
name: "ResponsiveTextField",
88
platforms: [.iOS(.v13)],
99
products: [
10-
// Products define the executables and libraries a package produces, and make them visible to other packages.
1110
.library(
1211
name: "ResponsiveTextField",
1312
targets: ["ResponsiveTextField"]),
1413
],
1514
dependencies: [
16-
// Dependencies declare other packages that this package depends on.
17-
// .package(url: /* package url */, from: "1.0.0"),
15+
.package(name: "SnapshotTesting", url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.8.1")
1816
],
1917
targets: [
20-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
21-
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2218
.target(
2319
name: "ResponsiveTextField",
2420
dependencies: []),
2521
.testTarget(
2622
name: "ResponsiveTextFieldTests",
27-
dependencies: ["ResponsiveTextField"]),
23+
dependencies: ["ResponsiveTextField", "SnapshotTesting"],
24+
exclude: ["__Snapshots__"]),
2825
]
2926
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"object": {
3+
"pins": [
4+
{
5+
"package": "SnapshotTesting",
6+
"repositoryURL": "https://github.com/pointfreeco/swift-snapshot-testing.git",
7+
"state": {
8+
"branch": null,
9+
"revision": "c466812aa2e22898f27557e2e780d3aad7a27203",
10+
"version": "1.8.2"
11+
}
12+
}
13+
]
14+
},
15+
"version": 1
16+
}

Sources/ResponsiveTextField/ResponsiveTextField.swift

+4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ extension ResponsiveTextField {
173173
public struct Configuration {
174174
var configure: (UITextField) -> Void
175175

176+
public init(configure: @escaping (UITextField) -> Void) {
177+
self.configure = configure
178+
}
179+
176180
public static func combine(_ configurations: Self...) -> Self {
177181
combine(configurations)
178182
}

Tests/LinuxMain.swift

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,96 @@
11
import XCTest
2-
@testable import ResponsiveTextField
2+
import ResponsiveTextField
3+
import SnapshotTesting
4+
import SwiftUI
5+
6+
extension Snapshotting where Value: View, Format == UIImage {
7+
static var fixedSizeTextFieldImage: Self {
8+
.image(layout: .fixed(width: 320, height: 30))
9+
}
10+
}
311

412
final class ResponsiveTextFieldTests: XCTestCase {
5-
func testExample() {
6-
// This is an example of a functional test case.
7-
// Use XCTAssert and related functions to verify your tests produce the correct
8-
// results.
9-
XCTAssertEqual(ResponsiveTextField().text, "Hello, World!")
13+
func testEmptyTextField() {
14+
assertSnapshot(
15+
matching: ResponsiveTextField(
16+
placeholder: "Placeholder Text",
17+
text: .constant(""),
18+
isEditing: .constant(true),
19+
isSecure: false,
20+
configuration: .empty
21+
).padding(),
22+
as: .fixedSizeTextFieldImage
23+
)
24+
}
25+
26+
func testTextFieldWithText() {
27+
assertSnapshot(
28+
matching: ResponsiveTextField(
29+
placeholder: "Placeholder Text",
30+
text: .constant("Textfield with some text"),
31+
isEditing: .constant(true),
32+
isSecure: false,
33+
configuration: .empty
34+
).padding(),
35+
as: .fixedSizeTextFieldImage
36+
)
1037
}
1138

12-
static var allTests = [
13-
("testExample", testExample),
14-
]
39+
func testSecureTextEntry() {
40+
assertSnapshot(
41+
matching: ResponsiveTextField(
42+
placeholder: "Placeholder Text",
43+
text: .constant("ssh this is top secret"),
44+
isEditing: .constant(true),
45+
isSecure: true,
46+
configuration: .empty
47+
).padding(),
48+
as: .fixedSizeTextFieldImage
49+
)
50+
}
51+
52+
func testTextFieldCustomTextStyle() {
53+
assertSnapshot(
54+
matching: ResponsiveTextField(
55+
placeholder: "Placeholder Text",
56+
text: .constant("Textfield with some text"),
57+
isEditing: .constant(true),
58+
isSecure: false,
59+
configuration: .empty
60+
)
61+
.responsiveTextFieldFont(.preferredFont(forTextStyle: .headline))
62+
.responsiveTextFieldTextColor(.systemGreen)
63+
.padding(),
64+
as: .fixedSizeTextFieldImage
65+
)
66+
}
67+
68+
func testTextFieldCustomTextAlignment() {
69+
assertSnapshot(
70+
matching: ResponsiveTextField(
71+
placeholder: "Placeholder Text",
72+
text: .constant("Textfield with some text"),
73+
isEditing: .constant(true),
74+
isSecure: false,
75+
configuration: .empty
76+
)
77+
.responsiveTextFieldTextAlignment(.center)
78+
.padding(),
79+
as: .fixedSizeTextFieldImage,
80+
named: "Center"
81+
)
82+
assertSnapshot(
83+
matching: ResponsiveTextField(
84+
placeholder: "Placeholder Text",
85+
text: .constant("Textfield with some text"),
86+
isEditing: .constant(true),
87+
isSecure: false,
88+
configuration: .empty
89+
)
90+
.responsiveTextFieldTextAlignment(.right)
91+
.padding(),
92+
as: .fixedSizeTextFieldImage,
93+
named: "Right"
94+
)
95+
}
1596
}

Tests/ResponsiveTextFieldTests/XCTestManifests.swift

-9
This file was deleted.

0 commit comments

Comments
 (0)