|
1 | 1 | 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 | +} |
3 | 11 |
|
4 | 12 | 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 | + ) |
10 | 37 | }
|
11 | 38 |
|
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 | + } |
15 | 96 | }
|
0 commit comments