update disappearing messages unit test

pull/941/head
ryanzhao 1 year ago
parent 00e468fcce
commit 89324f01bf

@ -313,8 +313,8 @@ class ThreadDisappearingMessagesSettingsViewModel: SessionTableViewModel<ThreadD
currentUserIsClosedGroupMember == true currentUserIsClosedGroupMember == true
), ),
accessibility: Accessibility( accessibility: Accessibility(
identifier: "Off option", identifier: "Disable disappearing messages (Off option)",
label: "Off option" label: "Disable disappearing messages (Off option)"
), ),
onTap: { onTap: {
let updatedConfig: DisappearingMessagesConfiguration = currentSelection let updatedConfig: DisappearingMessagesConfiguration = currentSelection
@ -394,8 +394,8 @@ class ThreadDisappearingMessagesSettingsViewModel: SessionTableViewModel<ThreadD
currentUserIsClosedGroupMember == true currentUserIsClosedGroupMember == true
), ),
accessibility: Accessibility( accessibility: Accessibility(
identifier: "Off option", identifier: "Disable disappearing messages (Off option)",
label: "Off option" label: "Disable disappearing messages (Off option)"
), ),
onTap: { onTap: {
let updatedConfig: DisappearingMessagesConfiguration = currentSelection let updatedConfig: DisappearingMessagesConfiguration = currentSelection

@ -75,13 +75,28 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
} }
it("has the correct number of items") { it("has the correct number of items") {
// The default disappearing messages configure is Off
// Should only show one section of Disappearing Messages Type
expect(viewModel.tableData.count) expect(viewModel.tableData.count)
.to(equal(1)) .to(equal(1))
expect(viewModel.tableData.first?.elements.count) if Features.useNewDisappearingMessagesConfig {
.to(equal(12)) // Off
// Disappear After Read
// Disappear After Send
expect(viewModel.tableData.first?.elements.count)
.to(equal(3))
} else {
// Off
// Legacy
// Disappear After Read
// Disappear After Send
expect(viewModel.tableData.first?.elements.count)
.to(equal(4))
}
} }
it("has the correct default state") { it("has the correct default state") {
// First option is always Off
expect(viewModel.tableData.first?.elements.first) expect(viewModel.tableData.first?.elements.first)
.to( .to(
equal( equal(
@ -94,33 +109,39 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { true } isSelected: { true }
), ),
accessibilityIdentifier: "Off option", accessibility: Accessibility(
accessibilityLabel: "Off option" identifier: "Disable disappearing messages (Off option)",
label: "Disable disappearing messages (Off option)"
)
) )
) )
) )
// Last option is always Disappear After Send`
let title: String = (DisappearingMessagesConfiguration.validDurationsSeconds.last?
.formatted(format: .long))
.defaulting(to: "")
expect(viewModel.tableData.first?.elements.last) expect(viewModel.tableData.first?.elements.last)
.to( .to(
equal( equal(
SessionCell.Info( SessionCell.Info(
id: ThreadDisappearingMessagesSettingsViewModel.Item(title: title), id: ThreadDisappearingMessagesSettingsViewModel.Item(
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized()
),
position: .bottom, position: .bottom,
title: title, title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized(),
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_DESCRIPTION".localized(),
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { false } isSelected: { false }
),
isEnabled: Features.useNewDisappearingMessagesConfig,
accessibility: Accessibility(
identifier: "Disappear after send option",
label: "Disappear after send option"
) )
) )
) )
) )
expect(viewModel.settingsData.count)
.to(equal(1))
} }
it("starts with the correct item active if not default") { it("starts with the correct item active if not default") {
// Test config: Disappear After Send - 2 weeks
let config: DisappearingMessagesConfiguration = DisappearingMessagesConfiguration let config: DisappearingMessagesConfiguration = DisappearingMessagesConfiguration
.defaultWith("TestId") .defaultWith("TestId")
.with( .with(
@ -148,6 +169,10 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
) )
) )
// Should have 2 sections now: Disappearing Messages Type & Timer
expect(viewModel.tableData.count)
.to(equal(2))
expect(viewModel.tableData.first?.elements.first) expect(viewModel.tableData.first?.elements.first)
.to( .to(
equal( equal(
@ -160,31 +185,34 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { false } isSelected: { false }
), ),
accessibilityIdentifier: "Off option", accessibility: Accessibility(
accessibilityLabel: "Off option" identifier: "Disable disappearing messages (Off option)",
label: "Disable disappearing messages (Off option)"
)
) )
) )
) )
expect(viewModel.settingsData.first?.elements.last) expect(viewModel.tableData.first?.elements.last)
.to( .to(
equal( equal(
SessionCell.Info( SessionCell.Info(
id: ThreadDisappearingMessagesViewModel.Item( id: ThreadDisappearingMessagesSettingsViewModel.Item(
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized() title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized()
), ),
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(
isSelected: { true } isSelected: { true }
),
accessibility: Accessibility(
identifier: "Disappear after send option",
label: "Disappear after send option"
) )
) )
) )
) )
expect(viewModel.settingsData.count)
.to(equal(2))
let title: String = (DisappearingMessagesConfiguration.validDurationsSeconds(.disappearAfterSend).last? let title: String = (DisappearingMessagesConfiguration.validDurationsSeconds(.disappearAfterSend).last?
.formatted(format: .long)) .formatted(format: .long))
.defaulting(to: "") .defaulting(to: "")
@ -198,12 +226,13 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { true } isSelected: { true }
), ),
accessibilityIdentifier: "Time option", accessibility: Accessibility(
accessibilityLabel: "Time option" identifier: "Time option",
label: "Time option"
)
) )
) )
) )
} }
it("has no footer button") { it("has no footer button") {
@ -253,6 +282,8 @@ class ThreadDisappearingMessagesSettingsViewModelSpec: QuickSpec {
) )
} }
// TODO: Continue to work from here
context("and saving") { context("and saving") {
it("dismisses the screen") { it("dismisses the screen") {
var didDismissScreen: Bool = false var didDismissScreen: Bool = false

Loading…
Cancel
Save