|
| 1 | +@testable import SWModels |
| 2 | +import Testing |
| 3 | + |
| 4 | +struct LoginCredentialsTests { |
| 5 | + @Test |
| 6 | + func testInitializationWithDefaultValues() { |
| 7 | + let credentials = LoginCredentials() |
| 8 | + #expect(credentials.login == "") |
| 9 | + #expect(credentials.password == "") |
| 10 | + #expect(credentials.minPasswordSize == Constants.minPasswordSize) |
| 11 | + } |
| 12 | + |
| 13 | + @Test |
| 14 | + func testInitializationWithCustomParameters() { |
| 15 | + let credentials = LoginCredentials( |
| 16 | + |
| 17 | + password: "qwerty", |
| 18 | + minPasswordSize: 5 |
| 19 | + ) |
| 20 | + #expect (credentials .login == "[email protected]") |
| 21 | + #expect(credentials.password == "qwerty") |
| 22 | + #expect(credentials.minPasswordSize == 5) |
| 23 | + } |
| 24 | + |
| 25 | + // MARK: - isReady |
| 26 | + |
| 27 | + @Test |
| 28 | + func testIsReady_AllFieldsEmpty() { |
| 29 | + let credentials = LoginCredentials() |
| 30 | + #expect(!credentials.isReady) |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + func testIsReady_LoginNotEmptyPasswordTooShort() { |
| 35 | + let credentials = LoginCredentials(login: "user", password: "12345") |
| 36 | + #expect(!credentials.isReady) |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + func testIsReady_ValidLoginAndExactMinPassword() { |
| 41 | + let credentials = LoginCredentials(login: "user", password: "123456") |
| 42 | + #expect(credentials.isReady) |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + func testIsReady_PasswordWithSpacesMeetingMinLength() { |
| 47 | + let credentials = LoginCredentials(login: "user", password: "12 345 6") |
| 48 | + #expect(credentials.isReady) |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + func testIsReady_PasswordWithSpacesBelowMinLength() { |
| 53 | + let credentials = LoginCredentials(login: "user", password: "123 45") |
| 54 | + #expect(!credentials.isReady) |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + func testIsReady_CustomMinPasswordSizeValidation() { |
| 59 | + let credentials = LoginCredentials( |
| 60 | + login: "user", |
| 61 | + password: "1234", |
| 62 | + minPasswordSize: 4 |
| 63 | + ) |
| 64 | + #expect(credentials.isReady) |
| 65 | + |
| 66 | + let credentials2 = LoginCredentials( |
| 67 | + login: "user", |
| 68 | + password: "123", |
| 69 | + minPasswordSize: 4 |
| 70 | + ) |
| 71 | + #expect(!credentials2.isReady) |
| 72 | + } |
| 73 | + |
| 74 | + // MARK: - canRestorePassword |
| 75 | + |
| 76 | + @Test |
| 77 | + func testCanRestorePassword_EmptyLogin() { |
| 78 | + let credentials = LoginCredentials(login: "") |
| 79 | + #expect(!credentials.canRestorePassword) |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + func testCanRestorePassword_NonEmptyLogin() { |
| 84 | + let credentials = LoginCredentials(login: " ") |
| 85 | + #expect(credentials.canRestorePassword) |
| 86 | + |
| 87 | + let credentials2 = LoginCredentials(login : "[email protected]") |
| 88 | + #expect(credentials2.canRestorePassword) |
| 89 | + } |
| 90 | + |
| 91 | + // MARK: - canLogIn |
| 92 | + |
| 93 | + @Test |
| 94 | + func testCanLogIn_AllConditionsMet() { |
| 95 | + let credentials = LoginCredentials(login: "user", password: "123456") |
| 96 | + #expect(credentials.canLogIn(isError: false, isNetworkConnected: true)) |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + func testCanLogIn_WhenNotReady() { |
| 101 | + let credentials = LoginCredentials(login: "user", password: "123") |
| 102 | + #expect(!credentials.canLogIn(isError: false, isNetworkConnected: true)) |
| 103 | + } |
| 104 | + |
| 105 | + @Test |
| 106 | + func testCanLogIn_WithError() { |
| 107 | + let credentials = LoginCredentials(login: "user", password: "123456") |
| 108 | + #expect(!credentials.canLogIn(isError: true, isNetworkConnected: true)) |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + func testCanLogIn_NoNetwork() { |
| 113 | + let credentials = LoginCredentials(login: "user", password: "123456") |
| 114 | + #expect(!credentials.canLogIn(isError: false, isNetworkConnected: false)) |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + func testCanLogIn_MultipleIssues() { |
| 119 | + let credentials = LoginCredentials(login: "user", password: "123") |
| 120 | + #expect(!credentials.canLogIn(isError: true, isNetworkConnected: false)) |
| 121 | + } |
| 122 | +} |
0 commit comments