-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Insight
differenceLabel
localization logic (#19473)
- Loading branch information
Showing
4 changed files
with
70 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
WordPress/WordPressTest/StatsSegmentedControlDataTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Nimble | ||
import XCTest | ||
@testable import WordPress | ||
|
||
class StatsSegmentedControlDataTests: XCTestCase { | ||
|
||
func testDifferenceLabel() { | ||
expect(StatsSegmentedControlData.fixture(difference: -12_345, differencePercent: -1).differenceLabel) | ||
== "-12.3K (-1%)" | ||
expect(StatsSegmentedControlData.fixture(difference: -12_345, differencePercent: 0).differenceLabel) | ||
== "-12.3K" | ||
expect(StatsSegmentedControlData.fixture(difference: -12_345, differencePercent: 1).differenceLabel) | ||
== "-12.3K (1%)" | ||
expect(StatsSegmentedControlData.fixture(difference: 0, differencePercent: -1).differenceLabel) | ||
== "0 (-1%)" | ||
expect(StatsSegmentedControlData.fixture(difference: 0, differencePercent: 0).differenceLabel) | ||
== "0" | ||
expect(StatsSegmentedControlData.fixture(difference: 0, differencePercent: 1).differenceLabel) | ||
== "0 (1%)" | ||
expect(StatsSegmentedControlData.fixture(difference: 12_345, differencePercent: -1).differenceLabel) | ||
== "+12.3K (-1%)" | ||
expect(StatsSegmentedControlData.fixture(difference: 12_345, differencePercent: 0).differenceLabel) | ||
== "+12.3K" | ||
expect(StatsSegmentedControlData.fixture(difference: 12_345, differencePercent: 1).differenceLabel) | ||
== "+12.3K (1%)" | ||
} | ||
} | ||
|
||
extension StatsSegmentedControlData { | ||
|
||
static func fixture( | ||
segmentTitle: String = "title", | ||
segmentData: Int = 0, | ||
segmentPrevData: Int = 1, | ||
difference: Int = 2, | ||
differenceText: String = "text", | ||
differencePercent: Int = 3 | ||
) -> StatsSegmentedControlData { | ||
StatsSegmentedControlData( | ||
segmentTitle: segmentTitle, | ||
segmentData: segmentData, | ||
segmentPrevData: segmentPrevData, | ||
difference: difference, | ||
differenceText: differenceText, | ||
differencePercent: differencePercent | ||
) | ||
} | ||
} |