1.1.0 feature work: Monthly Check-in, Charts, Goals, Share, Reviews
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import XCTest
|
||||
@testable import PortfolioJournal
|
||||
|
||||
@MainActor
|
||||
final class ChartsViewModelDisplayRulesTests: XCTestCase {
|
||||
func testAllocationTargetsSupportedOnlyForCategoryBreakdown() {
|
||||
XCTAssertTrue(ChartsViewModel.supportsAllocationTargets(for: .category))
|
||||
XCTAssertFalse(ChartsViewModel.supportsAllocationTargets(for: .source))
|
||||
}
|
||||
|
||||
func testEvolutionTimeRangesIncludeRequestedOptions() {
|
||||
let viewModel = ChartsViewModel(iapService: IAPService())
|
||||
let ranges = viewModel.availableTimeRanges(for: .evolution)
|
||||
|
||||
XCTAssertEqual(ranges, [.all, .yearToDate, .year, .quarter])
|
||||
}
|
||||
|
||||
func testYearToDateRangeStartsAtBeginningOfYear() {
|
||||
let calendar = Calendar(identifier: .gregorian)
|
||||
let referenceDate = calendar.date(from: DateComponents(year: 2026, month: 8, day: 15))!
|
||||
let startDate = ChartsViewModel.TimeRange.yearToDate.startDate(referenceDate: referenceDate)
|
||||
let expected = calendar.date(from: DateComponents(year: 2026, month: 1, day: 1))!
|
||||
|
||||
XCTAssertEqual(startDate, expected)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import XCTest
|
||||
@testable import PortfolioJournal
|
||||
|
||||
@MainActor
|
||||
final class GoalsDisplayRulesTests: XCTestCase {
|
||||
func testIsAchievedProgressThreshold() {
|
||||
XCTAssertFalse(GoalsViewModel.isAchieved(progress: 0.998))
|
||||
XCTAssertTrue(GoalsViewModel.isAchieved(progress: 0.999))
|
||||
XCTAssertTrue(GoalsViewModel.isAchieved(progress: 1.0))
|
||||
}
|
||||
|
||||
func testUrgencyLevelIsCriticalWhenBehindAndPastTargetDate() {
|
||||
let targetDate = Date(timeIntervalSince1970: 1_000_000)
|
||||
let referenceDate = Date(timeIntervalSince1970: 1_100_000)
|
||||
|
||||
let level = GoalsViewModel.urgencyLevel(
|
||||
targetDate: targetDate,
|
||||
isBehind: true,
|
||||
isAchieved: false,
|
||||
referenceDate: referenceDate
|
||||
)
|
||||
|
||||
XCTAssertEqual(level, .critical)
|
||||
}
|
||||
|
||||
func testUrgencyLevelIsWarningWhenBehindBeforeTargetDate() {
|
||||
let targetDate = Date(timeIntervalSince1970: 1_100_000)
|
||||
let referenceDate = Date(timeIntervalSince1970: 1_000_000)
|
||||
|
||||
let level = GoalsViewModel.urgencyLevel(
|
||||
targetDate: targetDate,
|
||||
isBehind: true,
|
||||
isAchieved: false,
|
||||
referenceDate: referenceDate
|
||||
)
|
||||
|
||||
XCTAssertEqual(level, .warning)
|
||||
}
|
||||
|
||||
func testUrgencyLevelIsNormalForAchievedGoals() {
|
||||
let level = GoalsViewModel.urgencyLevel(
|
||||
targetDate: Date(),
|
||||
isBehind: true,
|
||||
isAchieved: true,
|
||||
referenceDate: Date().addingTimeInterval(86_400)
|
||||
)
|
||||
|
||||
XCTAssertEqual(level, .normal)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user