Skip to content

Commit

Permalink
Complete Combine tests, adding CurrentValueSubject bridge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luizmb committed Jun 24, 2019
1 parent c9cf7f2 commit 682e6a3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
4 changes: 4 additions & 0 deletions SwiftRex.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@
D5E734B422C17DDB00B0E284 /* PublisherTypeBridgeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E734A322C15AA300B0E284 /* PublisherTypeBridgeTests.swift */; };
D5E734B722C1810C00B0E284 /* SubjectTypeBridgeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E734A522C15AA400B0E284 /* SubjectTypeBridgeTests.swift */; };
D5E734B822C1810D00B0E284 /* SubjectTypeBridgeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E734A522C15AA400B0E284 /* SubjectTypeBridgeTests.swift */; };
D5E734B922C1826F00B0E284 /* ReplayLastSubjectTypeBridgeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E734A422C15AA400B0E284 /* ReplayLastSubjectTypeBridgeTests.swift */; };
D5E734BA22C1827000B0E284 /* ReplayLastSubjectTypeBridgeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E734A422C15AA400B0E284 /* ReplayLastSubjectTypeBridgeTests.swift */; };
D5FDCB3E22B70E690012D2E7 /* ReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A6071F2071287A00D682EF /* ReducerTests.swift */; };
D5FDCB3F22B70E8F0012D2E7 /* Action1.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A6070C2071287900D682EF /* Action1.swift */; };
D5FDCB4022B70E8F0012D2E7 /* Action2.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A6070A2071287900D682EF /* Action2.swift */; };
Expand Down Expand Up @@ -2680,6 +2682,7 @@
D5E734B722C1810C00B0E284 /* SubjectTypeBridgeTests.swift in Sources */,
D5E7349E22C15A1B00B0E284 /* FooSubscription.swift in Sources */,
D5E734B022C15AB700B0E284 /* SubscriptionBridgeTests.swift in Sources */,
D5E734B922C1826F00B0E284 /* ReplayLastSubjectTypeBridgeTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -3025,6 +3028,7 @@
D5E734B822C1810D00B0E284 /* SubjectTypeBridgeTests.swift in Sources */,
D5E734A022C15A1C00B0E284 /* FooSubscription.swift in Sources */,
D5E734AB22C15AB600B0E284 /* SubscriptionBridgeTests.swift in Sources */,
D5E734BA22C1827000B0E284 /* ReplayLastSubjectTypeBridgeTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
51 changes: 42 additions & 9 deletions UnitTests/Combine/Bridge/ReplayLastSubjectTypeBridgeTests.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import ReactiveSwift
import Combine
import SwiftRex
import SwiftRexForRac
import SwiftRexForCombine
import XCTest

class ReplayLastSubjectTypeBridgeTests: XCTestCase {
func testMutablePropertyToReplayLastSubjectTypeOnValue() {
func testCurrentValueSubjectToReplayLastSubjectTypeOnValue() {
let shouldCallClosureValue = expectation(description: "Closure value should be called")

let property = MutableProperty<String>("no one cares 1")
property.value = "no one cares 2"
property.value = "current value"
let currentValueSubject = CurrentValueSubject<String, SomeError>("no one cares 1")
currentValueSubject.value = "no one cares 2"
currentValueSubject.value = "current value"

let sut = ReplayLastSubjectType(property: property)
let sut = ReplayLastSubjectType(currentValueSubject: currentValueSubject)

var round = 1
_ = sut.publisher.subscribe(SubscriberType(
Expand All @@ -36,10 +36,43 @@ class ReplayLastSubjectTypeBridgeTests: XCTestCase {
wait(for: [shouldCallClosureValue], timeout: 0.1)
}

func testCurrentValueSubjectToReplayLastSubjectTypeOnErrorDoesAlwaysFinishSuccessfully() {
let shouldCallClosureValue = expectation(description: "Closure value should be called")
let shouldCallClosureCompletion = expectation(description: "Closure completion should be called")
let someError = SomeError()
let currentValueSubject = CurrentValueSubject<String, SomeError>("no one cares 1")
currentValueSubject.value = "no one cares 2"
currentValueSubject.value = "current value"

let sut = ReplayLastSubjectType<String, SomeError>(currentValueSubject: currentValueSubject)

_ = sut.publisher.subscribe(SubscriberType<String, SomeError>(
onValue: { string in
XCTAssertEqual("current value", string)
shouldCallClosureValue.fulfill()
},
onCompleted: { error in
// Different from other Reactive frameworks, Combine allows CurrentValueSubject to have an Error
// generic parameter different than Never, which can receive error. However, it does never propagates
// the error, finishing the stream successfully. It's not clear if this is a bug or it's by design,
// the same way it's not clear whether or not these Subjects should complete at all. Anyway, this test
// will be here to continuously observe this behaviour on Combine Framework and, eventually, adapt
// SwiftRex behaviour to possible changes.
XCTAssertNil(error)
shouldCallClosureCompletion.fulfill()
}
))

XCTAssertEqual(sut.value(), "current value")
sut.subscriber.onCompleted(someError)

wait(for: [shouldCallClosureValue, shouldCallClosureCompletion], timeout: 0.1)
}

func testDefaultReplayLastSubjectTypeOnValue() {
let shouldCallClosureValue = expectation(description: "Closure value should be called")

let sut = ReplayLastSubjectType.reactive(initialValue: "no one cares 1")
let sut = ReplayLastSubjectType<String, SomeError>.combine(initialValue: "no one cares 1")
sut.subscriber.onValue("no one cares 2")
sut.subscriber.onValue("current value")

Expand Down Expand Up @@ -69,7 +102,7 @@ class ReplayLastSubjectTypeBridgeTests: XCTestCase {
func testDefaultReplayLastSubjectTypeMutate() {
let shouldCallClosureValue = expectation(description: "Closure value should be called")

let sut = ReplayLastSubjectType.reactive(initialValue: "no one cares 1")
let sut = ReplayLastSubjectType<String, SomeError>.combine(initialValue: "no one cares 1")
sut.subscriber.onValue("no one cares 2")
sut.subscriber.onValue("current value")

Expand Down

0 comments on commit 682e6a3

Please sign in to comment.