updated tests for new logic

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-09-13 12:25:57 -05:00
parent 45d2768a52
commit f10e04cef5
6 changed files with 24 additions and 35 deletions

View File

@ -98,9 +98,11 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
checkboxGroup
.publisher(for: .valueChanged)
.sink { group in
group.model.selectors.forEach { checkbox in
print("\(checkbox.labelText!) selected: \(checkbox.selected)")
}
let selected = group.selectedModelHandlers?
.compactMap{$0.labelText}
.joined(separator: ", ") ?? "none"
print("Selected: \(selected)")
}.store(in: &subscribers)
//setup UI
@ -114,6 +116,8 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
override func updateView(viewModel: DefaultCheckboxGroupModel) {
print("\(Self.self) updateView(viewModel)")
showErrorSwitch.isOn = viewModel.hasError
disabledSwitch.isOn = viewModel.disabled
checkboxGroup.set(with: viewModel)
}

View File

@ -103,7 +103,7 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
checkbox
.publisher(for: .valueChanged)
.sink { checkbox in
print("checkbox selected: \(checkbox.model.selected)")
print("checkbox selected: \(checkbox.isSelected)")
}.store(in: &subscribers)
//setup UI
@ -118,6 +118,8 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
override func updateView(viewModel: DefaultCheckboxModel) {
print("\(Self.self) updateView(viewModel)")
showErrorSwitch.isOn = viewModel.hasError
disabledSwitch.isOn = viewModel.disabled
checkbox.set(with: viewModel)
}

View File

@ -21,10 +21,11 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
//--------------------------------------------------
// MARK: - Combine Properties
//--------------------------------------------------
@Published public var model: ModelType = ModelType()
public var modelPublisher: Published<ModelType>.Publisher { $model }
public var modelSubject = CurrentValueSubject<ModelType, Never>(ModelType())
public var modelPublisher: AnyPublisher<ModelType, Never> { modelSubject.eraseToAnyPublisher() }
public var subscribers = Set<AnyCancellable>()
public var firstRender: Bool = false
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------

View File

@ -113,7 +113,7 @@ class RadioBoxGroupViewController: ModelScrollViewController<DefaultRadioBoxGro
radioBoxGroup
.publisher(for: .valueChanged)
.sink { group in
print("Selected: \(group.selectedModel?.text ?? "none")")
print("Selected: \(group.selectedModelHandler?.text ?? "none")")
}.store(in: &subscribers)
//set UI values

View File

@ -84,7 +84,13 @@ class RadioButtonViewController: ModelScrollViewController<DefaultRadioButtonGr
model2.value = "model 2 Value"
model2.labelText = "iPhone 11 Bundle 2"
model2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
defaultModel.selectors = [model1, model2]
var model3 = DefaultRadioButtonModel()
model3.inputId = "model3"
model3.value = "model 3 Value"
model3.labelText = "iPhone 11 Bundle 3"
model3.childText = "Apple iPhone 11 - 256 GB\nOtterbox Case Black\nScreen Protector"
defaultModel.selectors = [model1, model2, model3]
set(with: defaultModel)
//update the model
@ -100,7 +106,7 @@ class RadioButtonViewController: ModelScrollViewController<DefaultRadioButtonGr
radioButtonGroup
.publisher(for: .valueChanged)
.sink { group in
print("Selected: \(group.selectedModel?.labelText ?? "none")")
print("Selected: \(group.selectedModelHandler?.labelText ?? "none")")
}.store(in: &subscribers)
//set UI values

View File

@ -20,10 +20,6 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
var disabledSwitch = UISwitch()
var strikeThroughSwitch = UISwitch()
var surfacePickerSelectorView = PickerSelectorView(title: "light")
var textField = TextField()
var subTextField = TextField()
var subTextRightField = TextField()
var showErrorSwitch = UISwitch()
var radioSwatchGroup = RadioSwatchGroup()
@ -39,7 +35,6 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Strikethrough", view: strikeThroughSwitch)
addFormRow(label: "Text", view: textField)
disabledSwitch
.publisher(for: .valueChanged)
@ -63,23 +58,6 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
self?.model.selectors = selectors
}
}.store(in: &subscribers)
textField
.textPublisher
.sink { [weak self] text in
let selectors = self?.model.selectors.compactMap { existing in
if existing.inputId == self?.model.selectors.first?.inputId {
return existing.copyWith {
$0.text = text
}
} else {
return existing
}
}
if let selectors {
self?.model.selectors = selectors
}
}.store(in: &subscribers)
surfacePickerSelectorView.button
.publisher(for: .touchUpInside)
@ -88,7 +66,6 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
}.store(in: &subscribers)
}
func setupModel(){
var defaultModel = DefaultRadioSwatchGroupModel()
@ -149,13 +126,12 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
radioSwatchGroup
.publisher(for: .valueChanged)
.sink { group in
print("Selected: \(group.selectedModel?.text ?? "none")")
print("Selected: \(group.selectedModelHandler?.text ?? "none")")
}.store(in: &subscribers)
//set UI values
surfacePickerSelectorView.text = model.surface.rawValue
disabledSwitch.isOn = model.disabled
textField.text = model1.text
}
override func updateView(viewModel: ModelType) {