@@ -40,8 +40,24 @@ final class SimplePaymentsSummaryViewModelTests: XCTestCase {
4040
4141 func test_provided_amount_gets_properly_formatted( ) {
4242 // Given
43+ let mockStores = MockStoresManager ( sessionManager: . testingInstance)
44+ mockStores. whenReceivingAction ( ofType: AppSettingsAction . self) { action in
45+ switch action {
46+ case let . getSimplePaymentsTaxesToggleState( _, onCompletion) :
47+ onCompletion ( . success( false ) ) // Keep the taxes toggle turned off
48+ case . setSimplePaymentsTaxesToggleState:
49+ break // No op
50+ default :
51+ XCTFail ( " Unexpected action: \( action) " )
52+ }
53+ }
54+
4355 let currencyFormatter = CurrencyFormatter ( currencySettings: CurrencySettings ( ) ) // Default is US.
44- let viewModel = SimplePaymentsSummaryViewModel ( providedAmount: " 100 " , totalWithTaxes: " 104.30 " , taxAmount: " $4.3 " , currencyFormatter: currencyFormatter)
56+ let viewModel = SimplePaymentsSummaryViewModel ( providedAmount: " 100 " ,
57+ totalWithTaxes: " 104.30 " ,
58+ taxAmount: " $4.3 " ,
59+ currencyFormatter: currencyFormatter,
60+ stores: mockStores)
4561
4662 // When & Then
4763 XCTAssertEqual ( viewModel. providedAmount, " $100.00 " )
@@ -215,26 +231,55 @@ final class SimplePaymentsSummaryViewModelTests: XCTestCase {
215231
216232 func test_noteAdded_event_is_tracked_after_editing_note( ) {
217233 // Given
234+ let mockStores = MockStoresManager ( sessionManager: . testingInstance)
235+ mockStores. whenReceivingAction ( ofType: AppSettingsAction . self) { action in
236+ switch action {
237+ case let . getSimplePaymentsTaxesToggleState( _, onCompletion) :
238+ onCompletion ( . success( true ) )
239+ case . setSimplePaymentsTaxesToggleState:
240+ break // No op
241+ default :
242+ XCTFail ( " Unexpected action: \( action) " )
243+ }
244+ }
245+
218246 let mockAnalytics = MockAnalyticsProvider ( )
219247 let viewModel = SimplePaymentsSummaryViewModel ( providedAmount: " 1.0 " ,
220248 totalWithTaxes: " 1.0 " ,
221249 taxAmount: " 0.0 " ,
250+ stores: mockStores,
222251 analytics: WooAnalytics ( analyticsProvider: mockAnalytics) )
223252
224253 // When
225254 viewModel. noteViewModel. newNote = " content "
226255 viewModel. noteViewModel. updateNote ( onFinish: { _ in } )
227256
228257 // Then
229- assertEqual ( mockAnalytics. receivedEvents, [ WooAnalyticsStat . simplePaymentsFlowNoteAdded. rawValue] )
258+ assertEqual ( mockAnalytics. receivedEvents, [
259+ WooAnalyticsStat . simplePaymentsFlowTaxesToggled. rawValue, // Event triggered when view model loads the toggle state during initialization
260+ WooAnalyticsStat . simplePaymentsFlowNoteAdded. rawValue
261+ ] )
230262 }
231263
232264 func test_taxesToggled_event_is_tracked_after_switching_taxes_toggle( ) {
233265 // Given
266+ let mockStores = MockStoresManager ( sessionManager: . testingInstance)
267+ mockStores. whenReceivingAction ( ofType: AppSettingsAction . self) { action in
268+ switch action {
269+ case let . getSimplePaymentsTaxesToggleState( _, onCompletion) :
270+ onCompletion ( . success( false ) )
271+ case . setSimplePaymentsTaxesToggleState:
272+ break // No op
273+ default :
274+ XCTFail ( " Unexpected action: \( action) " )
275+ }
276+ }
277+
234278 let mockAnalytics = MockAnalyticsProvider ( )
235279 let viewModel = SimplePaymentsSummaryViewModel ( providedAmount: " 1.0 " ,
236280 totalWithTaxes: " 1.0 " ,
237281 taxAmount: " 0.0 " ,
282+ stores: mockStores,
238283 analytics: WooAnalytics ( analyticsProvider: mockAnalytics) )
239284
240285 // When
@@ -243,12 +288,15 @@ final class SimplePaymentsSummaryViewModelTests: XCTestCase {
243288
244289 // Then
245290 assertEqual ( mockAnalytics. receivedEvents, [
291+ WooAnalyticsStat . simplePaymentsFlowTaxesToggled. rawValue, // Event triggered when view model loads the toggle state during initialization
246292 WooAnalyticsStat . simplePaymentsFlowTaxesToggled. rawValue, // Taxes enabled
247293 WooAnalyticsStat . simplePaymentsFlowTaxesToggled. rawValue // Taxes disabled
248294 ] )
249295
250- assertEqual ( mockAnalytics. receivedProperties [ 0 ] [ " state " ] as? String , " on " ) // Taxes enabled
251- assertEqual ( mockAnalytics. receivedProperties [ 1 ] [ " state " ] as? String , " off " ) // Taxes disabled
296+ assertEqual ( mockAnalytics. receivedProperties [ 0 ] [ " state " ] as? String ,
297+ " off " ) // Taxes disabled when view model loads the toggle state during initialization
298+ assertEqual ( mockAnalytics. receivedProperties [ 1 ] [ " state " ] as? String , " on " ) // Taxes enabled due to setting `enableTaxes` as true
299+ assertEqual ( mockAnalytics. receivedProperties [ 2 ] [ " state " ] as? String , " off " ) // Taxes disabled due to setting `enableTaxes` as false
252300 }
253301
254302 func test_failing_event_is_tracked_when_order_fails_to_update( ) {
0 commit comments