-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ricocrescenzio95/3-add-uitests
Setup UITests
- Loading branch information
Showing
34 changed files
with
256 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Welcome to SUITextField contribution | ||
|
||
Thank you for investing your time in contributing to our project! | ||
|
||
## Issues | ||
|
||
### Create a new issue | ||
|
||
Open an [issue](https://github.com/ricocrescenzio95/SUITextField/issues/new?assignees=ricocrescenzio95&labels=enhancement&template=feature_request.md&title=%5BNEW%5D) or a [bug](https://github.com/ricocrescenzio95/SUITextField/issues/new?assignees=ricocrescenzio95&labels=enhancement&template=feature_request.md&title=%5BNEW%5D). | ||
|
||
### Solve an issue | ||
|
||
Create a branch from an existing issue (or first create an issue) and work on it 🥳 | ||
|
||
Just few things: | ||
|
||
- Try to follow Swift code-style, indenting 4 spaces and 120 char per line | ||
- Use documentation comments as much as you can. Update DocC documentation as well. | ||
- Write some snapshot tests (if you're not experienced, let [me](https://github.com/ricocrescenzio95) know, I might take care of those ✌🏻). | ||
|
||
## Pull Request | ||
|
||
Open a PR and describe your solution, any hidden implementation or workaround (if any). | ||
Don't forget to link the PR to the issue (Github should help you). Assign [me](https://github.com/ricocrescenzio95) as | ||
reviewer and we'll discuss about your solution. | ||
|
||
## Your PR is merged! | ||
|
||
Congratulations :tada::tada: The solution looks good and we can merge it :sparkles:. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...e/SUITextFieldExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-snapshot-testing", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git", | ||
"state" : { | ||
"revision" : "f8a9c997c3c1dab4e216a8ec9014e23144cbab37", | ||
"version" : "1.9.0" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// CoreTestCase.swift | ||
// | ||
// | ||
// Created by Rico Crescenzio on 14/04/22. | ||
// | ||
|
||
import XCTest | ||
import SnapshotTesting | ||
import SwiftUI | ||
|
||
class CoreTestCase: XCTestCase { | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
XCTAssertEqual(UIDevice.current.name, "iPhone 11 Pro") | ||
} | ||
|
||
func assertSnapshot<V>( | ||
matching view: V, | ||
asLayer: Bool = false, | ||
named name: String, | ||
record recording: Bool = false, | ||
timeout: TimeInterval = 5, | ||
file: StaticString = #file, | ||
testName: String = #function, | ||
line: UInt = #line | ||
) where V: View { | ||
let view = UIHostingController(rootView: view).view! | ||
SnapshotTesting.assertSnapshot( | ||
matching: view, | ||
as: .image(precision: 0.8, size: view.intrinsicContentSize), | ||
named: name, | ||
record: recording, | ||
file: file, | ||
testName: testName, | ||
line: line | ||
) | ||
let darkMode = UITraitCollection(userInterfaceStyle: .dark) | ||
SnapshotTesting.assertSnapshot( | ||
matching: view, | ||
as: .image(precision: 0.8, size: view.intrinsicContentSize, traits: darkMode), | ||
named: name + "-dark", | ||
record: recording, | ||
file: file, | ||
testName: testName, | ||
line: line | ||
) | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// | ||
// StylingTests.swift | ||
// | ||
// | ||
// Created by Rico Crescenzio on 14/04/22. | ||
// | ||
|
||
import XCTest | ||
@testable import SwiftUITextField | ||
import SnapshotTesting | ||
import SwiftUI | ||
|
||
final class StylingTests: CoreTestCase { | ||
|
||
private func testBorder(_ border: UITextField.BorderStyle, testName: String = #function) { | ||
let view = SUITextField(text: .constant("test")) | ||
.onUpdate { | ||
XCTAssertEqual($0.borderStyle, border) | ||
} | ||
.uiTextFieldBorderStyle(border) | ||
assertSnapshot(matching: view, | ||
named: "textField", | ||
testName: testName) | ||
} | ||
|
||
private func testAlignment(_ alignment: NSTextAlignment, testName: String = #function) { | ||
let view = SUITextField(text: .constant("test")) | ||
.onUpdate { | ||
XCTAssertEqual($0.textAlignment, alignment) | ||
} | ||
.frame(width: 200) | ||
.uiTextFieldTextAlignment(alignment) | ||
assertSnapshot(matching: view, | ||
named: "textField", | ||
testName: testName) | ||
} | ||
|
||
func testInitialState() { | ||
let view = SUITextField(text: .constant("test")) | ||
.onUpdate { | ||
XCTAssertEqual($0.borderStyle, .none) | ||
} | ||
.uiTextFieldBorderStyle(.none) | ||
assertSnapshot(matching: view, named: "textField") | ||
assertSnapshot(matching: SUITextField(text: .constant("test")), named: "textField") | ||
} | ||
|
||
func testRoundedRectBorder() { | ||
testBorder(.roundedRect) | ||
} | ||
|
||
func testBezelBorder() { | ||
testBorder(.bezel) | ||
} | ||
|
||
func testLineBorder() { | ||
testBorder(.line) | ||
} | ||
|
||
func testTextColor() { | ||
let view = SUITextField(text: .constant("test")) | ||
.onUpdate { | ||
XCTAssertEqual($0.textColor, .systemBlue) | ||
} | ||
.uiTextFieldTextColor(.systemBlue) | ||
assertSnapshot(matching: view, named: "textField") | ||
} | ||
|
||
func testLeftAlignment() { | ||
testAlignment(.left) | ||
} | ||
|
||
func testRightAlignment() { | ||
testAlignment(.right) | ||
} | ||
|
||
func testCenterAlignment() { | ||
testAlignment(.center) | ||
} | ||
|
||
func testNaturalAlignment() { | ||
testAlignment(.natural) | ||
} | ||
|
||
func testJustifiedAlignment() { | ||
testAlignment(.justified) | ||
} | ||
|
||
func testDefaultTextAttributesRewriteAll() { | ||
let attributes: [NSAttributedString.Key: Any] = [ | ||
.foregroundColor: UIColor.systemRed, | ||
.font: UIFont.systemFont(ofSize: 12, weight: .bold), | ||
.paragraphStyle: { | ||
let paragraph = NSMutableParagraphStyle() | ||
paragraph.alignment = .right | ||
return paragraph | ||
}(), | ||
.kern: 10, | ||
.backgroundColor: UIColor.systemYellow | ||
] | ||
let view = SUITextField(text: .constant("test")) | ||
.uiTextFieldDefaultTextAttributes(attributes) | ||
.frame(width: 200) | ||
assertSnapshot(matching: view, named: "textField") | ||
} | ||
|
||
func testDefaultTextAttributesKeepNew() { | ||
let attributes: [NSAttributedString.Key: Any] = [ | ||
.foregroundColor: UIColor.systemRed, | ||
.kern: 5 | ||
] | ||
let newAttributes: [NSAttributedString.Key: Any] = [ | ||
.foregroundColor: UIColor.systemBlue, | ||
] | ||
let view = SUITextField(text: .constant("test")) | ||
.uiTextFieldDefaultTextAttributes(newAttributes, mergePolicy: .keepNew) | ||
.uiTextFieldDefaultTextAttributes(attributes) | ||
.frame(width: 200) | ||
assertSnapshot(matching: view, named: "textField") | ||
} | ||
|
||
func testDefaultTextAttributesKeepOld() { | ||
let attributes: [NSAttributedString.Key: Any] = [ | ||
.foregroundColor: UIColor.systemRed, | ||
.kern: 5 | ||
] | ||
let newAttributes: [NSAttributedString.Key: Any] = [ | ||
.foregroundColor: UIColor.systemBlue, | ||
.paragraphStyle: { | ||
let paragraph = NSMutableParagraphStyle() | ||
paragraph.alignment = .right | ||
return paragraph | ||
}() | ||
] | ||
let view = SUITextField(text: .constant("test")) | ||
.uiTextFieldDefaultTextAttributes(newAttributes, mergePolicy: .keepOld) | ||
.uiTextFieldDefaultTextAttributes(attributes) | ||
.frame(width: 200) | ||
assertSnapshot(matching: view, named: "textField") | ||
} | ||
|
||
} |
Binary file added
BIN
+2.69 KB
...SUITextFieldTests/__Snapshots__/StylingTests/testBezelBorder.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.79 KB
Tests/SUITextFieldTests/__Snapshots__/StylingTests/testBezelBorder.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.51 KB
...extFieldTests/__Snapshots__/StylingTests/testCenterAlignment.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.29 KB
.../SUITextFieldTests/__Snapshots__/StylingTests/testCenterAlignment.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.53 KB
.../__Snapshots__/StylingTests/testDefaultTextAttributesKeepNew.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.06 KB
...Tests/__Snapshots__/StylingTests/testDefaultTextAttributesKeepNew.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.43 KB
.../__Snapshots__/StylingTests/testDefaultTextAttributesKeepOld.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.06 KB
...Tests/__Snapshots__/StylingTests/testDefaultTextAttributesKeepOld.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.53 KB
...Snapshots__/StylingTests/testDefaultTextAttributesRewriteAll.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.45 KB
...ts/__Snapshots__/StylingTests/testDefaultTextAttributesRewriteAll.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.26 KB
...UITextFieldTests/__Snapshots__/StylingTests/testInitialState.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.24 KB
Tests/SUITextFieldTests/__Snapshots__/StylingTests/testInitialState.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.42 KB
...FieldTests/__Snapshots__/StylingTests/testJustifiedAlignment.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.18 KB
...ITextFieldTests/__Snapshots__/StylingTests/testJustifiedAlignment.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.42 KB
...ITextFieldTests/__Snapshots__/StylingTests/testLeftAlignment.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.18 KB
Tests/SUITextFieldTests/__Snapshots__/StylingTests/testLeftAlignment.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.53 KB
.../SUITextFieldTests/__Snapshots__/StylingTests/testLineBorder.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.56 KB
Tests/SUITextFieldTests/__Snapshots__/StylingTests/testLineBorder.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.42 KB
...xtFieldTests/__Snapshots__/StylingTests/testNaturalAlignment.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.18 KB
...SUITextFieldTests/__Snapshots__/StylingTests/testNaturalAlignment.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.31 KB
...TextFieldTests/__Snapshots__/StylingTests/testRightAlignment.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.19 KB
...s/SUITextFieldTests/__Snapshots__/StylingTests/testRightAlignment.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.5 KB
...tFieldTests/__Snapshots__/StylingTests/testRoundedRectBorder.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.45 KB
...UITextFieldTests/__Snapshots__/StylingTests/testRoundedRectBorder.textField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.3 KB
...s/SUITextFieldTests/__Snapshots__/StylingTests/testTextColor.textField-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.08 KB
Tests/SUITextFieldTests/__Snapshots__/StylingTests/testTextColor.textField.png
Oops, something went wrong.