@@ -20,58 +20,105 @@ final class OneOfRegexValidatorTests: XCTestCase {
2020 error: " Type one of social profile link (insta, facebook, linkedIn) "
2121 )
2222 } ( )
23-
24- private var subscription = Set < AnyCancellable > ( )
25-
26- init ( ) {
27- socialProfileValidator
28- . assign ( to: \. validationResult, on: self )
29- . store ( in: & subscription)
30- }
3123 }
3224
3325 let viewModel = ViewModel ( )
26+ var cancellables : Set < AnyCancellable > !
27+
28+ override func setUp( ) {
29+ super. setUp ( )
30+ cancellables = . init( )
31+ }
3432
3533 func testIgnoreFirstValue( ) {
34+ viewModel. socialProfileValidator
35+ . sink ( receiveValue: { _ in } )
36+ . store ( in: & cancellables)
37+
3638 XCTAssertEqual ( viewModel. validationResult, . untouched)
3739 }
3840
3941 func testExpectedInstagramInput( ) {
42+ let expectation = XCTestExpectation ( description: " Instagram input expectation " )
43+
44+ viewModel. socialProfileValidator
45+ . sink ( receiveValue: { [ weak self] result in
46+ self ? . viewModel. validationResult = result
47+ expectation. fulfill ( )
48+ } )
49+ . store ( in: & cancellables)
50+
4051 viewModel. socialProfileUrl = " instagram.com/userprofile "
4152
42- _ = XCTWaiter . wait ( for: [ XCTestExpectation ( ) ] , timeout: 0.75 )
53+ wait ( for: [ expectation ] , timeout: 1 )
4354
4455 XCTAssertEqual ( viewModel. validationResult, . success( . instagram) )
4556 }
4657
4758 func testExpectedFacebookInput( ) {
48- viewModel . socialProfileUrl = " facebook.com/userprofile "
59+ let expectation = XCTestExpectation ( description : " Facebook input expectation " )
4960
50- _ = XCTWaiter . wait ( for: [ XCTestExpectation ( ) ] , timeout: 0.75 )
61+ viewModel. socialProfileValidator
62+ . sink ( receiveValue: { [ weak self] result in
63+ self ? . viewModel. validationResult = result
64+ expectation. fulfill ( )
65+ } )
66+ . store ( in: & cancellables)
67+
68+ viewModel. socialProfileUrl = " facebook.com/userprofile "
69+
70+ wait ( for: [ expectation] , timeout: 1 )
5171
5272 XCTAssertEqual ( viewModel. validationResult, . success( . facebook) )
5373 }
5474
5575 func testExpectedLinkedInInput( ) {
76+ let expectation = XCTestExpectation ( description: " Linkedin input expectation " )
77+
78+ viewModel. socialProfileValidator
79+ . sink ( receiveValue: { [ weak self] result in
80+ self ? . viewModel. validationResult = result
81+ expectation. fulfill ( )
82+ } )
83+ . store ( in: & cancellables)
84+
5685 viewModel. socialProfileUrl = " linkedin.com/in/userprofile "
5786
58- _ = XCTWaiter . wait ( for: [ XCTestExpectation ( ) ] , timeout: 0.75 )
87+ wait ( for: [ expectation ] , timeout: 1 )
5988
6089 XCTAssertEqual ( viewModel. validationResult, . success( . linkedIn) )
6190 }
6291
6392 func testUnexpectedValue( ) {
93+ let expectation = XCTestExpectation ( description: " Youtube input expectation " )
94+
95+ viewModel. socialProfileValidator
96+ . sink ( receiveValue: { [ weak self] result in
97+ self ? . viewModel. validationResult = result
98+ expectation. fulfill ( )
99+ } )
100+ . store ( in: & cancellables)
101+
64102 viewModel. socialProfileUrl = " http://youtube.com/userprofile "
65103
66- _ = XCTWaiter . wait ( for: [ XCTestExpectation ( ) ] , timeout: 0.75 )
104+ wait ( for: [ expectation ] , timeout: 1 )
67105
68106 XCTAssertEqual ( viewModel. validationResult, . failure( reason: " Type one of social profile link (insta, facebook, linkedIn) " , tableName: nil ) )
69107 }
70108
71109 func testEmptyValue( ) {
110+ let expectation = XCTestExpectation ( description: " Invalid input expectation " )
111+
112+ viewModel. socialProfileValidator
113+ . sink ( receiveValue: { [ weak self] result in
114+ self ? . viewModel. validationResult = result
115+ expectation. fulfill ( )
116+ } )
117+ . store ( in: & cancellables)
118+
72119 viewModel. socialProfileUrl = " "
73120
74- _ = XCTWaiter . wait ( for: [ XCTestExpectation ( ) ] , timeout: 0.75 )
121+ wait ( for: [ expectation ] , timeout: 1 )
75122
76123 XCTAssertEqual ( viewModel. validationResult, . failure( reason: " Type one of social profile link (insta, facebook, linkedIn) " , tableName: nil ) )
77124 }
0 commit comments