diff --git a/.gitignore b/.gitignore index 3b29812..cf206b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,34 @@ +*.DS_Store .DS_Store -/.build -/Packages -/*.xcodeproj -xcuserdata/ +*.generated.swift + +## Build generated +build/ DerivedData/ -.swiftpm/config/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc +xcuserdata/ +xcshareddata/ +/.swiftpm +*.xcuserstate + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint + +# Swift Package Manager +.build/ +*Package.resolved +Package.resolved* + +# SwiftLint +lintOutput.json diff --git a/ExampleApp/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ExampleApp/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index da2cfba..0000000 --- a/ExampleApp/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,14 +0,0 @@ -{ - "pins" : [ - { - "identity" : "viewinspector", - "kind" : "remoteSourceControl", - "location" : "https://github.com/nalexn/ViewInspector", - "state" : { - "branch" : "master", - "revision" : "4effbd9143ab797eb60d2f32d4265c844c980946" - } - } - ], - "version" : 2 -} diff --git a/Package.resolved b/Package.resolved deleted file mode 100644 index da2cfba..0000000 --- a/Package.resolved +++ /dev/null @@ -1,14 +0,0 @@ -{ - "pins" : [ - { - "identity" : "viewinspector", - "kind" : "remoteSourceControl", - "location" : "https://github.com/nalexn/ViewInspector", - "state" : { - "branch" : "master", - "revision" : "4effbd9143ab797eb60d2f32d4265c844c980946" - } - } - ], - "version" : 2 -} diff --git a/Package.swift b/Package.swift index f92de2c..cb3a288 100644 --- a/Package.swift +++ b/Package.swift @@ -11,17 +11,16 @@ let package = Package( products: [ .library( name: "FormView", - targets: ["FormView"]) + targets: ["FormView"] + ) ], dependencies: [ - .package(url: "https://github.com/nalexn/ViewInspector", branch: "master") + .package(url: "https://github.com/nalexn/ViewInspector", exact: "0.10.1") ], targets: [ .target( name: "FormView", - dependencies: []), - .testTarget( - name: "FormViewTests", - dependencies: ["FormView", "ViewInspector"]) + dependencies: [] + ) ] ) diff --git a/Tests/FormViewTests/FormViewTests.swift b/Tests/FormViewTests/FormViewTests.swift deleted file mode 100644 index 726a10b..0000000 --- a/Tests/FormViewTests/FormViewTests.swift +++ /dev/null @@ -1,92 +0,0 @@ -// -// FormViewTests.swift -// -// -// Created by Maxim Aliev on 18.02.2023. -// - -import SwiftUI -import XCTest -import ViewInspector -import Combine -@testable import FormView - -final class FormViewTests: XCTestCase { - func testPreventInvalidInput() throws { - var text1 = "" - var text2 = "" - let sut = InspectionWrapperView( - wrapped: FormView { - ScrollView { - FormField( - value: Binding(get: { text1 }, set: { text1 = $0 }), - validationRules: [.digitsOnly] - ) - .id(1) - FormField(value: Binding(get: { text2 }, set: { text2 = $0 })) - .id(2) - } - } - ) - - let exp = sut.inspection.inspect { view in - let scrollView = try view.find(ViewType.ScrollView.self) - let textField1 = try view.find(viewWithId: 1).textField() - - try scrollView.callOnSubmit() - try textField1.callOnChange(newValue: "New Focus Field", index: 1) - try textField1.callOnChange(newValue: "123") - XCTAssertEqual(try textField1.input(), "123") - - text1 = "123" - try textField1.callOnChange(newValue: "123_A") - XCTAssertEqual(try textField1.input(), text1) - } - - ViewHosting.host(view: sut) - wait(for: [exp], timeout: 0.1) - } - - func testSubmitTextField() throws { - var text1 = "" - var text2 = "" - let sut = InspectionWrapperView( - wrapped: FormView { - ScrollView { - FormField( - value: Binding(get: { text1 }, set: { text1 = $0 }), - validationRules: [.digitsOnly] - ) - .id(1) - FormField(value: Binding(get: { text2 }, set: { text2 = $0 })) - .id(2) - } - } - ) - - let exp = sut.inspection.inspect { view in - let scrollView = try view.find(ViewType.ScrollView.self) - let textField1 = try view.find(viewWithId: 1).textField() -// let formField2 = try view.find(viewWithId: 2).view(FormField.self).actualView() - - try scrollView.callOnSubmit() - try textField1.callOnChange(newValue: "field2", index: 1) - -// XCTAssertEqual(formField2.focusField, "field2") - XCTAssertTrue(true) - } - - ViewHosting.host(view: sut.environment(\.focusField, "field1")) - wait(for: [exp], timeout: 0.1) - } - - func testFocusNextField() throws { - var fieldStates = [FieldState(id: "1", isFocused: false), FieldState(id: "2", isFocused: false)] - - var nextFocusField = fieldStates.focusNextField(currentFocusField: "") - XCTAssertEqual(nextFocusField, "1") - - nextFocusField = fieldStates.focusNextField(currentFocusField: "1") - XCTAssertEqual(nextFocusField, "2") - } -} diff --git a/Tests/FormViewTests/InspectionHelper/Inspection.swift b/Tests/FormViewTests/InspectionHelper/Inspection.swift deleted file mode 100644 index 77b5b12..0000000 --- a/Tests/FormViewTests/InspectionHelper/Inspection.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// Inspection.swift -// -// -// Created by Maxim Aliev on 18.02.2023. -// - -import Combine -import ViewInspector -@testable import FormView - -final class Inspection { - let notice = PassthroughSubject() - var callbacks: [UInt: (V) -> Void] = [:] - - func visit(_ view: V, _ line: UInt) { - if let callback = callbacks.removeValue(forKey: line) { - callback(view) - } - } -} - -extension Inspection: InspectionEmissary { } diff --git a/Tests/FormViewTests/InspectionHelper/InspectionWrapperView.swift b/Tests/FormViewTests/InspectionHelper/InspectionWrapperView.swift deleted file mode 100644 index 6fe6878..0000000 --- a/Tests/FormViewTests/InspectionHelper/InspectionWrapperView.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// InspectionWrapperView.swift -// -// -// Created by Maxim Aliev on 18.02.2023. -// - -import SwiftUI - -struct InspectionWrapperView: View { - let inspection = Inspection() - var wrapped: V - - init(wrapped: V) { - self.wrapped = wrapped - } - - var body: some View { - wrapped - .onReceive(inspection.notice) { - inspection.visit(self, $0) - } - } -} diff --git a/Tests/FormViewTests/Validation/TextValidationRuleTests.swift b/Tests/FormViewTests/Validation/TextValidationRuleTests.swift deleted file mode 100644 index b6dc3f5..0000000 --- a/Tests/FormViewTests/Validation/TextValidationRuleTests.swift +++ /dev/null @@ -1,79 +0,0 @@ -// -// TextValidationRuleTests.swift -// -// -// Created by Maxim Aliev on 07.02.2023. -// - -import XCTest -@testable import FormView - -final class TextValidationRuleTests: XCTestCase { - func testIgnoreEmpty() throws { - try test(textRule: .digitsOnly, trueString: "", falseString: "1234 A") - } - - func testNotEmpty() throws { - try test(textRule: .notEmpty, trueString: "Not empty", falseString: "") - } - - func testMinLength() throws { - try test(textRule: .minLength(4), trueString: "1234", falseString: "123") - } - - func testMaxLength() throws { - try test(textRule: .maxLength(4), trueString: "1234", falseString: "123456") - } - - func testAtLeastOneDigit() throws { - try test(textRule: .atLeastOneDigit, trueString: "Digit 5", falseString: "No Digits") - } - - func testAtLeastOneLetter() throws { - try test(textRule: .atLeastOneLetter, trueString: "1234 A", falseString: "1234") - } - - func testDigitsOnly() throws { - try test(textRule: .digitsOnly, trueString: "1234", falseString: "1234 A") - } - - func testLettersOnly() throws { - try test(textRule: .lettersOnly, trueString: "Letters", falseString: "Digit 5") - } - - func testAtLeastOneLowercaseLetter() throws { - try test(textRule: .atLeastOneLowercaseLetter, trueString: "LOWEr", falseString: "UPPER") - } - - func testAtLeastOneUppercaseLetter() throws { - try test(textRule: .atLeastOneUppercaseLetter, trueString: "Upper", falseString: "lower") - } - - func testAtLeastOneSpecialCharacter() throws { - try test(textRule: .atLeastOneSpecialCharacter, trueString: "Special %", falseString: "No special") - } - - func testNoSpecialCharacters() throws { - try test(textRule: .noSpecialCharacters, trueString: "No special", falseString: "Special %") - } - - func testEmail() throws { - try test(textRule: .email, trueString: "alievmaxx@gmail.com", falseString: "alievmaxx@.com") - } - - func testNotRecurringPincode() throws { - try test(textRule: .notRecurringPincode, trueString: "1234", falseString: "5555") - } - - func testRegex() throws { - let dateRegex = "(\\d{2}).(\\d{2}).(\\d{4})" - try test(textRule: .regex(dateRegex), trueString: "21.12.2000", falseString: "21..2000") - } - - private func test(textRule: TextValidationRule, trueString: String, falseString: String) throws { - let isPassed = textRule.check(value: trueString) - let isFailed = textRule.check(value: falseString) == false - - XCTAssertTrue(isPassed && isFailed) - } -} diff --git a/Tests/FormViewTests/Validation/ValidatorTests.swift b/Tests/FormViewTests/Validation/ValidatorTests.swift deleted file mode 100644 index a2f5d59..0000000 --- a/Tests/FormViewTests/Validation/ValidatorTests.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// ValidatorTests.swift -// -// -// Created by Maxim Aliev on 19.02.2023. -// - -import SwiftUI -import XCTest -@testable import FormView - -final class ValidatorTests: XCTestCase { - func testValidator() throws { - var text: String = "" - var failedValidationRules: [TextValidationRule] = [] - - let validator = FieldValidator( - value: Binding(get: { text }, set: { text = $0 }), - validationRules: [.digitsOnly], - inputRules: [.maxLength(4)], - failedValidationRules: Binding(get: { failedValidationRules }, set: { failedValidationRules = $0 }) - ) - - validator.value = "1" - validator.validate() - XCTAssertTrue(failedValidationRules.isEmpty) - - validator.value = "12_A" - XCTAssertEqual(failedValidationRules, [.digitsOnly]) - - validator.value = "12345" - let failedInputRules = validator.validateInput() - XCTAssertEqual(failedInputRules, [.maxLength(4)]) - } -}