@@ -157,17 +157,27 @@ final class StoreContextTests: XCTestCase {
157157 )
158158
159159 XCTAssertEqual ( context. watch ( dependency0, in: transactionState) , 0 )
160- XCTAssertEqual ( store. graph. dependencies, [ key: [ dependency0Key] ] )
161- XCTAssertEqual ( store. graph. children, [ dependency0Key: [ key] ] )
160+ XCTAssertEqual (
161+ store. graph,
162+ Graph (
163+ dependencies: [ key: [ dependency0Key] ] ,
164+ children: [ dependency0Key: [ key] ]
165+ )
166+ )
162167 XCTAssertEqual ( ( store. state. caches [ dependency0Key] as? AtomCache < TestStateAtom < Int > > ) ? . value, 0 )
163168 XCTAssertNotNil ( store. state. states [ dependency0Key] )
164169 XCTAssertTrue ( snapshots. flatMap ( \. caches) . isEmpty)
165170
166171 transactionState. terminate ( )
167172
168173 XCTAssertEqual ( context. watch ( dependency1, in: transactionState) , 1 )
169- XCTAssertEqual ( store. graph. dependencies, [ key: [ dependency0Key] ] )
170- XCTAssertEqual ( store. graph. children, [ dependency0Key: [ key] ] )
174+ XCTAssertEqual (
175+ store. graph,
176+ Graph (
177+ dependencies: [ key: [ dependency0Key] ] ,
178+ children: [ dependency0Key: [ key] ]
179+ )
180+ )
171181 XCTAssertNil ( store. state. caches [ dependency1Key] )
172182 XCTAssertNil ( store. state. states [ dependency1Key] )
173183 XCTAssertTrue ( snapshots. isEmpty)
@@ -214,7 +224,7 @@ final class StoreContextTests: XCTestCase {
214224 )
215225
216226 XCTAssertEqual ( initialValue, 0 )
217- XCTAssertTrue ( subscriber. subscribing . contains ( key) )
227+ XCTAssertTrue ( store . graph . subscribed [ subscriber. key ] ? . contains ( key) ?? false )
218228 XCTAssertNotNil ( store. state. subscriptions [ key] ? [ subscriber. key] )
219229 XCTAssertEqual ( ( store. state. caches [ key] as? AtomCache < TestAtom > ) ? . value, 0 )
220230 XCTAssertEqual ( ( store. state. caches [ dependencyKey] as? AtomCache < DependencyAtom > ) ? . value, 0 )
@@ -226,11 +236,15 @@ final class StoreContextTests: XCTestCase {
226236 snapshots. removeAll ( )
227237 store. state. subscriptions [ key] ? [ subscriber. key] ? . update ( )
228238 subscriberState = nil
239+
229240 XCTAssertEqual ( updateCount, 1 )
241+ XCTAssertNil ( store. graph. subscribed [ subscriber. key] )
230242 XCTAssertNil ( store. state. caches [ key] )
231243 XCTAssertNil ( store. state. states [ key] )
244+ XCTAssertNil ( store. state. subscriptions [ key] )
232245 XCTAssertNil ( store. state. caches [ dependencyKey] )
233246 XCTAssertNil ( store. state. states [ dependencyKey] )
247+ XCTAssertNil ( store. state. subscriptions [ dependencyKey] )
234248 XCTAssertEqual (
235249 snapshots. map { $0. caches. mapValues { $0. value as? Int } } ,
236250 [ [ : ] ]
@@ -372,11 +386,21 @@ final class StoreContextTests: XCTestCase {
372386 )
373387
374388 _ = context. watch ( atom, subscriber: subscriber, subscription: Subscription ( ) )
375- snapshots. removeAll ( )
376389 context. unwatch ( atom, subscriber: subscriber)
390+
377391 XCTAssertEqual (
378392 snapshots. map { $0. caches. mapValues { $0. value as? Int } } ,
379- [ [ : ] ]
393+ [
394+ [ AtomKey ( atom) : 0 ] ,
395+ [ : ] ,
396+ ]
397+ )
398+ XCTAssertEqual (
399+ snapshots. map ( \. graph) ,
400+ [
401+ Graph ( subscribed: [ subscriber. key: [ AtomKey ( atom) ] ] ) ,
402+ Graph ( subscribed: [ subscriber. key: [ ] ] ) ,
403+ ]
380404 )
381405 }
382406
@@ -568,7 +592,7 @@ final class StoreContextTests: XCTestCase {
568592 context. unwatch ( dependency1Atom, subscriber: subscriber)
569593 context. unwatch ( dependency2Atom, subscriber: subscriber)
570594 scoped1Context. unwatch ( dependency1Atom, subscriber: subscriber)
571- scoped2Context. unwatch ( dependency1Atom , subscriber: subscriber)
595+ scoped2Context. unwatch ( dependency2Atom , subscriber: subscriber)
572596
573597 // Override for `scoped1Context` shouldn't inherited to `scoped2Context`.
574598 XCTAssertEqual ( scoped2Context. watch ( atom, subscriber: subscriber, subscription: Subscription ( ) ) , 21 )
@@ -644,6 +668,12 @@ final class StoreContextTests: XCTestCase {
644668 AtomKey ( atom) ,
645669 AtomKey ( publisherAtom) ,
646670 ] ,
671+ ] ,
672+ subscribed: [
673+ subscriber. key: [
674+ AtomKey ( ( atom) ) ,
675+ AtomKey ( ( publisherAtom) ) ,
676+ ]
647677 ]
648678 )
649679 )
@@ -1014,6 +1044,11 @@ final class StoreContextTests: XCTestCase {
10141044 AtomKey ( TestDependency1Atom ( ) ) : [ AtomKey ( TestAtom ( ) ) ] ,
10151045 AtomKey ( TestDependency2Atom ( ) ) : [ AtomKey ( TestAtom ( ) ) ] ,
10161046 AtomKey ( TestDependency3Atom ( ) , scopeKey: scopeToken. key) : [ AtomKey ( TestAtom ( ) ) ] ,
1047+ ] ,
1048+ subscribed: [
1049+ subscriber. key: [
1050+ AtomKey ( atom)
1051+ ]
10171052 ]
10181053 )
10191054
0 commit comments