Files
swift-composable-architectu…/Examples/CaseStudies/SwiftUICaseStudiesTests/02-Effects-LongLivingTests.swift
Stephen Celis 65401c361a Modernize case study using Notification Center (#1090)
* Use NotificationCenter directly in case study

* wip

* wip
2022-05-12 13:30:11 -04:00

34 lines
868 B
Swift

import Combine
import ComposableArchitecture
import XCTest
@testable import SwiftUICaseStudies
class LongLivingEffectsTests: XCTestCase {
func testReducer() {
let notificationCenter = NotificationCenter()
let store = TestStore(
initialState: .init(),
reducer: longLivingEffectsReducer,
environment: .init(
notificationCenter: notificationCenter
)
)
store.send(.onAppear)
// Simulate a screenshot being taken
notificationCenter.post(name: UIApplication.userDidTakeScreenshotNotification, object: nil)
store.receive(.userDidTakeScreenshotNotification) {
$0.screenshotCount = 1
}
store.send(.onDisappear)
// Simulate a screenshot being taken to show no effects
// are executed.
notificationCenter.post(name: UIApplication.userDidTakeScreenshotNotification, object: nil)
}
}