mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
6e60922f71
Подготовительный пр Вынес тесты на ContainerBlockLayout в отдельный файл + подпричесал остальные тесты, что увидел.
120 lines
3.5 KiB
Swift
120 lines
3.5 KiB
Swift
import Foundation
|
|
|
|
import BaseUI
|
|
import CommonCore
|
|
import LayoutKit
|
|
|
|
typealias ImageBlockTestModels = BlockTestsModels.Image
|
|
typealias TextBlockTestModels = BlockTestsModels.Text
|
|
typealias ContainerBlockTestModels = BlockTestsModels.Container
|
|
typealias GalleryBlockTestModels = BlockTestsModels.Gallery
|
|
typealias TabsBlockTestModels = BlockTestsModels.Tabs
|
|
typealias SwitchableContainerBlockTestModels = BlockTestsModels.SwitchableContainer
|
|
|
|
enum BlockTestsModels {
|
|
enum Text {
|
|
static let base = TextBlock(widthTrait: .fixed(128), text: text)
|
|
static let text = "Северная Ирландия".with(typo: typo)
|
|
static let typo = Typo(size: .textM, weight: .regular).with(height: .textM).kerned(.textM)
|
|
static let intrinsicTextSize = text.sizeForWidth(.infinity)
|
|
}
|
|
|
|
enum Container {
|
|
static let threeGaps: [CGFloat] = [10, 20, 30]
|
|
static let threeGapsSize = threeGaps.reduce(0, +)
|
|
}
|
|
|
|
struct Gallery {
|
|
static let path = UIElementPath("gallery")
|
|
|
|
static let base = make(blocks: [TextBlockTestModels.base, TextBlockTestModels.base])
|
|
|
|
static func make(blocks: [Block]) -> GalleryBlock {
|
|
try! GalleryBlock(
|
|
model: GalleryViewModel(
|
|
blocks: blocks,
|
|
metrics: GalleryViewMetrics(gaps: Array(
|
|
repeating: 0,
|
|
times: try! UInt(value: blocks.count + 1)
|
|
)),
|
|
path: path
|
|
),
|
|
state: .default,
|
|
widthTrait: .fixed(128),
|
|
heightTrait: .fixed(128)
|
|
)
|
|
}
|
|
}
|
|
|
|
struct Tabs {
|
|
static let path = UIElementPath("tabs")
|
|
|
|
static let base = try! make(
|
|
titles: ["A", "B"],
|
|
blocks: [TextBlockTestModels.base, TextBlockTestModels.base]
|
|
)
|
|
|
|
static let gallery = try! make(
|
|
titles: ["A"],
|
|
blocks: [GalleryBlockTestModels.base]
|
|
)
|
|
|
|
private static func make(titles: [String], blocks: [Block]) throws -> TabsBlock {
|
|
try TabsBlock(
|
|
model: try TabViewModel(
|
|
listModel: TabListViewModel(
|
|
tabTitleLinks: titles.enumerated().map { UILink(text: $1, path: path + "title.\($0)") }
|
|
),
|
|
contentsModel: try! TabContentsViewModel(
|
|
pages: blocks.enumerated().map { $1.makeTabPage(with: path + "page.\($0)") },
|
|
pagesHeight: .default,
|
|
path: path
|
|
)
|
|
),
|
|
state: .default,
|
|
widthTrait: .fixed(128),
|
|
heightTrait: .fixed(128)
|
|
)
|
|
}
|
|
}
|
|
|
|
enum Image {
|
|
static let imageSize = CGSize(width: 80, height: 60)
|
|
static let image = BaseTiny.Image.imageWithSolidColor(.black, size: imageSize)!
|
|
}
|
|
|
|
enum SwitchableContainer {
|
|
static let path = UIElementPath("switchableContainerBlock")
|
|
|
|
static let base = SwitchableContainerBlock(
|
|
selectedItem: .left,
|
|
items: (
|
|
.init(
|
|
title: .init(text: "A", selectedTypo: Typo(), deselectedTypo: Typo()),
|
|
content: GalleryBlockTestModels.base
|
|
),
|
|
.init(
|
|
title: .init(text: "A", selectedTypo: Typo(), deselectedTypo: Typo()),
|
|
content: GalleryBlockTestModels.base
|
|
)
|
|
),
|
|
backgroundColor: .clear,
|
|
selectedBackgroundColor: .clear,
|
|
titleGaps: 0,
|
|
titleContentGap: 0,
|
|
selectorSideGaps: 0,
|
|
switchAction: nil,
|
|
path: path
|
|
)
|
|
}
|
|
|
|
static func block(withSize size: CGSize) -> Block {
|
|
try! ContainerBlock(
|
|
layoutDirection: .vertical,
|
|
widthTrait: .fixed(size.width),
|
|
heightTrait: .fixed(size.height),
|
|
children: [TextBlock(widthTrait: .resizable, text: "".with(typo: Typo()))]
|
|
)
|
|
}
|
|
}
|