In snapshots UISwitch doesnt switch to ride side, when i make it display(isOn: false)
Its just placed on the left side, but the color is gray, like its disabled. How can i snapshot my UISwitch with chainging control position? Just like in real app. I tried to make it with expectation, give it a delay, but it doesnt work in any way.
The last one is my test. First one is my custom UIswitch.
open class SwitchControl: UISwitch {
public var onPress: ((SwitchCotrolOutput & LoadingOutput) -> Void)?
public var isLoading: Bool?
private var switchStyle: SwitchControlPresentableModel.Style? {
didSet {
display(style: switchStyle)
}
}
public init() {
super.init(frame: .zero)
addTarget(self, action: #selector(didPress), for: .valueChanged)
}
public init(style: SwitchControlPresentableModel.Style) {
super.init(frame: .zero)
addTarget(self, action: #selector(didPress), for: .valueChanged)
self.switchStyle = style
display(style: style)
}
@objc private func didPress() {
onPress?(self)
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}}
extension SwitchControl: SwitchCotrolOutput {
public func display(model: SwitchControlPresentableModel?) {
isHidden = model == nil
if let isOn = model?.isOn { display(isOn: isOn) }
if let isEnabled = model?.isEnabled { display(isEnabled: isEnabled) }
if let style = model?.style {
switchStyle = style
}
display(onPress: model?.onPress)
}
public func display(style: SwitchControlPresentableModel.Style?) {
onTintColor = style?.tintColor
thumbTintColor = style?.thumbTintColor
backgroundColor = style?.backgroundColor
cornerRadius = style?.cornerRadius ?? 0
}
public func display(onPress: ((SwitchCotrolOutput & LoadingOutput) -> Void)?) {
self.onPress = onPress
}
public func display(isOn: Bool) {
self.isOn = isOn
}
public func display(isEnabled: Bool) {
self.isEnabled = isEnabled
}
public func display(isHidden: Bool) {
self.isHidden = isHidden
}}
func test_switchControl_default_state() {
// GIVEN
let (sut, container) = makeSUT()
// WHEN
sut.display(isOn: true)
sut.display(isEnabled: true)
// THEN
assert(snapshot: container.snapshot(for: .iPhone(style: .light)),
named: "SWITCHCONTROL_DEFAUlt_STATE_LIGHT")
assert(snapshot: container.snapshot(for: .iPhone(style: .dark)),
named: "SWITCHCONTROL_DEFAUlt_STATE_DARK")
}
