Skip to content

Instantly share code, notes, and snippets.

View esilverberg's full-sized avatar

Eric Silverberg esilverberg

View GitHub Profile
@Nested
@DisplayName("given instruction cards should be shown")
inner class InstructionCards {
@BeforeEach
fun setup() {
matchViewModel.startButtonTapped()
}
@Test
fun `then swipe right card shown first`() {
context("given instruction cards should be shown") {
var testObs: TestObserver<PSSMatchViewModel.Event, Never>!
beforeEach {
testObs = TestObserver<PSSMatchViewModel.Event, Never>()
viewModel.events.signal.observe(testObs.observer)
}
it("then swipe right card shown first") {
guard case .started(let context) = viewModel.state.value else {
// Define the mock
class MatchApiFixture: PSSMatchApiImplementing {
public var getMatchStackValue: Result<PSSMatchStack, Error> = .success(PSSMatchStack.fixture!)
func getMatchStack() -> SignalProducer<PSSMatchStack, Error> {
return SignalProducer(getMatchStackValue)
}
}
// Inject into tests
let matchApi = (container.resolve(PSSMatchApiImplementing.self)! as! MatchApiFixture)
// Define the mock
single<IMatchApi> {
mockk<IMatchApi>(relaxed = true) {
every { getMatchStack() } returns Single.just(defaultMatchStack())
}
}
// inject into tests
val matchApi: IMatchApi by inject()
// 🍎 Using Quick and Swinject
describe("MatchViewModelTests") {
var container: Container!
var logic: PSSMatchLogic!
var accountRepository: PSSAccountRepository!
var appEventLogger: PSSAppEventLogging!
var viewModel: PSSMatchViewModel!
beforeEach {
container = Container().injectEverythingForTests()
// 🍎 Using Swinject
extension Container {
func injectAppRepositories() -> Container {
self.register(PSSMatchRepository.self) { resolver in
return PSSMatchRepository(
api: resolver.resolve(PSSMatchApiImplementing.self)!,
prefs: resolver.resolve(PSSPrefsStoreImplementing.self)!)
}.inObjectScope(.container)
}
}
Type iOS Android
Screens UIViewController Activity, Fragment
Views UIView View
Lists UICollectionView RecyclerView
Data sources UICollectionViewDataSource RecyclerView.Adapter
// 🍎
protocol PSSMatchApiImplementing {
func getMatchStack(location: CLLocationCoordinate2D,
browseMode: PSSBrowseMode?,
loadMore: Bool) -> SignalProducer<PSSMatchStack, Error>
func postRate(profile: PSSProfile, rating: PSSProfileRating) -> SignalProducer<Void, Error>
func postRateReminder(profile: PSSProfile) -> SignalProducer<Void, Error>
func deleteRating(profile: PSSProfile) -> SignalProducer<Void, Error>
}
// 🍎
class PSSMatchRepository {
private let kPrefsHasShownMatchInstructionsKey = "has_shown_match_instructions"
private let api: PSSMatchApiImplementing
private let prefs: PSSPrefsStoreImplementing
init(api: PSSMatchApiImplementing,
prefs: PSSPrefsStoreImplementing) {
self.api = api
// 🍎
final class PSSMatchLogic {
private let accountRepository: PSSAccountRepository
private let matchRepository: PSSMatchRepository
private let locationRepository: PSSLocationRepository
private let featureRepository: PSSFeatureRepository
init(accountRepository: PSSAccountRepository, matchRepository: PSSMatchRepository, locationRepository: PSSLocationRepository, featureRepository: PSSFeatureRepository) {
self.accountRepository = accountRepository
self.matchRepository = matchRepository