-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73795b2
commit 7d8741a
Showing
10 changed files
with
343 additions
and
20 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
.swiftpm/xcode/xcshareddata/xcschemes/FloatingTextField.xcscheme
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,103 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1500" | ||
version = "1.8"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "FloatingTextField" | ||
BuildableName = "FloatingTextField" | ||
BlueprintName = "FloatingTextField" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "NO" | ||
buildForArchiving = "NO" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "FloatingTextFieldTests" | ||
BuildableName = "FloatingTextFieldTests" | ||
BlueprintName = "FloatingTextFieldTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES" | ||
codeCoverageEnabled = "YES" | ||
onlyGenerateCoverageForSpecifiedTargets = "YES"> | ||
<CodeCoverageTargets> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "FloatingTextField" | ||
BuildableName = "FloatingTextField" | ||
BlueprintName = "FloatingTextField" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</CodeCoverageTargets> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "FloatingTextFieldTests" | ||
BuildableName = "FloatingTextFieldTests" | ||
BlueprintName = "FloatingTextFieldTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "FloatingTextField" | ||
BuildableName = "FloatingTextField" | ||
BlueprintName = "FloatingTextField" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
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,23 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-snapshot-testing", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-snapshot-testing", | ||
"state" : { | ||
"revision" : "bb0ea08db8e73324fe6c3727f755ca41a23ff2f4", | ||
"version" : "1.14.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-syntax", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-syntax.git", | ||
"state" : { | ||
"revision" : "74203046135342e4a4a627476dd6caf8b28fe11b", | ||
"version" : "509.0.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
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
Tests/FloatingTextFieldTests/SnapshotTests/FloatingTextFieldSnapshotTests.swift
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,68 @@ | ||
// | ||
// floating-text-field | ||
// Copyright © 2023 Space Code. All rights reserved. | ||
// | ||
|
||
@testable import FloatingTextField | ||
import SnapshotTesting | ||
import SwiftUI | ||
import XCTest | ||
|
||
// MARK: - FloatingTextFieldSnapshotTests | ||
|
||
final class FloatingTextFieldSnapshotTests: XCTestCase { | ||
// MARK: Tests | ||
|
||
func test_thatFloatingTextFieldShowsOnlyPlaceholder_whenTextIsEmpty() { | ||
assertSnapshots( | ||
of: FloatingTextField(.constant(.empty), placeholder: .placeholder), | ||
as: [.image(layout: .default, traits: .light)] | ||
) | ||
} | ||
|
||
func test_thatFloatingTextFieldShowsCompactedPlaceholder_whenTextIsNotEmpty() { | ||
assertSnapshots( | ||
of: FloatingTextField(.constant(.text), placeholder: .placeholder), | ||
as: [.image(layout: .default, traits: .light)] | ||
) | ||
} | ||
|
||
func test_thatFloatingTextFieldShowsSecureField() { | ||
assertSnapshots( | ||
of: FloatingTextField(.constant(.text), placeholder: .placeholder) | ||
.secureField(true), | ||
as: [.image(layout: .default, traits: .light)] | ||
) | ||
} | ||
|
||
func test_thatFloatingTextFieldShowsCustomizedView() { | ||
assertSnapshots( | ||
of: FloatingTextField(.constant(.text), placeholder: .placeholder) | ||
.textFont(Font.system(size: 17.0)) | ||
.borderWidth(2.0) | ||
.borderColor(.black) | ||
.focusedBorderColor(.black) | ||
.titleColor(Color.black) | ||
.placeholderFont(Font.system(size: 14.0)) | ||
.placeholderColor(.gray) | ||
.borderCornerRadius(12.0), | ||
as: [.image(layout: .default, traits: .light)] | ||
) | ||
} | ||
} | ||
|
||
// MARK: - Constants | ||
|
||
private extension String { | ||
static let empty = "" | ||
static let text = "[email protected]" | ||
static let placeholder = "Username" | ||
} | ||
|
||
private extension SwiftUISnapshotLayout { | ||
static let `default` = SwiftUISnapshotLayout.fixed(width: 375, height: 60) | ||
} | ||
|
||
private extension UITraitCollection { | ||
static let light = UITraitCollection(userInterfaceStyle: .light) | ||
} |
Binary file added
BIN
+12.9 KB
...ts/test_thatFloatingTextFieldShowsCompactedPlaceholder_whenTextIsNotEmpty.1.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
+18.1 KB
...atingTextFieldSnapshotTests/test_thatFloatingTextFieldShowsCustomizedView.1.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
+7.62 KB
...pshotTests/test_thatFloatingTextFieldShowsOnlyPlaceholder_whenTextIsEmpty.1.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
+8.34 KB
...FloatingTextFieldSnapshotTests/test_thatFloatingTextFieldShowsSecureField.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions
135
Tests/FloatingTextFieldTests/UnitTests/FloatingTextFieldTests.swift
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,135 @@ | ||
// | ||
// floating-text-field | ||
// Copyright © 2023 Space Code. All rights reserved. | ||
// | ||
|
||
@testable import FloatingTextField | ||
import SwiftUI | ||
import XCTest | ||
|
||
// MARK: - FloatingTextFieldTests | ||
|
||
final class FloatingTextFieldTests: XCTestCase { | ||
// MARK: Properties | ||
|
||
private var sut: FloatingTextField! | ||
|
||
// MARK: XCTestCase | ||
|
||
override func setUp() { | ||
super.setUp() | ||
sut = FloatingTextField( | ||
.constant(.text), | ||
placeholder: .placeholder | ||
) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
super.tearDown() | ||
} | ||
|
||
// MARK: Tests | ||
|
||
func test_thatFloatingTextFieldChangesForegroundColor_whenTitleColorDidSet() { | ||
// when | ||
_ = sut.titleColor(.red) | ||
|
||
// then | ||
XCTAssertEqual(sut.configuration.titleColor, .red) | ||
} | ||
|
||
func test_thatFloatingTextFieldChangesSecureEntry_whenSecureEntryDidSet() { | ||
// when | ||
_ = sut.secureField(true) | ||
|
||
// then | ||
XCTAssertTrue(sut.configuration.isSecureEntry) | ||
} | ||
|
||
func test_thatFloatingTextFieldChangesPlaceholderColor_whenPlaceholderColorDidSet() { | ||
// when | ||
_ = sut.placeholderColor(.red) | ||
|
||
// then | ||
XCTAssertEqual(sut.configuration.placeholderColor, .red) | ||
} | ||
|
||
func test_thatFloatingTextFieldChangesPlaceholderFont_whenPlaceholderFontDidSet() { | ||
// given | ||
let font = Font.system(size: 17.0) | ||
|
||
// when | ||
_ = sut.placeholderFont(font) | ||
|
||
// then | ||
XCTAssertEqual(sut.configuration.placeholderFont, font) | ||
} | ||
|
||
func test_thatFloatingTextFieldChangesFont_whenFontDidSet() { | ||
// given | ||
let font = Font.system(size: 17.0) | ||
|
||
// when | ||
_ = sut.textFont(font) | ||
|
||
// then | ||
XCTAssertEqual(sut.configuration.font, font) | ||
} | ||
|
||
func test_thatFloatingTextFieldChangesBorderWidth_whenBorderWidthDidSet() { | ||
// given | ||
let borderWidth: CGFloat = 1 | ||
|
||
// when | ||
_ = sut.borderWidth(borderWidth) | ||
|
||
// then | ||
XCTAssertEqual(sut.configuration.borderWidth, borderWidth) | ||
} | ||
|
||
func test_thatFloatingTextFieldChangesBorderColor_whenBorderColorDidSet() { | ||
// when | ||
_ = sut.borderColor(.red) | ||
|
||
// then | ||
XCTAssertEqual(sut.configuration.borderColor, .red) | ||
} | ||
|
||
func test_thatFloatingTextFieldChangesFocusedBorderColor_whenFocusedBorderColorDidSet() { | ||
// when | ||
_ = sut.focusedBorderColor(.red) | ||
|
||
// then | ||
XCTAssertEqual(sut.configuration.focusedBorderColor, .red) | ||
} | ||
|
||
func test_thatFloatingTextFieldChangesBorderCornerRadius_whenFocusedBorderCornerRadiusDidSet() { | ||
// given | ||
let cornerRadius: CGFloat = 12 | ||
|
||
// when | ||
_ = sut.borderCornerRadius(cornerRadius) | ||
|
||
// then | ||
XCTAssertEqual(sut.configuration.borderCornerRadius, cornerRadius) | ||
} | ||
|
||
func test_thatFloatingTextFieldChangesPlaceholderBottomPadding_whenPlaceholderBottomPaddingDidSet() { | ||
// given | ||
let padding: CGFloat = 12 | ||
|
||
// when | ||
_ = sut.placeholderBottomPadding(padding) | ||
|
||
// then | ||
XCTAssertEqual(sut.configuration.placeholderBottomPadding, padding) | ||
} | ||
} | ||
|
||
// MARK: - Constants | ||
|
||
private extension String { | ||
static let text = "text" | ||
static let placeholder = "placeholder" | ||
} |