@@ -124,6 +124,67 @@ describe('mapFacetsCached WITH an initial value', () => {
124
124
// check that the map was called just once
125
125
expect ( mapFunction ) . toHaveBeenCalledTimes ( 1 )
126
126
} )
127
+
128
+ it ( 'gets NO_VALUE as a value from a single source if it also has NO_VALUE' , ( ) => {
129
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
130
+ const sourceFacet = createFacet ( { initialValue : NO_VALUE } )
131
+ const mapFacet = mapFacetsCached ( [ sourceFacet ] , mapFunction , ( ) => ( ) => false )
132
+
133
+ expect ( mapFacet . get ( ) ) . toBe ( NO_VALUE )
134
+ } )
135
+
136
+ it ( 'gets NO_VALUE as a value from multiple sources if they also have NO_VALUE' , ( ) => {
137
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
138
+ const sourceAFacet = createFacet ( { initialValue : 'initial value' } )
139
+ const sourceBFacet = createFacet ( { initialValue : NO_VALUE } )
140
+ const mapFacet = mapFacetsCached ( [ sourceAFacet , sourceBFacet ] , mapFunction , ( ) => ( ) => false )
141
+
142
+ expect ( mapFacet . get ( ) ) . toBe ( NO_VALUE )
143
+ } )
144
+
145
+ it ( 'can get the mapped value from a single source before any subscription' , ( ) => {
146
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
147
+ const sourceFacet = createFacet ( { initialValue : 'initial value' } )
148
+ const mapFacet = mapFacetsCached ( [ sourceFacet ] , mapFunction , ( ) => ( ) => false )
149
+
150
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
151
+ } )
152
+
153
+ it ( 'can get the mapped value from multiple sources before any subscription' , ( ) => {
154
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
155
+ const sourceAFacet = createFacet ( { initialValue : 'initial value' } )
156
+ const sourceBFacet = createFacet ( { initialValue : 'initial value' } )
157
+ const mapFacet = mapFacetsCached ( [ sourceAFacet , sourceBFacet ] , mapFunction , ( ) => ( ) => false )
158
+
159
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
160
+ } )
161
+
162
+ it ( 'caches calls to the mapFunction through a get call before any subscription, given a single source' , ( ) => {
163
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
164
+ const sourceFacet = createFacet ( { initialValue : 'initial value' } )
165
+ const mapFacet = mapFacetsCached ( [ sourceFacet ] , mapFunction , ( ) => ( ) => false )
166
+
167
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
168
+ expect ( mapFunction ) . toHaveBeenCalledTimes ( 1 )
169
+
170
+ mapFunction . mockClear ( )
171
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
172
+ expect ( mapFunction ) . not . toHaveBeenCalled ( )
173
+ } )
174
+
175
+ it ( 'caches calls to the mapFunction through a get call before any subscription, given multiple sources' , ( ) => {
176
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
177
+ const sourceAFacet = createFacet ( { initialValue : 'initial value' } )
178
+ const sourceBFacet = createFacet ( { initialValue : 'initial value' } )
179
+ const mapFacet = mapFacetsCached ( [ sourceAFacet , sourceBFacet ] , mapFunction , ( ) => ( ) => false )
180
+
181
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
182
+ expect ( mapFunction ) . toHaveBeenCalledTimes ( 1 )
183
+
184
+ mapFunction . mockClear ( )
185
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
186
+ expect ( mapFunction ) . not . toHaveBeenCalled ( )
187
+ } )
127
188
} )
128
189
129
190
describe ( 'mapFacetsLightweight' , ( ) => {
0 commit comments