updated tests for new logic
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
45d2768a52
commit
f10e04cef5
@ -98,9 +98,11 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
|||||||
checkboxGroup
|
checkboxGroup
|
||||||
.publisher(for: .valueChanged)
|
.publisher(for: .valueChanged)
|
||||||
.sink { group in
|
.sink { group in
|
||||||
group.model.selectors.forEach { checkbox in
|
let selected = group.selectedModelHandlers?
|
||||||
print("\(checkbox.labelText!) selected: \(checkbox.selected)")
|
.compactMap{$0.labelText}
|
||||||
}
|
.joined(separator: ", ") ?? "none"
|
||||||
|
|
||||||
|
print("Selected: \(selected)")
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//setup UI
|
//setup UI
|
||||||
@ -114,6 +116,8 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
|||||||
|
|
||||||
override func updateView(viewModel: DefaultCheckboxGroupModel) {
|
override func updateView(viewModel: DefaultCheckboxGroupModel) {
|
||||||
print("\(Self.self) updateView(viewModel)")
|
print("\(Self.self) updateView(viewModel)")
|
||||||
|
showErrorSwitch.isOn = viewModel.hasError
|
||||||
|
disabledSwitch.isOn = viewModel.disabled
|
||||||
checkboxGroup.set(with: viewModel)
|
checkboxGroup.set(with: viewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -103,7 +103,7 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
|||||||
checkbox
|
checkbox
|
||||||
.publisher(for: .valueChanged)
|
.publisher(for: .valueChanged)
|
||||||
.sink { checkbox in
|
.sink { checkbox in
|
||||||
print("checkbox selected: \(checkbox.model.selected)")
|
print("checkbox selected: \(checkbox.isSelected)")
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//setup UI
|
//setup UI
|
||||||
@ -118,6 +118,8 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
|||||||
|
|
||||||
override func updateView(viewModel: DefaultCheckboxModel) {
|
override func updateView(viewModel: DefaultCheckboxModel) {
|
||||||
print("\(Self.self) updateView(viewModel)")
|
print("\(Self.self) updateView(viewModel)")
|
||||||
|
showErrorSwitch.isOn = viewModel.hasError
|
||||||
|
disabledSwitch.isOn = viewModel.disabled
|
||||||
checkbox.set(with: viewModel)
|
checkbox.set(with: viewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,10 +21,11 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Combine Properties
|
// MARK: - Combine Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@Published public var model: ModelType = ModelType()
|
public var modelSubject = CurrentValueSubject<ModelType, Never>(ModelType())
|
||||||
public var modelPublisher: Published<ModelType>.Publisher { $model }
|
public var modelPublisher: AnyPublisher<ModelType, Never> { modelSubject.eraseToAnyPublisher() }
|
||||||
public var subscribers = Set<AnyCancellable>()
|
public var subscribers = Set<AnyCancellable>()
|
||||||
|
public var firstRender: Bool = false
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -113,7 +113,7 @@ class RadioBoxGroupViewController: ModelScrollViewController<DefaultRadioBoxGro
|
|||||||
radioBoxGroup
|
radioBoxGroup
|
||||||
.publisher(for: .valueChanged)
|
.publisher(for: .valueChanged)
|
||||||
.sink { group in
|
.sink { group in
|
||||||
print("Selected: \(group.selectedModel?.text ?? "none")")
|
print("Selected: \(group.selectedModelHandler?.text ?? "none")")
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//set UI values
|
//set UI values
|
||||||
|
|||||||
@ -84,7 +84,13 @@ class RadioButtonViewController: ModelScrollViewController<DefaultRadioButtonGr
|
|||||||
model2.value = "model 2 Value"
|
model2.value = "model 2 Value"
|
||||||
model2.labelText = "iPhone 11 Bundle 2"
|
model2.labelText = "iPhone 11 Bundle 2"
|
||||||
model2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
|
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)
|
set(with: defaultModel)
|
||||||
|
|
||||||
//update the model
|
//update the model
|
||||||
@ -100,7 +106,7 @@ class RadioButtonViewController: ModelScrollViewController<DefaultRadioButtonGr
|
|||||||
radioButtonGroup
|
radioButtonGroup
|
||||||
.publisher(for: .valueChanged)
|
.publisher(for: .valueChanged)
|
||||||
.sink { group in
|
.sink { group in
|
||||||
print("Selected: \(group.selectedModel?.labelText ?? "none")")
|
print("Selected: \(group.selectedModelHandler?.labelText ?? "none")")
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//set UI values
|
//set UI values
|
||||||
|
|||||||
@ -20,10 +20,6 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
|
|||||||
var disabledSwitch = UISwitch()
|
var disabledSwitch = UISwitch()
|
||||||
var strikeThroughSwitch = UISwitch()
|
var strikeThroughSwitch = UISwitch()
|
||||||
var surfacePickerSelectorView = PickerSelectorView(title: "light")
|
var surfacePickerSelectorView = PickerSelectorView(title: "light")
|
||||||
var textField = TextField()
|
|
||||||
var subTextField = TextField()
|
|
||||||
var subTextRightField = TextField()
|
|
||||||
var showErrorSwitch = UISwitch()
|
|
||||||
|
|
||||||
var radioSwatchGroup = RadioSwatchGroup()
|
var radioSwatchGroup = RadioSwatchGroup()
|
||||||
|
|
||||||
@ -39,7 +35,6 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
|
|||||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
addFormRow(label: "Strikethrough", view: strikeThroughSwitch)
|
addFormRow(label: "Strikethrough", view: strikeThroughSwitch)
|
||||||
addFormRow(label: "Text", view: textField)
|
|
||||||
|
|
||||||
disabledSwitch
|
disabledSwitch
|
||||||
.publisher(for: .valueChanged)
|
.publisher(for: .valueChanged)
|
||||||
@ -63,23 +58,6 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
|
|||||||
self?.model.selectors = selectors
|
self?.model.selectors = selectors
|
||||||
}
|
}
|
||||||
}.store(in: &subscribers)
|
}.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
|
surfacePickerSelectorView.button
|
||||||
.publisher(for: .touchUpInside)
|
.publisher(for: .touchUpInside)
|
||||||
@ -88,7 +66,6 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
|
|||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func setupModel(){
|
func setupModel(){
|
||||||
var defaultModel = DefaultRadioSwatchGroupModel()
|
var defaultModel = DefaultRadioSwatchGroupModel()
|
||||||
|
|
||||||
@ -149,13 +126,12 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
|
|||||||
radioSwatchGroup
|
radioSwatchGroup
|
||||||
.publisher(for: .valueChanged)
|
.publisher(for: .valueChanged)
|
||||||
.sink { group in
|
.sink { group in
|
||||||
print("Selected: \(group.selectedModel?.text ?? "none")")
|
print("Selected: \(group.selectedModelHandler?.text ?? "none")")
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//set UI values
|
//set UI values
|
||||||
surfacePickerSelectorView.text = model.surface.rawValue
|
surfacePickerSelectorView.text = model.surface.rawValue
|
||||||
disabledSwitch.isOn = model.disabled
|
disabledSwitch.isOn = model.disabled
|
||||||
textField.text = model1.text
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func updateView(viewModel: ModelType) {
|
override func updateView(viewModel: ModelType) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user