mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
127 lines
2.7 KiB
Swift
127 lines
2.7 KiB
Swift
@testable import DivKit
|
|
@testable import LayoutKit
|
|
|
|
import XCTest
|
|
|
|
import VGSL
|
|
|
|
final class DivTextExtensionsTests: XCTestCase {
|
|
func test_WithText() {
|
|
let block = makeBlock(
|
|
divText(text: "Hello!")
|
|
)
|
|
|
|
let expectedBlock = StateBlock(
|
|
child: DecoratingBlock(
|
|
child: TextBlock(
|
|
widthTrait: .resizable,
|
|
text: "Hello!".withTypo(),
|
|
verticalAlignment: .leading,
|
|
accessibilityElement: nil
|
|
),
|
|
accessibilityElement: accessibility(
|
|
traits: .staticText,
|
|
label: "Hello!"
|
|
)
|
|
),
|
|
ids: []
|
|
)
|
|
|
|
assertEqual(block, expectedBlock)
|
|
}
|
|
|
|
func test_WithAccessibility() throws {
|
|
let block = makeBlock(
|
|
divText(
|
|
accessibility: DivAccessibility(
|
|
description: .value("Accessibility description"),
|
|
type: .button
|
|
),
|
|
id: "text_id",
|
|
text: "Hello!"
|
|
)
|
|
)
|
|
|
|
let expectedBlock = StateBlock(
|
|
child: DecoratingBlock(
|
|
child: TextBlock(
|
|
widthTrait: .resizable,
|
|
text: "Hello!".withTypo(),
|
|
verticalAlignment: .leading,
|
|
accessibilityElement: nil
|
|
),
|
|
accessibilityElement: accessibility(
|
|
traits: .button,
|
|
label: "Accessibility description",
|
|
identifier: "text_id"
|
|
)
|
|
),
|
|
ids: []
|
|
)
|
|
|
|
assertEqual(block, expectedBlock)
|
|
}
|
|
|
|
func test_WithAccessibilityWithoutDescription_AppliesTextAsDescription() throws {
|
|
let block = makeBlock(
|
|
divText(
|
|
accessibility: DivAccessibility(type: .button),
|
|
text: "Hello!"
|
|
)
|
|
)
|
|
|
|
let expectedBlock = StateBlock(
|
|
child: DecoratingBlock(
|
|
child: TextBlock(
|
|
widthTrait: .resizable,
|
|
text: "Hello!".withTypo(),
|
|
verticalAlignment: .leading,
|
|
accessibilityElement: nil
|
|
),
|
|
accessibilityElement: accessibility(
|
|
traits: .button,
|
|
label: "Hello!"
|
|
)
|
|
),
|
|
ids: []
|
|
)
|
|
|
|
assertEqual(block, expectedBlock)
|
|
}
|
|
|
|
func test_WithAction() {
|
|
let block = makeBlock(
|
|
divText(
|
|
actions: [
|
|
divAction(
|
|
logId: "action_log_id",
|
|
url: "https://some.url"
|
|
),
|
|
],
|
|
text: "Hello!"
|
|
)
|
|
)
|
|
|
|
let expectedBlock = StateBlock(
|
|
child: DecoratingBlock(
|
|
child: textBlock(text: "Hello!"),
|
|
actions: NonEmptyArray(
|
|
uiAction(
|
|
logId: "action_log_id",
|
|
path: .root + "0",
|
|
url: "https://some.url"
|
|
)
|
|
),
|
|
actionAnimation: .default,
|
|
accessibilityElement: accessibility(
|
|
traits: .staticText,
|
|
label: "Hello!"
|
|
)
|
|
),
|
|
ids: []
|
|
)
|
|
|
|
assertEqual(block, expectedBlock)
|
|
}
|
|
}
|