Skip to content

Commit 835f9c6

Browse files
authored
Merge pull request #5795 from woocommerce/feat/5743-stats-view-model-tests
Add unit tests for `StoreStatsPeriodViewModel`
2 parents 5d2398b + 69ad305 commit 835f9c6

File tree

9 files changed

+568
-6
lines changed

9 files changed

+568
-6
lines changed

Networking/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,87 @@ extension OrderItemRefund {
391391
}
392392
}
393393

394+
extension OrderStatsV4 {
395+
public func copy(
396+
siteID: CopiableProp<Int64> = .copy,
397+
granularity: CopiableProp<StatsGranularityV4> = .copy,
398+
totals: CopiableProp<OrderStatsV4Totals> = .copy,
399+
intervals: CopiableProp<[OrderStatsV4Interval]> = .copy
400+
) -> OrderStatsV4 {
401+
let siteID = siteID ?? self.siteID
402+
let granularity = granularity ?? self.granularity
403+
let totals = totals ?? self.totals
404+
let intervals = intervals ?? self.intervals
405+
406+
return OrderStatsV4(
407+
siteID: siteID,
408+
granularity: granularity,
409+
totals: totals,
410+
intervals: intervals
411+
)
412+
}
413+
}
414+
415+
extension OrderStatsV4Interval {
416+
public func copy(
417+
interval: CopiableProp<String> = .copy,
418+
dateStart: CopiableProp<String> = .copy,
419+
dateEnd: CopiableProp<String> = .copy,
420+
subtotals: CopiableProp<OrderStatsV4Totals> = .copy
421+
) -> OrderStatsV4Interval {
422+
let interval = interval ?? self.interval
423+
let dateStart = dateStart ?? self.dateStart
424+
let dateEnd = dateEnd ?? self.dateEnd
425+
let subtotals = subtotals ?? self.subtotals
426+
427+
return OrderStatsV4Interval(
428+
interval: interval,
429+
dateStart: dateStart,
430+
dateEnd: dateEnd,
431+
subtotals: subtotals
432+
)
433+
}
434+
}
435+
436+
extension OrderStatsV4Totals {
437+
public func copy(
438+
totalOrders: CopiableProp<Int> = .copy,
439+
totalItemsSold: CopiableProp<Int> = .copy,
440+
grossRevenue: CopiableProp<Decimal> = .copy,
441+
couponDiscount: CopiableProp<Decimal> = .copy,
442+
totalCoupons: CopiableProp<Int> = .copy,
443+
refunds: CopiableProp<Decimal> = .copy,
444+
taxes: CopiableProp<Decimal> = .copy,
445+
shipping: CopiableProp<Decimal> = .copy,
446+
netRevenue: CopiableProp<Decimal> = .copy,
447+
totalProducts: NullableCopiableProp<Int> = .copy
448+
) -> OrderStatsV4Totals {
449+
let totalOrders = totalOrders ?? self.totalOrders
450+
let totalItemsSold = totalItemsSold ?? self.totalItemsSold
451+
let grossRevenue = grossRevenue ?? self.grossRevenue
452+
let couponDiscount = couponDiscount ?? self.couponDiscount
453+
let totalCoupons = totalCoupons ?? self.totalCoupons
454+
let refunds = refunds ?? self.refunds
455+
let taxes = taxes ?? self.taxes
456+
let shipping = shipping ?? self.shipping
457+
let netRevenue = netRevenue ?? self.netRevenue
458+
let totalProducts = totalProducts ?? self.totalProducts
459+
460+
return OrderStatsV4Totals(
461+
totalOrders: totalOrders,
462+
totalItemsSold: totalItemsSold,
463+
grossRevenue: grossRevenue,
464+
couponDiscount: couponDiscount,
465+
totalCoupons: totalCoupons,
466+
refunds: refunds,
467+
taxes: taxes,
468+
shipping: shipping,
469+
netRevenue: netRevenue,
470+
totalProducts: totalProducts
471+
)
472+
}
473+
}
474+
394475
extension PaymentGatewayAccount {
395476
public func copy(
396477
siteID: CopiableProp<Int64> = .copy,
@@ -1387,6 +1468,42 @@ extension SiteSetting {
13871468
}
13881469
}
13891470

1471+
extension SiteVisitStats {
1472+
public func copy(
1473+
siteID: CopiableProp<Int64> = .copy,
1474+
date: CopiableProp<String> = .copy,
1475+
granularity: CopiableProp<StatGranularity> = .copy,
1476+
items: NullableCopiableProp<[SiteVisitStatsItem]> = .copy
1477+
) -> SiteVisitStats {
1478+
let siteID = siteID ?? self.siteID
1479+
let date = date ?? self.date
1480+
let granularity = granularity ?? self.granularity
1481+
let items = items ?? self.items
1482+
1483+
return SiteVisitStats(
1484+
siteID: siteID,
1485+
date: date,
1486+
granularity: granularity,
1487+
items: items
1488+
)
1489+
}
1490+
}
1491+
1492+
extension SiteVisitStatsItem {
1493+
public func copy(
1494+
period: CopiableProp<String> = .copy,
1495+
visitors: CopiableProp<Int> = .copy
1496+
) -> SiteVisitStatsItem {
1497+
let period = period ?? self.period
1498+
let visitors = visitors ?? self.visitors
1499+
1500+
return SiteVisitStatsItem(
1501+
period: period,
1502+
visitors: visitors
1503+
)
1504+
}
1505+
}
1506+
13901507
extension SystemPlugin {
13911508
public func copy(
13921509
siteID: CopiableProp<Int64> = .copy,

Networking/Networking/Model/Stats/OrderStatsV4.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Codegen
33

44
/// Represents order stats over a specific period.
55
/// v4 API
6-
public struct OrderStatsV4: Decodable, Equatable, GeneratedFakeable {
6+
public struct OrderStatsV4: Decodable, Equatable, GeneratedCopiable, GeneratedFakeable {
77
public let siteID: Int64
88
public let granularity: StatsGranularityV4
99
public let totals: OrderStatsV4Totals

Networking/Networking/Model/Stats/OrderStatsV4Interval.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Codegen
22

33
/// Represents a single order stat for a specific period.
44
/// v4 API
5-
public struct OrderStatsV4Interval: Decodable, Equatable, GeneratedFakeable {
5+
public struct OrderStatsV4Interval: Decodable, Equatable, GeneratedCopiable, GeneratedFakeable {
66
public let interval: String
77
/// Interval start date string in the site time zone.
88
public let dateStart: String

Networking/Networking/Model/Stats/OrderStatsV4Totals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Codegen
22

33
/// Represents the data associated with order stats over a specific period.
44
/// v4
5-
public struct OrderStatsV4Totals: Decodable, Equatable, GeneratedFakeable {
5+
public struct OrderStatsV4Totals: Decodable, Equatable, GeneratedCopiable, GeneratedFakeable {
66
public let totalOrders: Int
77
public let totalItemsSold: Int
88
public let grossRevenue: Decimal

Networking/Networking/Model/Stats/SiteVisitStats.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Codegen
33

44
/// Represents site visit stats over a specific period.
55
///
6-
public struct SiteVisitStats: Decodable, GeneratedFakeable {
6+
public struct SiteVisitStats: Decodable, GeneratedCopiable, GeneratedFakeable {
77
public let siteID: Int64
88
public let date: String
99
public let granularity: StatGranularity

Networking/Networking/Model/Stats/SiteVisitStatsItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Codegen
33

44
/// Represents an single site visit stat for a specific period.
55
///
6-
public struct SiteVisitStatsItem: Equatable, GeneratedFakeable {
6+
public struct SiteVisitStatsItem: Equatable, GeneratedCopiable, GeneratedFakeable {
77
public let period: String
88
public let visitors: Int
99

WooCommerce/Classes/ViewRelated/Dashboard/Stats v4/StatsTimeRangeBarViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private extension StatsTimeRangeV4 {
6161
}
6262

6363
/// View model for `StatsTimeRangeBarView`.
64-
struct StatsTimeRangeBarViewModel {
64+
struct StatsTimeRangeBarViewModel: Equatable {
6565
let timeRangeText: String
6666

6767
init(startDate: Date,

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
02913E9523A774C500707A0C /* UnitInputFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02913E9423A774C500707A0C /* UnitInputFormatter.swift */; };
268268
02913E9723A774E600707A0C /* DecimalInputFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02913E9623A774E600707A0C /* DecimalInputFormatter.swift */; };
269269
0294F8AB25E8A12C005B537A /* WooTabNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0294F8AA25E8A12C005B537A /* WooTabNavigationController.swift */; };
270+
02952B5127808B08008E9BA3 /* StoreStatsPeriodViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02952B5027808B08008E9BA3 /* StoreStatsPeriodViewModelTests.swift */; };
270271
0295355B245ADF8100BDC42B /* FilterType+Products.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0295355A245ADF8100BDC42B /* FilterType+Products.swift */; };
271272
029700EC24FE38C900D242F8 /* ScrollWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 029700EB24FE38C900D242F8 /* ScrollWatcher.swift */; };
272273
029700EF24FE38F000D242F8 /* ScrollWatcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 029700EE24FE38F000D242F8 /* ScrollWatcherTests.swift */; };
@@ -1845,6 +1846,7 @@
18451846
02913E9423A774C500707A0C /* UnitInputFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitInputFormatter.swift; sourceTree = "<group>"; };
18461847
02913E9623A774E600707A0C /* DecimalInputFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecimalInputFormatter.swift; sourceTree = "<group>"; };
18471848
0294F8AA25E8A12C005B537A /* WooTabNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooTabNavigationController.swift; sourceTree = "<group>"; };
1849+
02952B5027808B08008E9BA3 /* StoreStatsPeriodViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreStatsPeriodViewModelTests.swift; sourceTree = "<group>"; };
18481850
0295355A245ADF8100BDC42B /* FilterType+Products.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FilterType+Products.swift"; sourceTree = "<group>"; };
18491851
029700EB24FE38C900D242F8 /* ScrollWatcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollWatcher.swift; sourceTree = "<group>"; };
18501852
029700EE24FE38F000D242F8 /* ScrollWatcherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollWatcherTests.swift; sourceTree = "<group>"; };
@@ -5009,6 +5011,7 @@
50095011
isa = PBXGroup;
50105012
children = (
50115013
576D9F2824DB81D3007B48F4 /* StoreStatsAndTopPerformersPeriodViewModelTests.swift */,
5014+
02952B5027808B08008E9BA3 /* StoreStatsPeriodViewModelTests.swift */,
50125015
);
50135016
path = "Stats V4";
50145017
sourceTree = "<group>";
@@ -8845,6 +8848,7 @@
88458848
02FE89C7231FAA4100E85EF8 /* MainTabBarControllerTests.swift in Sources */,
88468849
B63AAF4B254AD2C6000B28A2 /* URL+SurveyViewControllerTests.swift in Sources */,
88478850
D802548C26552F41001B2CC1 /* CardPresentModalProcessingTests.swift in Sources */,
8851+
02952B5127808B08008E9BA3 /* StoreStatsPeriodViewModelTests.swift in Sources */,
88488852
B57C5C9F21B80E8300FF82B2 /* SampleError.swift in Sources */,
88498853
02404EE42315151400FF1170 /* MockStatsVersionStoresManager.swift in Sources */,
88508854
02C2756D24F4EEBF00286C04 /* ProductShippingSettingsViewModelTests.swift in Sources */,

0 commit comments

Comments
 (0)