Slide 1

Slide 1 text

DocC Tutorial ͱ TCA ʹ͓͚Δςετػೳͷ঺հ TCA ͰΘ͍Θ͍ LT ձ ΞΠΧϫ

Slide 2

Slide 2 text

DocC Tutorial

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

https://github.com/kalupas226/ tca-workshop

Slide 5

Slide 5 text

https://lu.ma/9a52kvnm

Slide 6

Slide 6 text

νϡʔτϦΞϧͷߏ੒ • 4 Chapter Ͱ TCA ͷجຊʙ࣮ફతͳ஌ࣝΛ਎ʹ෇͚Δ͜ͱ͕Ͱ͖Δ • TCA 1.9.2 ʹରԠࡁΈ (2024/03/17 ࣌఺) • GitHub Actions Ͱ push ͷ౓ʹ GitHub Pages ʹσϓϩΠ͞ΕΔঢ়ଶʹͳ͓ͬͯΓɺ ΠϕϯτͷλΠϛϯά౳ͰϒϥογϡΞοϓ͍ͯ͠Δ • DocC ʹΑΔνϡʔτϦΞϧ࡞੒ͷࢀߟʹͳΔ͔΋ • `Sources/Docs` ʹશͯͷϑΝΠϧ͕͋Γ·͢ • Xcode 15 ͷ DocC Preview ͕ͳ͚Ε͹࡞Δͷ͕ݫ͔ͬͨ͠…

Slide 7

Slide 7 text

TCA ͷςετػೳ

Slide 8

Slide 8 text

The testability of features built in the Composable Architecture is the #1 priority of the library. https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/testing/

Slide 9

Slide 9 text

TCA ͷςετ let store = TestStore(initialState: Feature.State(count: 0)) { Feature() }

Slide 10

Slide 10 text

໢ཏੑ (Exhaustivity) ͷ͋Δςετ͕Մೳ let store = TestStore(initialState: Feature.State(count: 0)) { Feature() } await store.send(.incrementButtonTapped)

Slide 11

Slide 11 text

໢ཏੑ (Exhaustivity) ͷ͋Δςετ͕Մೳ let store = TestStore(initialState: Feature.State(count: 0)) { Feature() } await store.send(.incrementButtonTapped) { $0.count = 1 }

Slide 12

Slide 12 text

TCA ʹ͓͚Δςετͷ໢ཏੑ (Exhaustivity) • ໢ཏੑΛอͬͯςετΛॻ͚Δ͜ͱ͸ TCA ͷେ͖ͳϝϦοτ • ͔͠͠ɺίʔυͷن໛ʹΑͬͯ͸ɺ໢ཏੑ͕ٯޮՌʹͳΔ͜ͱ΋͋Δ • ಛʹ TCA ͷੑ্࣭ɺΞϓϦͷ Root feature ΄Ͳ໢ཏੑΛอͪͳ͕Β ςετΛॻ͘͜ͱ͕೉͘͠ͳΓ͕ͪ

Slide 13

Slide 13 text

Root Feature (App) → Child Feature (Login) ʹ ͓͚Δςετͷ໢ཏੑͷྫ await store.send(\.login.submitButtonTapped) { // 1⃣ Ϣʔβʔͷ submit button λοϓΛΤϛϡϨʔτ͢Δɻ $0.login?.isLoading = true // 2⃣ login feature ͷ͢΂ͯͷঢ়ଶͷมߋΛ assertion ͢Δɻ // ... } await store.receive(\.login.loginResponse.success) { // 3⃣ login feature Ͱ͸ API ϦΫΤετ͕ߦΘΕΔͨΊɺͦͷϋϯυϦϯά͕ඞཁɻ $0.login?.isLoading = false // 4⃣ login feature ͷ͢΂ͯͷঢ়ଶͷมߋΛ assertion ͢Δɻ // ... } await store.receive(\.login.delegate.didLogin) { // 5⃣ login feature ͸ϩάΠϯ͕੒ޭͨ͜͠ͱΛ Delegate Action Λ௨ͯ͡਌ʹ఻͑Δɻ // 6⃣ app feature ͷ͢΂ͯͷঢ়ଶͷมߋΛ assertion ͢Δɻ $0.authenticatedTab = .loggedIn( Profile.State(...) ) // 7⃣ ࠷ऴతʹλϒͷঢ়ଶ͕มߋ͞ΕΔ͜ͱΛ assertion ͯ͠ςετऴྃɻ $0.selectedTab = .activity }

Slide 14

Slide 14 text

Exhaustivity Λ o ff ʹͯ͠ Root Feature ͷ ݶΒΕͨ෦෼͚ͩͷςετΛߦ͏ store.exhaustivity = .off // ⬅ // Ϣʔβʔͷ submit button λοϓΛΤϛϡϨʔτ͢Δɻ await store.send(\.login.submitButtonTapped) // ࠷ऴతʹ login feature ʹΑͬͯϩάΠϯ͕੒ޭͨ͜͠ͱ͕ app feature ʹ఻ΘΓɺ // ͦΕʹΑΓى͖ΔมߋΛ assertion ͢Δ͚ͩͱͳΔɻ await store.receive(\.login.delegate.didLogin) { $0.selectedTab = .activity }

Slide 15

Slide 15 text

Exhaustivity Λ o ff ʹ͢Δ࣌ͷςΫχοΫ • ར༻͸ Root دΓͷ Feature ͚ͩʹཹΊΔ • `off(showSkippedAssertions:)` • Exhaustivity Λ off ʹͭͭ͠΋ skip ͞Εͨ΋ͷΛදࣔ͢Δ • `withExhaustivity(_:operation:)` • ෦෼తʹ exhaustivity Λ off ʹͯ͠ςετͰ͖Δ • `skipReceivedActions(strict: fi le:line)` • ड͚औͬͨ action Λશͯ skip ͢Δ • `assert(_: fi le:line:)` • Store ͷঢ়ଶͷ assertion ͕ՄೳͰɺಛʹ Store ͷ࠷ऴঢ়ଶΛ assertion ͢Δͷʹศར

Slide 16

Slide 16 text

TCA ͰςετΛॻ্͘Ͱ໾ཱͭଞͷ࿩ • `withDependencies(_:operation:)` • ෦෼తʹґଘΛॻ͖׵͑ͯςετ͢Δ • `useMainSerialExecutor` • Async ͳฒྻॲཧΛϝΠϯεϨουͰॲཧ͠ςελϒϧʹ͢Δ • ࠓͷ TCA ͸σϑΥϧτͰ͜ͷػೳ͕༗ޮʹͳ͍ͬͯΔ • Non-exhaustive testing ͷ஫ҙ఺ • https://pointfreeco.github.io/swift-composable-architecture/main/documentation/ composablearchitecture/testing#Non-exhaustive-testing