Browse Source

Update ReviewControllerTests.swift

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
5c64797cfc
  1. 52
      Clocker/ClockerUnitTests/ReviewControllerTests.swift

52
Clocker/ClockerUnitTests/ReviewControllerTests.swift

@ -18,7 +18,7 @@ class ReviewControllerTests: XCTestCase {
}
func testPromptNotDisplayedInFirstWeekSinceInstall() {
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker") else {
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker1") else {
return
}
// Set key install time
@ -33,16 +33,17 @@ class ReviewControllerTests: XCTestCase {
let dateChunk = TimeChunk(seconds: 0,
minutes: 0,
hours: 0,
days: -7,
days: 8,
weeks: 0,
months: 0,
years: 0)
let oldDate = Date().subtract(dateChunk)
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker") else {
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker2") else {
return
}
mockDefaults.set(oldDate, forKey: "install")
ReviewController.applicationDidLaunch(mockDefaults)
// Explicitly set preview mode to false
ReviewController.setPreviewMode(false)
@ -52,4 +53,49 @@ class ReviewControllerTests: XCTestCase {
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"))
}
}

Loading…
Cancel
Save