You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/SessionTests/Settings/NotificationContentViewMode...

164 lines
7.0 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Combine
import GRDB
import Quick
import Nimble
@testable import Session
class NotificationContentViewModelSpec: QuickSpec {
// MARK: - Spec
override func spec() {
var mockStorage: Storage!
var dataChangeCancellable: AnyCancellable?
var dismissCancellable: AnyCancellable?
var viewModel: NotificationContentViewModel!
describe("a NotificationContentViewModel") {
// MARK: - Configuration
beforeEach {
mockStorage = Storage(
customWriter: try! DatabaseQueue(),
customMigrations: [
SNUtilitiesKit.migrations(),
SNSnodeKit.migrations(),
SNMessagingKit.migrations(),
SNUIKit.migrations()
]
)
viewModel = NotificationContentViewModel(storage: mockStorage, scheduling: .immediate)
dataChangeCancellable = viewModel.observableTableData
Fixed a number of issues found during internal testing Added copy for an unrecoverable startup case Added some additional logs to better debug ValueObservation query errors Increased the pageSize to 20 on iPad devices (to prevent it immediately loading a second page) Cleaned up a bunch of threading logic (try to avoid overriding subscribe/receive threads specified at subscription) Consolidated the 'sendMessage' and 'sendAttachments' functions Updated the various frameworks to use 'DAWRF with DSYM' to allow for better debugging during debug mode (at the cost of a longer build time) Updated the logic to optimistically insert messages when sending to avoid any database write delays Updated the logic to avoid sending notifications for messages which are already marked as read by the config Fixed an issue where multiple paths could incorrectly get built at the same time in some cases Fixed an issue where other job queues could be started before the blockingQueue finishes Fixed a potential bug with the snode version comparison (was just a string comparison which would fail when getting to double-digit values) Fixed a bug where you couldn't remove the last reaction on a message Fixed the broken media message zoom animations Fixed a bug where the last message read in a conversation wouldn't be correctly detected as already read Fixed a bug where the QuoteView had no line limits (resulting in the '@You' mention background highlight being incorrectly positioned in the quote preview) Fixed a bug where a large number of configSyncJobs could be scheduled (only one would run at a time but this could result in performance impacts)
1 year ago
.receive(on: DispatchQueue.main, immediatelyIfMain: true)
.sink(
receiveCompletion: { _ in },
receiveValue: { viewModel.updateTableData($0.0) }
)
}
afterEach {
dataChangeCancellable?.cancel()
dismissCancellable?.cancel()
mockStorage = nil
dataChangeCancellable = nil
dismissCancellable = nil
viewModel = nil
}
// MARK: - Basic Tests
it("has the correct title") {
expect(viewModel.title).to(equal("NOTIFICATIONS_STYLE_CONTENT_TITLE".localized()))
}
it("has the correct number of items") {
expect(viewModel.tableData.count)
.to(equal(1))
expect(viewModel.tableData.first?.elements.count)
.to(equal(3))
}
it("has the correct default state") {
expect(viewModel.tableData.first?.elements)
.to(
equal([
SessionCell.Info(
id: Preferences.NotificationPreviewType.nameAndPreview,
position: .top,
title: "NOTIFICATIONS_STYLE_CONTENT_OPTION_NAME_AND_CONTENT".localized(),
rightAccessory: .radio(
isSelected: { true }
)
),
SessionCell.Info(
id: Preferences.NotificationPreviewType.nameNoPreview,
position: .middle,
title: "NOTIFICATIONS_STYLE_CONTENT_OPTION_NAME_ONLY".localized(),
rightAccessory: .radio(
isSelected: { false }
)
),
SessionCell.Info(
id: Preferences.NotificationPreviewType.noNameNoPreview,
position: .bottom,
title: "NOTIFICATIONS_STYLE_CONTENT_OPTION_NO_NAME_OR_CONTENT".localized(),
rightAccessory: .radio(
isSelected: { false }
)
)
])
)
}
it("starts with the correct item active if not default") {
mockStorage.write { db in
db[.preferencesNotificationPreviewType] = Preferences.NotificationPreviewType.nameNoPreview
}
viewModel = NotificationContentViewModel(storage: mockStorage, scheduling: .immediate)
dataChangeCancellable = viewModel.observableTableData
Fixed a number of issues found during internal testing Added copy for an unrecoverable startup case Added some additional logs to better debug ValueObservation query errors Increased the pageSize to 20 on iPad devices (to prevent it immediately loading a second page) Cleaned up a bunch of threading logic (try to avoid overriding subscribe/receive threads specified at subscription) Consolidated the 'sendMessage' and 'sendAttachments' functions Updated the various frameworks to use 'DAWRF with DSYM' to allow for better debugging during debug mode (at the cost of a longer build time) Updated the logic to optimistically insert messages when sending to avoid any database write delays Updated the logic to avoid sending notifications for messages which are already marked as read by the config Fixed an issue where multiple paths could incorrectly get built at the same time in some cases Fixed an issue where other job queues could be started before the blockingQueue finishes Fixed a potential bug with the snode version comparison (was just a string comparison which would fail when getting to double-digit values) Fixed a bug where you couldn't remove the last reaction on a message Fixed the broken media message zoom animations Fixed a bug where the last message read in a conversation wouldn't be correctly detected as already read Fixed a bug where the QuoteView had no line limits (resulting in the '@You' mention background highlight being incorrectly positioned in the quote preview) Fixed a bug where a large number of configSyncJobs could be scheduled (only one would run at a time but this could result in performance impacts)
1 year ago
.receive(on: DispatchQueue.main, immediatelyIfMain: true)
.sink(
receiveCompletion: { _ in },
receiveValue: { viewModel.updateTableData($0.0) }
)
expect(viewModel.tableData.first?.elements)
.to(
equal([
SessionCell.Info(
id: Preferences.NotificationPreviewType.nameAndPreview,
position: .top,
title: "NOTIFICATIONS_STYLE_CONTENT_OPTION_NAME_AND_CONTENT".localized(),
rightAccessory: .radio(
isSelected: { false }
)
),
SessionCell.Info(
id: Preferences.NotificationPreviewType.nameNoPreview,
position: .middle,
title: "NOTIFICATIONS_STYLE_CONTENT_OPTION_NAME_ONLY".localized(),
rightAccessory: .radio(
isSelected: { true }
)
),
SessionCell.Info(
id: Preferences.NotificationPreviewType.noNameNoPreview,
position: .bottom,
title: "NOTIFICATIONS_STYLE_CONTENT_OPTION_NO_NAME_OR_CONTENT".localized(),
rightAccessory: .radio(
isSelected: { false }
)
)
])
)
}
context("when tapping an item") {
it("updates the saved preference") {
viewModel.tableData.first?.elements.last?.onTap?()
expect(mockStorage[.preferencesNotificationPreviewType])
.to(equal(Preferences.NotificationPreviewType.noNameNoPreview))
}
it("dismisses the screen") {
var didDismissScreen: Bool = false
dismissCancellable = viewModel.dismissScreen
Fixed a number of issues found during internal testing Added copy for an unrecoverable startup case Added some additional logs to better debug ValueObservation query errors Increased the pageSize to 20 on iPad devices (to prevent it immediately loading a second page) Cleaned up a bunch of threading logic (try to avoid overriding subscribe/receive threads specified at subscription) Consolidated the 'sendMessage' and 'sendAttachments' functions Updated the various frameworks to use 'DAWRF with DSYM' to allow for better debugging during debug mode (at the cost of a longer build time) Updated the logic to optimistically insert messages when sending to avoid any database write delays Updated the logic to avoid sending notifications for messages which are already marked as read by the config Fixed an issue where multiple paths could incorrectly get built at the same time in some cases Fixed an issue where other job queues could be started before the blockingQueue finishes Fixed a potential bug with the snode version comparison (was just a string comparison which would fail when getting to double-digit values) Fixed a bug where you couldn't remove the last reaction on a message Fixed the broken media message zoom animations Fixed a bug where the last message read in a conversation wouldn't be correctly detected as already read Fixed a bug where the QuoteView had no line limits (resulting in the '@You' mention background highlight being incorrectly positioned in the quote preview) Fixed a bug where a large number of configSyncJobs could be scheduled (only one would run at a time but this could result in performance impacts)
1 year ago
.receive(on: DispatchQueue.main, immediatelyIfMain: true)
.sink(
receiveCompletion: { _ in },
receiveValue: { _ in didDismissScreen = true }
)
viewModel.tableData.first?.elements.last?.onTap?()
expect(didDismissScreen).to(beTrue())
}
}
}
}
}