|
|
@ -5,7 +5,8 @@ import XCTest |
|
|
|
|
|
|
|
|
|
|
|
class ReviewControllerTests: XCTestCase { |
|
|
|
class ReviewControllerTests: XCTestCase { |
|
|
|
func testDebuggingMode() throws { |
|
|
|
func testDebuggingMode() throws { |
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker") else { |
|
|
|
let mockSuite = "com.test.Clocker.\(randomLetter())" |
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: mockSuite) else { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
ReviewController.applicationDidLaunch(mockDefaults) |
|
|
|
ReviewController.applicationDidLaunch(mockDefaults) |
|
|
@ -15,10 +16,12 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
|
|
ReviewController.setPreviewMode(true) |
|
|
|
ReviewController.setPreviewMode(true) |
|
|
|
XCTAssertTrue(ReviewController.canPrompt()) |
|
|
|
XCTAssertTrue(ReviewController.canPrompt()) |
|
|
|
|
|
|
|
mockDefaults.removeSuite(named: mockSuite) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testPromptNotDisplayedInFirstWeekSinceInstall() { |
|
|
|
func testPromptNotDisplayedInFirstWeekSinceInstall() { |
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker1") else { |
|
|
|
let mockSuite = "com.test.Clocker1.\(randomLetter())" |
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: mockSuite) else { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
// Set key install time |
|
|
|
// Set key install time |
|
|
@ -27,6 +30,7 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
ReviewController.setPreviewMode(false) |
|
|
|
ReviewController.setPreviewMode(false) |
|
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(ReviewController.canPrompt()) |
|
|
|
XCTAssertFalse(ReviewController.canPrompt()) |
|
|
|
|
|
|
|
mockDefaults.removeSuite(named: mockSuite) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testPrompDisplayedAfterFirstWeekOfInstall() { |
|
|
|
func testPrompDisplayedAfterFirstWeekOfInstall() { |
|
|
@ -38,8 +42,8 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
months: 0, |
|
|
|
months: 0, |
|
|
|
years: 0) |
|
|
|
years: 0) |
|
|
|
let oldDate = Date().subtract(dateChunk) |
|
|
|
let oldDate = Date().subtract(dateChunk) |
|
|
|
|
|
|
|
let mockSuite = "com.test.Clocker2.\(randomLetter())" |
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker2") else { |
|
|
|
guard let mockDefaults = UserDefaults(suiteName: mockSuite) else { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
mockDefaults.set(oldDate, forKey: "install") |
|
|
|
mockDefaults.set(oldDate, forKey: "install") |
|
|
@ -51,6 +55,7 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
XCTAssertNil(mockDefaults.object(forKey: "last-prompt")) |
|
|
|
XCTAssertNil(mockDefaults.object(forKey: "last-prompt")) |
|
|
|
XCTAssertNil(mockDefaults.object(forKey: "last-version")) |
|
|
|
XCTAssertNil(mockDefaults.object(forKey: "last-version")) |
|
|
|
XCTAssertTrue(ReviewController.canPrompt()) |
|
|
|
XCTAssertTrue(ReviewController.canPrompt()) |
|
|
|
|
|
|
|
mockDefaults.removeSuite(named: mockSuite) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testPromptDisplayAfterTwoMonths() { |
|
|
|
func testPromptDisplayAfterTwoMonths() { |
|
|
@ -72,7 +77,8 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
years: 0) |
|
|
|
years: 0) |
|
|
|
let lastPromptDate = Date().subtract(promptChunk) |
|
|
|
let lastPromptDate = Date().subtract(promptChunk) |
|
|
|
|
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker3") else { |
|
|
|
let mockSuite = "com.test.Clocker3.\(randomLetter())" |
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: mockSuite) else { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
mockDefaults.set(minInstall, forKey: "install") |
|
|
|
mockDefaults.set(minInstall, forKey: "install") |
|
|
@ -83,6 +89,7 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
// Explicitly set preview mode to false |
|
|
|
// Explicitly set preview mode to false |
|
|
|
ReviewController.setPreviewMode(false) |
|
|
|
ReviewController.setPreviewMode(false) |
|
|
|
XCTAssertFalse(ReviewController.canPrompt()) |
|
|
|
XCTAssertFalse(ReviewController.canPrompt()) |
|
|
|
|
|
|
|
mockDefaults.removeSuite(named: mockSuite) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testPrompDisplayedAfterThreeMonths() { |
|
|
|
func testPrompDisplayedAfterThreeMonths() { |
|
|
@ -104,7 +111,8 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
years: 0) |
|
|
|
years: 0) |
|
|
|
let lastPromptDate = Date().subtract(promptChunk) |
|
|
|
let lastPromptDate = Date().subtract(promptChunk) |
|
|
|
|
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker4") else { |
|
|
|
let mockSuite = "com.test.Clocker4.\(randomLetter())" |
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: mockSuite) else { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
mockDefaults.set(minInstall, forKey: "install") |
|
|
|
mockDefaults.set(minInstall, forKey: "install") |
|
|
@ -118,15 +126,23 @@ class ReviewControllerTests: XCTestCase { |
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey: "last-prompt")) |
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey: "last-prompt")) |
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey: "last-version")) |
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey: "last-version")) |
|
|
|
XCTAssertTrue(ReviewController.canPrompt()) |
|
|
|
XCTAssertTrue(ReviewController.canPrompt()) |
|
|
|
|
|
|
|
mockDefaults.removeSuite(named: mockSuite) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testPrompted() { |
|
|
|
func testPrompted() { |
|
|
|
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker5") else { |
|
|
|
let mockSuite = "com.test.Clocker5.\(randomLetter())" |
|
|
|
|
|
|
|
guard let mockDefaults = UserDefaults(suiteName: mockSuite) else { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
ReviewController.applicationDidLaunch(mockDefaults) |
|
|
|
ReviewController.applicationDidLaunch(mockDefaults) |
|
|
|
ReviewController.prompt() |
|
|
|
ReviewController.prompt() |
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey: "last-prompt")) |
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey: "last-prompt")) |
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey: "last-version")) |
|
|
|
XCTAssertNotNil(mockDefaults.object(forKey: "last-version")) |
|
|
|
|
|
|
|
mockDefaults.removeSuite(named: mockSuite) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func randomLetter() -> String { |
|
|
|
|
|
|
|
let alphabet: [String] = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] |
|
|
|
|
|
|
|
return alphabet[Int(arc4random_uniform(26))] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|