Skip to content

Instantly share code, notes, and snippets.

View atimca's full-sized avatar

Maxim Smirnov atimca

View GitHub Profile
@atimca
atimca / Signal+Extensions.swift
Created November 5, 2020 13:00
Entwine+Blocking
//
// Copyright © 2020 maximsmirnov. All rights reserved.
//
import Entwine
public extension Signal {
var error: Failure? {
guard case .completion(.failure(let error)) = self else { return nil }
return error
🛑 failed - Unexpected state mutation: …
  AppState(
  todos: [
  Todo(
− isComplete: false,
+ isComplete: true,
  description: "Milk",
  id: 00000000-0000-0000-0000-000000000000
  ),
  ]
private let reducer: (inout State, Action, Environment) -> Effect<Action, Never>
store.assert(
.environment {
$0.currentDate = { 100 }
$0.trainingProcessor = TrainingProcessor(
applyGrade: { _, _, _ in flashCard },
nextTraining: { _ in flashCard }
)
},
.send(.fillTheBlanks(.goNext(grade))),
.receive(.trainingCompleted(.bright)) {
struct StateStore {
private let scheduler: TestScheduler
init(
scheduler: TestScheduler,
permissionService: (PermissionType) -> Observable<PermissionStatus> = { _ in .never() },
alertModule: (AlertModule.State) -> Observable<GeneralEvent> = { _ in .never() }
)
}
import RxCocoa
import RxSwift
import RxTest
open class TestStore<State: Core.State, Event>: Store<State, Event> where State.Event == Event {
private let observer: TestableObserver<State>
private let scheduler: TestScheduler
private let disposeBag: DisposeBag
public init(scheduler: TestScheduler,
// User wants to open calendar event edit.
// User doesn't have permission for editing a calendar.
// Request should be sent to the user.
// If the user authorized the permission.
// Calendar event edit will be opened.
// User added new event. -> Calendar State should be saved. And then the scene should be dismissed with Calendar State == nil.
// After dismissing dismissedScene should be calendar.
func testCalendarUserStoryWithPermission() {
// Given
let authorizedEvents = [PermissionType.events: PermissionStatus.authorized]
func testAfterDataLoadedEventStateWillBeChangedIntoLoadedWithReceivedData() {
// Given
let initialState: State = .initial
let data = ["first", "second"]
// When
let resultState = State.reduce(state: initialState, event: .dataLoaded(data: data))
// Then
XCTAssertEqual(resultState, .loaded(data: data))
}
extension State {
static func reduce(state: State, event: Event) -> State {
var state = state
switch event {
case .dataLoaded(let data):
state = .loaded(data: data)
case .loadData:
state = .loading
}
return state
func reduce(state: State, event: Event) -> State