Skip to content

Commit

Permalink
Apply change requests
Browse files Browse the repository at this point in the history
  • Loading branch information
alpavanoglu committed Jul 7, 2023
1 parent 4dec92e commit 7570461
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private extension CompliancePopoverCoordinator {
extension UserDefaults {
static let didShowCompliancePopupKey = "didShowCompliancePopup"

@objc var didShowCompliancePopup: Bool {
var didShowCompliancePopup: Bool {
get {
bool(forKey: Self.didShowCompliancePopupKey)
} set {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class CompliancePopoverViewModel: ObservableObject {
appAnalytics?.setUserHasOptedOut(!isAnalyticsEnabled)

let (accountID, restAPI) = contextManager.performQuery { context -> (NSNumber?, WordPressComRestApi?) in
let account = try? WPAccount.lookupDefaultWordPressComAccount(in: context)
let account = try? WPAccount.lookupDefaultWordPressComAccount(in: context)
return (account?.userID, account?.wordPressComRestApi)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,50 @@ final class CompliancePopoverViewModelTests: CoreDataTestCase {
testDefaults?.removeObject(forKey: UserDefaults.didShowCompliancePopupKey)
}

func testDidTapSettingsUpdatesDefaults() {
guard let defaults = try? XCTUnwrap(testDefaults) else {
return
}
func testDidTapSettingsUpdatesDefaults() throws {
let defaults = try XCTUnwrap(testDefaults)
let sut = CompliancePopoverViewModel(defaults: defaults, contextManager: contextManager)
sut.didTapSettings()
XCTAssert(defaults.didShowCompliancePopup)
}

func testDidTapSettingsInvokesCoordinatorNavigation() {
guard let defaults = try? XCTUnwrap(testDefaults) else {
return
}
func testDidTapSettingsInvokesCoordinatorNavigation() throws {
let defaults = try XCTUnwrap(testDefaults)
let mockCoordinator = MockCompliancePopoverCoordinator()
let sut = CompliancePopoverViewModel(defaults: defaults, contextManager: contextManager)
sut.coordinator = mockCoordinator
sut.didTapSettings()
XCTAssertEqual(mockCoordinator.navigateToSettingsCallCount, 1)
}

func testDidTapSaveInvokesDismissWhenAccountIDExists() {
guard let defaults = try? XCTUnwrap(testDefaults) else {
return
}
func testDidTapSaveInvokesDismissWhenAccountIDExists() throws {
let defaults = try XCTUnwrap(testDefaults)
let mockCoordinator = MockCompliancePopoverCoordinator()
UserSettings.defaultDotComUUID = account().uuid
let sut = CompliancePopoverViewModel(
defaults: defaults,
contextManager: makeCoreDataStack()
contextManager: contextManager
)
sut.coordinator = mockCoordinator
sut.didTapSave()
XCTAssertEqual(mockCoordinator.dismissCallCount, 1)
XCTAssert(defaults.didShowCompliancePopup)
}

private func makeCoreDataStack() -> ContextManager {
let contextManager = ContextManager.forTesting()
let account = AccountBuilder(contextManager)
private func account() -> WPAccount {
return AccountBuilder(contextManager)
.with(id: 1229)
.with(username: "foobar")
.with(email: "[email protected]")
.with(authToken: "9384rj398t34j98")
.build()
UserSettings.defaultDotComUUID = account.uuid
return contextManager
}
}

private class MockCompliancePopoverCoordinator: CompliancePopoverCoordinatorProtocol {
var navigateToSettingsCallCount = 0
var presentIfNeededCallCount = 0
var dismissCallCount = 0
private(set) var navigateToSettingsCallCount = 0
private(set) var presentIfNeededCallCount = 0
private(set) var dismissCallCount = 0

func presentIfNeeded() {
presentIfNeededCallCount += 1
Expand Down

0 comments on commit 7570461

Please sign in to comment.