mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
140 lines
3.9 KiB
Swift
140 lines
3.9 KiB
Swift
@testable import DivKit
|
|
import DivKitTestsSupport
|
|
import LayoutKit
|
|
import VGSL
|
|
import XCTest
|
|
|
|
final class DivStateManagerTests: XCTestCase {
|
|
private let stateManager = DivStateManager()
|
|
private let transition = DivAppearanceTransition.divFadeTransition(DivFadeTransition())
|
|
private let visibilityExpression: DivKit.Expression<DivVisibility> = expression("@{visibility}")
|
|
|
|
func test_shouldBlockAppearWithTransition_isFalseForNewBlock() {
|
|
XCTAssertFalse(
|
|
stateManager.shouldBlockAppearWithTransition(
|
|
path: DivBlockPath(rawValue: "root/blockId")
|
|
)
|
|
)
|
|
}
|
|
|
|
func test_shouldBlockAppearWithTransition_isFalseForVisibleBlock() {
|
|
let statePath = DivStatePath(rawValue: "root")
|
|
stateManager.setBlockVisibility(
|
|
statePath: statePath,
|
|
div: divSeparator(
|
|
id: "blockId",
|
|
transitionIn: transition,
|
|
visibility: visibilityExpression
|
|
).value,
|
|
isVisible: true
|
|
)
|
|
|
|
XCTAssertFalse(
|
|
stateManager.shouldBlockAppearWithTransition(
|
|
path: statePath + "blockId"
|
|
)
|
|
)
|
|
}
|
|
|
|
func test_shouldBlockAppearWithTransition_isFalseForInvisibleBlockWithConstantVisibility() {
|
|
let statePath = DivStatePath(rawValue: "root")
|
|
stateManager.setBlockVisibility(
|
|
statePath: statePath,
|
|
div: divSeparator(
|
|
id: "blockId",
|
|
transitionIn: transition
|
|
).value,
|
|
isVisible: false
|
|
)
|
|
|
|
XCTAssertFalse(
|
|
stateManager.shouldBlockAppearWithTransition(
|
|
path: statePath + "blockId"
|
|
)
|
|
)
|
|
}
|
|
|
|
func test_shouldBlockAppearWithTransition_isFalseForBlockWithoutTransitions() {
|
|
let statePath = DivStatePath(rawValue: "root")
|
|
stateManager.setBlockVisibility(
|
|
statePath: statePath,
|
|
div: divSeparator(
|
|
id: "blockId",
|
|
visibility: visibilityExpression
|
|
).value,
|
|
isVisible: false
|
|
)
|
|
|
|
XCTAssertFalse(
|
|
stateManager.shouldBlockAppearWithTransition(
|
|
path: statePath + "blockId"
|
|
)
|
|
)
|
|
}
|
|
|
|
func test_shouldBlockAppearWithTransition_isFalseForBlockWithWrongTransitionTrigger() {
|
|
let statePath = DivStatePath(rawValue: "root")
|
|
stateManager.setBlockVisibility(
|
|
statePath: statePath,
|
|
div: divSeparator(
|
|
id: "blockId",
|
|
transitionIn: transition,
|
|
transitionTriggers: [.stateChange],
|
|
visibility: visibilityExpression
|
|
).value,
|
|
isVisible: false
|
|
)
|
|
|
|
XCTAssertFalse(
|
|
stateManager.shouldBlockAppearWithTransition(
|
|
path: statePath + "blockId"
|
|
)
|
|
)
|
|
}
|
|
|
|
func test_shouldBlockAppearWithTransition_isTrueForInvisibleBlock() {
|
|
let statePath = DivStatePath(rawValue: "root")
|
|
stateManager.setBlockVisibility(
|
|
statePath: statePath,
|
|
div: divSeparator(
|
|
id: "blockId",
|
|
transitionIn: transition,
|
|
visibility: visibilityExpression
|
|
).value,
|
|
isVisible: false
|
|
)
|
|
|
|
XCTAssertTrue(
|
|
stateManager.shouldBlockAppearWithTransition(
|
|
path: statePath + "blockId"
|
|
)
|
|
)
|
|
}
|
|
|
|
func test_settingStateToDivStateManager() {
|
|
stateManager.setState(stateBlockPath: statePath, stateID: "first")
|
|
XCTAssertEqual(stateManager.get(stateBlockPath: statePath)?.currentStateID, "first")
|
|
}
|
|
|
|
func test_settingStateToDivStateManagerByBinding() {
|
|
let stateBinding = Binding<String>(
|
|
name: "binding",
|
|
value: Property<String>(initialValue: "second")
|
|
)
|
|
stateManager.setState(stateBlockPath: statePath, stateBinding: stateBinding)
|
|
XCTAssertEqual(stateManager.get(stateBlockPath: statePath)?.currentStateID, "second")
|
|
}
|
|
|
|
func test_checkBindingChangedAfterSettingStateManually() {
|
|
let stateBinding = Binding<String>(
|
|
name: "binding",
|
|
value: Property<String>(initialValue: "second")
|
|
)
|
|
stateManager.setState(stateBlockPath: statePath, stateBinding: stateBinding)
|
|
stateManager.setState(stateBlockPath: statePath, stateID: "first")
|
|
XCTAssertEqual(stateBinding.value, "first")
|
|
}
|
|
}
|
|
|
|
private let statePath: DivStatePath = "0/state"
|