|
|
@ -18,7 +18,7 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testPromptNotDisplayedInFirstWeekSinceInstall() { |
|
|
|
func testPromptNotDisplayedInFirstWeekSinceInstall() { |
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker") else { |
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker1") else { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
// Set key install time |
|
|
|
// Set key install time |
|
|
@ -33,16 +33,17 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
let dateChunk = TimeChunk(seconds: 0, |
|
|
|
let dateChunk = TimeChunk(seconds: 0, |
|
|
|
minutes: 0, |
|
|
|
minutes: 0, |
|
|
|
hours: 0, |
|
|
|
hours: 0, |
|
|
|
days: -7, |
|
|
|
days: 8, |
|
|
|
weeks: 0, |
|
|
|
weeks: 0, |
|
|
|
months: 0, |
|
|
|
months: 0, |
|
|
|
years: 0) |
|
|
|
years: 0) |
|
|
|
let oldDate = Date().subtract(dateChunk) |
|
|
|
let oldDate = Date().subtract(dateChunk) |
|
|
|
|
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker") else { |
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker2") else { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
mockDefaults.set(oldDate, forKey: "install") |
|
|
|
mockDefaults.set(oldDate, forKey: "install") |
|
|
|
|
|
|
|
ReviewController.applicationDidLaunch(mockDefaults) |
|
|
|
|
|
|
|
|
|
|
|
// Explicitly set preview mode to false |
|
|
|
// Explicitly set preview mode to false |
|
|
|
ReviewController.setPreviewMode(false) |
|
|
|
ReviewController.setPreviewMode(false) |
|
|
@ -51,5 +52,50 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
XCTAssertNil(mockDefaults.object(forKey:"last-version")) |
|
|
|
XCTAssertNil(mockDefaults.object(forKey:"last-version")) |
|
|
|
XCTAssertTrue(ReviewController.canPrompt()) |
|
|
|
XCTAssertTrue(ReviewController.canPrompt()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func testPrompDisplayedAfterThreeMonths() { |
|
|
|
|
|
|
|
let dateChunk = TimeChunk(seconds: 0, |
|
|
|
|
|
|
|
minutes: 0, |
|
|
|
|
|
|
|
hours: 0, |
|
|
|
|
|
|
|
days: 98, |
|
|
|
|
|
|
|
weeks: 0, |
|
|
|
|
|
|
|
months: 0, |
|
|
|
|
|
|
|
years: 0) |
|
|
|
|
|
|
|
let minInstall = Date().subtract(dateChunk) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let promptChunk = TimeChunk(seconds: 0, |
|
|
|
|
|
|
|
minutes: 0, |
|
|
|
|
|
|
|
hours: 0, |
|
|
|
|
|
|
|
days: 91, |
|
|
|
|
|
|
|
weeks: 0, |
|
|
|
|
|
|
|
months: 0, |
|
|
|
|
|
|
|
years: 0) |
|
|
|
|
|
|
|
let lastPromptDate = Date().subtract(promptChunk) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker3") else { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mockDefaults.set(minInstall, forKey: "install") |
|
|
|
|
|
|
|
mockDefaults.set("test-version", forKey: "last-version") |
|
|
|
|
|
|
|
mockDefaults.set(lastPromptDate, forKey: "last-prompt") |
|
|
|
|
|
|
|
ReviewController.applicationDidLaunch(mockDefaults) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Explicitly set preview mode to false |
|
|
|
|
|
|
|
ReviewController.setPreviewMode(false) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey:"last-prompt")) |
|
|
|
|
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey:"last-version")) |
|
|
|
|
|
|
|
XCTAssertTrue(ReviewController.canPrompt()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func testPrompted() { |
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker4") else { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ReviewController.applicationDidLaunch(mockDefaults) |
|
|
|
|
|
|
|
ReviewController.prompt() |
|
|
|
|
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey:"last-prompt")) |
|
|
|
|
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey:"last-version")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|