refactor on accessibility of SessionButton.Info, and fix some unit tests on disappearing messages config

pull/941/head
ryanzhao 2 years ago
parent 71f96058f1
commit 32d7dd2ea6

@ -105,8 +105,10 @@ class ThreadDisappearingMessagesSettingsViewModel: SessionTableViewModel<ThreadD
style: .bordered, style: .bordered,
title: "DISAPPERING_MESSAGES_SAVE_TITLE".localized(), title: "DISAPPERING_MESSAGES_SAVE_TITLE".localized(),
isEnabled: true, isEnabled: true,
accessibilityIdentifier: "Set button", accessibility: Accessibility(
accessibilityLabel: "Set button", identifier: "Set button",
label: "Set button"
),
minWidth: 110, minWidth: 110,
onTap: { onTap: {
self?.saveChanges() self?.saveChanges()
@ -515,8 +517,10 @@ class ThreadDisappearingMessagesSettingsViewModel: SessionTableViewModel<ThreadD
threadId: threadId, threadId: threadId,
threadVariant: threadVariant threadVariant: threadVariant
) )
}
// Contacts & legacy closed groups need to update the SessionUtil
// Contacts & legacy closed groups need to update the SessionUtil
dependencies.storage.writeAsync { db in
switch threadVariant { switch threadVariant {
case .contact: case .contact:
try SessionUtil try SessionUtil

@ -398,8 +398,8 @@ class SessionTableViewController<NavItemId: Equatable, Section: SessionTableSect
self?.footerButton.setStyle(buttonInfo.style) self?.footerButton.setStyle(buttonInfo.style)
self?.footerButton.isEnabled = buttonInfo.isEnabled self?.footerButton.isEnabled = buttonInfo.isEnabled
self?.footerButton.set(.width, greaterThanOrEqualTo: buttonInfo.minWidth) self?.footerButton.set(.width, greaterThanOrEqualTo: buttonInfo.minWidth)
self?.footerButton.accessibilityIdentifier = buttonInfo.accessibilityIdentifier self?.footerButton.accessibilityIdentifier = buttonInfo.accessibility?.identifier
self?.footerButton.accessibilityLabel = buttonInfo.accessibilityLabel self?.footerButton.accessibilityLabel = buttonInfo.accessibility?.label
} }
self?.onFooterTap = buttonInfo?.onTap self?.onFooterTap = buttonInfo?.onTap

@ -200,6 +200,7 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
id: ThreadDisappearingMessagesSettingsViewModel.Item( id: ThreadDisappearingMessagesSettingsViewModel.Item(
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized() title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized()
), ),
position: .bottom,
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized(), title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized(),
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_DESCRIPTION".localized(), subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_DESCRIPTION".localized(),
rightAccessory: .radio( rightAccessory: .radio(
@ -216,7 +217,7 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
let title: String = (DisappearingMessagesConfiguration.validDurationsSeconds(.disappearAfterSend).last? let title: String = (DisappearingMessagesConfiguration.validDurationsSeconds(.disappearAfterSend).last?
.formatted(format: .long)) .formatted(format: .long))
.defaulting(to: "") .defaulting(to: "")
expect(viewModel.tableData.first?.elements.last) expect(viewModel.tableData.last?.elements.last)
.to( .to(
equal( equal(
SessionCell.Info( SessionCell.Info(
@ -233,72 +234,99 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
) )
) )
) )
}
it("has no footer button") {
var footerButtonInfo: SessionButton.Info?
context("change to another setting and change back") { cancellables.append(
// Change to another setting viewModel.footerButtonInfo
viewModel.tableData.first?.elements.first?.onTap?() .receiveOnMain(immediately: true)
// Change back .sink(
viewModel.tableData.first?.elements.last?.onTap?() receiveCompletion: { _ in },
receiveValue: { info in footerButtonInfo = info }
it("shows the previous setting with no set button") { )
expect(viewModel.tableData.first?.elements.last) )
.to(
equal( expect(footerButtonInfo).to(beNil())
SessionCell.Info( }
id: ThreadDisappearingMessagesSettingsViewModel.Item(
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized() it("change to another setting and change back") {
), // Test config: Disappear After Send - 2 weeks
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized(), let config: DisappearingMessagesConfiguration = DisappearingMessagesConfiguration
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_DESCRIPTION".localized(), .defaultWith("TestId")
rightAccessory: .radio( .with(
isSelected: { true } isEnabled: true,
), durationSeconds: DisappearingMessagesConfiguration.validDurationsSeconds(.disappearAfterSend).last,
accessibility: Accessibility( type: .disappearAfterSend
identifier: "Disappear after send option", )
label: "Disappear after send option" mockStorage.write { db in
) _ = try config.saved(db)
) }
viewModel = ThreadDisappearingMessagesSettingsViewModel(
dependencies: dependencies,
threadId: "TestId",
threadVariant: .contact,
currentUserIsClosedGroupMember: nil,
currentUserIsClosedGroupAdmin: nil,
config: config
)
cancellables.append(
viewModel.observableTableData
.receiveOnMain(immediately: true)
.sink(
receiveCompletion: { _ in },
receiveValue: { viewModel.updateTableData($0.0) }
)
)
// Change to another setting
viewModel.tableData.first?.elements.first?.onTap?()
// Change back
viewModel.tableData.first?.elements.last?.onTap?()
expect(viewModel.tableData.first?.elements.last)
.to(
equal(
SessionCell.Info(
id: ThreadDisappearingMessagesSettingsViewModel.Item(
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized()
),
position: .bottom,
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized(),
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_DESCRIPTION".localized(),
rightAccessory: .radio(
isSelected: { true }
),
accessibility: Accessibility(
identifier: "Disappear after send option",
label: "Disappear after send option"
) )
) )
)
let title: String = (DisappearingMessagesConfiguration.validDurationsSeconds(.disappearAfterSend).last? )
.formatted(format: .long))
.defaulting(to: "") let title: String = (DisappearingMessagesConfiguration.validDurationsSeconds(.disappearAfterSend).last?
expect(viewModel.tableData.first?.elements.last) .formatted(format: .long))
.to( .defaulting(to: "")
equal( expect(viewModel.tableData.last?.elements.last)
SessionCell.Info( .to(
id: ThreadDisappearingMessagesSettingsViewModel.Item(title: title), equal(
position: .bottom, SessionCell.Info(
title: title, id: ThreadDisappearingMessagesSettingsViewModel.Item(title: title),
rightAccessory: .radio( position: .bottom,
isSelected: { true } title: title,
), rightAccessory: .radio(
accessibility: Accessibility( isSelected: { true }
identifier: "Time option", ),
label: "Time option" accessibility: Accessibility(
) identifier: "Time option",
) label: "Time option"
) )
) )
var footerButtonInfo: SessionButton.Info?
cancellables.append(
viewModel.footerButtonInfo
.receiveOnMain(immediately: true)
.sink(
receiveCompletion: { _ in },
receiveValue: { info in footerButtonInfo = info }
)
) )
)
expect(footerButtonInfo).to(beNil())
}
}
}
it("has no footer button") {
var footerButtonInfo: SessionButton.Info? var footerButtonInfo: SessionButton.Info?
cancellables.append( cancellables.append(
@ -337,7 +365,10 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
style: .bordered, style: .bordered,
title: "DISAPPERING_MESSAGES_SAVE_TITLE".localized(), title: "DISAPPERING_MESSAGES_SAVE_TITLE".localized(),
isEnabled: true, isEnabled: true,
accessibilityIdentifier: "Set button", accessibility: Accessibility(
identifier: "Set button",
label: "Set button"
),
minWidth: 110, minWidth: 110,
onTap: {} onTap: {}
) )
@ -381,7 +412,7 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
) )
expect(updatedConfig?.durationSeconds) expect(updatedConfig?.durationSeconds)
.toEventually( .toEventually(
equal(DisappearingMessagesConfiguration.validDurationsSeconds(.disappearAfterSend).last ?? -1), equal(DisappearingMessagesConfiguration.DefaultDuration.disappearAfterSend.seconds),
timeout: .milliseconds(100) timeout: .milliseconds(100)
) )
expect(updatedConfig?.type) expect(updatedConfig?.type)

@ -21,8 +21,7 @@ public final class SessionButton: UIButton {
public let style: Style public let style: Style
public let title: String public let title: String
public let isEnabled: Bool public let isEnabled: Bool
public let accessibilityIdentifier: String? public let accessibility: Accessibility?
public let accessibilityLabel: String?
public let minWidth: CGFloat public let minWidth: CGFloat
public let onTap: () -> () public let onTap: () -> ()
@ -30,16 +29,14 @@ public final class SessionButton: UIButton {
style: Style, style: Style,
title: String, title: String,
isEnabled: Bool, isEnabled: Bool,
accessibilityIdentifier: String? = nil, accessibility: Accessibility? = nil,
accessibilityLabel: String? = nil,
minWidth: CGFloat = 0, minWidth: CGFloat = 0,
onTap: @escaping () -> () onTap: @escaping () -> ()
) { ) {
self.style = style self.style = style
self.title = title self.title = title
self.isEnabled = isEnabled self.isEnabled = isEnabled
self.accessibilityIdentifier = accessibilityIdentifier self.accessibility = accessibility
self.accessibilityLabel = accessibilityLabel
self.onTap = onTap self.onTap = onTap
self.minWidth = minWidth self.minWidth = minWidth
} }
@ -49,8 +46,7 @@ public final class SessionButton: UIButton {
lhs.style == rhs.style && lhs.style == rhs.style &&
lhs.title == rhs.title && lhs.title == rhs.title &&
lhs.isEnabled == rhs.isEnabled && lhs.isEnabled == rhs.isEnabled &&
lhs.accessibilityIdentifier == rhs.accessibilityIdentifier && lhs.accessibility == rhs.accessibility &&
lhs.accessibilityLabel == rhs.accessibilityLabel &&
lhs.minWidth == rhs.minWidth lhs.minWidth == rhs.minWidth
) )
} }

@ -9,5 +9,5 @@ public final class Features {
public static let useSharedUtilForUserConfig: Bool = true // TODO: Base this off a timestamp public static let useSharedUtilForUserConfig: Bool = true // TODO: Base this off a timestamp
// public static let useNewDisappearingMessagesConfig: Bool = Date().timeIntervalSince1970 > 1671062400 // 15/12/2022 // public static let useNewDisappearingMessagesConfig: Bool = Date().timeIntervalSince1970 > 1671062400 // 15/12/2022
public static let useNewDisappearingMessagesConfig: Bool = false public static let useNewDisappearingMessagesConfig: Bool = true
} }

Loading…
Cancel
Save