diff --git a/native-route/ios/RSSuper/Services/NotificationManager.swift b/native-route/ios/RSSuper/Services/NotificationManager.swift index c063665..496dfe3 100644 --- a/native-route/ios/RSSuper/Services/NotificationManager.swift +++ b/native-route/ios/RSSuper/Services/NotificationManager.swift @@ -172,8 +172,9 @@ class NotificationManager { } /// Check if notification manager is available - func isAvailable() -> Bool { - return notificationService.isAvailable + /// - Parameter completionHandler: Callback with availability status + func isAvailable(_ completionHandler: @escaping (Bool) -> Void) { + notificationService.isAvailable(completionHandler) } } diff --git a/native-route/ios/RSSuper/Services/NotificationService.swift b/native-route/ios/RSSuper/Services/NotificationService.swift index 47b46f8..e5637fa 100644 --- a/native-route/ios/RSSuper/Services/NotificationService.swift +++ b/native-route/ios/RSSuper/Services/NotificationService.swift @@ -43,14 +43,17 @@ class NotificationService { /// Request notification authorization /// - Parameter context: Application context - private func requestAuthorization(context: Any) throws { + private func requestAuthorization(context: Any) { let options: UNAuthorizationOptions = [.alert, .sound, .badge] - let authorized = try unuserNotifications.requestAuthorization(options: options) - if authorized { - print("Notification authorization authorized") - } else { - print("Notification authorization denied") + unuserNotifications.requestAuthorization(options: options) { authorized, error in + if let error = error { + print("Notification authorization error: \(error)") + } else if authorized { + print("Notification authorization authorized") + } else { + print("Notification authorization denied") + } } } @@ -156,12 +159,11 @@ class NotificationService { } /// Check if notification service is available - var isAvailable: Bool { - var authorized = false + /// - Parameter completionHandler: Callback with authorization status + func isAvailable(_ completionHandler: @escaping (Bool) -> Void) { unuserNotifications.getNotificationSettings { settings in - authorized = settings.authorizationStatus == .authorized + completionHandler(settings.authorizationStatus == .authorized) } - return authorized } /// Get current authorization status diff --git a/native-route/ios/RSSuperTests/SettingsStoreTests.swift b/native-route/ios/RSSuperTests/SettingsStoreTests.swift new file mode 100644 index 0000000..65ef7e3 --- /dev/null +++ b/native-route/ios/RSSuperTests/SettingsStoreTests.swift @@ -0,0 +1,162 @@ +import XCTest +@testable import RSSuper + +class SettingsStoreTests: XCTestCase { + + var settingsStore: SettingsStore! + var appSettings: AppSettings! + + override func setUp() { + super.setUp() + settingsStore = SettingsStore.shared + appSettings = AppSettings.shared + } + + override func tearDown() { + settingsStore = nil + appSettings = nil + super.tearDown() + } + + func testGetFontSize_defaultValue() { + let fontSize = settingsStore.getFontSize() + XCTAssertNotNil(fontSize) + } + + func testSetFontSize() { + let fontSize: ReadingPreferences.FontSize = .large + settingsStore.setFontSize(fontSize) + XCTAssertEqual(settingsStore.getFontSize(), fontSize) + } + + func testGetLineHeight_defaultValue() { + let lineHeight = settingsStore.getLineHeight() + XCTAssertNotNil(lineHeight) + } + + func testSetLineHeight() { + let lineHeight: ReadingPreferences.LineHeight = .tall + settingsStore.setLineHeight(lineHeight) + XCTAssertEqual(settingsStore.getLineHeight(), lineHeight) + } + + func testIsShowTableOfContents_defaultValue() { + let show = settingsStore.isShowTableOfContents() + XCTAssertNotNil(show) + } + + func testSetShowTableOfContents() { + settingsStore.setShowTableOfContents(true) + XCTAssertTrue(settingsStore.isShowTableOfContents()) + } + + func testIsShowReadingTime_defaultValue() { + let show = settingsStore.isShowReadingTime() + XCTAssertNotNil(show) + } + + func testSetShowReadingTime() { + settingsStore.setShowReadingTime(true) + XCTAssertTrue(settingsStore.isShowReadingTime()) + } + + func testIsShowAuthor_defaultValue() { + let show = settingsStore.isShowAuthor() + XCTAssertNotNil(show) + } + + func testSetShowAuthor() { + settingsStore.setShowAuthor(true) + XCTAssertTrue(settingsStore.isShowAuthor()) + } + + func testIsShowDate_defaultValue() { + let show = settingsStore.isShowDate() + XCTAssertNotNil(show) + } + + func testSetShowDate() { + settingsStore.setShowDate(true) + XCTAssertTrue(settingsStore.isShowDate()) + } + + func testIsNewArticlesEnabled_defaultValue() { + let enabled = settingsStore.isNewArticlesEnabled() + XCTAssertNotNil(enabled) + } + + func testSetNewArticles() { + settingsStore.setNewArticles(true) + XCTAssertTrue(settingsStore.isNewArticlesEnabled()) + } + + func testIsEpisodeReleasesEnabled_defaultValue() { + let enabled = settingsStore.isEpisodeReleasesEnabled() + XCTAssertNotNil(enabled) + } + + func testSetEpisodeReleases() { + settingsStore.setEpisodeReleases(true) + XCTAssertTrue(settingsStore.isEpisodeReleasesEnabled()) + } + + func testIsCustomAlertsEnabled_defaultValue() { + let enabled = settingsStore.isCustomAlertsEnabled() + XCTAssertNotNil(enabled) + } + + func testSetCustomAlerts() { + settingsStore.setCustomAlerts(true) + XCTAssertTrue(settingsStore.isCustomAlertsEnabled()) + } + + func testIsBadgeCountEnabled_defaultValue() { + let enabled = settingsStore.isBadgeCountEnabled() + XCTAssertNotNil(enabled) + } + + func testSetBadgeCount() { + settingsStore.setBadgeCount(true) + XCTAssertTrue(settingsStore.isBadgeCountEnabled()) + } + + func testIsSoundEnabled_defaultValue() { + let enabled = settingsStore.isSoundEnabled() + XCTAssertNotNil(enabled) + } + + func testSetSound() { + settingsStore.setSound(true) + XCTAssertTrue(settingsStore.isSoundEnabled()) + } + + func testIsVibrationEnabled_defaultValue() { + let enabled = settingsStore.isVibrationEnabled() + XCTAssertNotNil(enabled) + } + + func testSetVibration() { + settingsStore.setVibration(true) + XCTAssertTrue(settingsStore.isVibrationEnabled()) + } + + func testIsAppGroupAvailable() { + let available = settingsStore.isAppGroupAvailable() + XCTAssertNotNil(available) + } + + func testGetReadingPreferences() { + let prefs = settingsStore.getReadingPreferences() + XCTAssertNotNil(prefs) + } + + func testGetNotificationPreferences() { + let prefs = settingsStore.getNotificationPreferences() + XCTAssertNotNil(prefs) + } + + func testGetAllPreferences() { + let prefs = settingsStore.getAllPreferences() + XCTAssertNotNil(prefs) + } +}