Files
divkit/client/ios/DivKitExtensionsTests/ShimmerImagePreviewStyleTests.swift
T
pkurchatov e2b330d645 Swift 6 support in DivKitExtensionsTests
commit_hash:f3785279b800fa5cb88b1d6dbda2e87a80ee9f3d
2025-12-23 18:17:36 +03:00

75 lines
1.9 KiB
Swift

import DivKit
@testable import DivKitExtensions
import LayoutKit
import Testing
import VGSL
@MainActor
@Suite
struct ShimmerImagePreviewStyleTests {
private let tester = ShimmerStyleTester { dict, context in
try ShimmerImagePreviewStyle(
dictionary: dict,
expressionResolver: context.expressionResolver
)
}
@Test
func whenDecodingEmptyImagePreviewStyle_DecodesWithDefaultValues() {
tester.assertStyle(ShimmerImagePreviewStyle.default, .init())
}
@Test
func whenDecodingImagePreviewStyleWithExactValues_DecodesCorrectly() {
tester.assertStyle(
expectedStyle,
[
"angle": 15.0,
"duration": 1.6,
"colors": ["#ffffff", "#ffffff00", "#ffffff"],
"locations": [0.1, 0.5, 0.9],
"corner_radius": [
"top-left": 0,
"top-right": 8,
"bottom-left": 16,
"bottom-right": 32,
],
]
)
}
@Test
func whenDecodingImagePreviewStyleWithExpressionValues_DecodesCorrectly() {
tester.assertStyle(
expectedStyle,
[
"angle": "@{15}",
"colors": [
"@{'#ffffff'}",
"@{'#ffffff00'}",
"@{'#ffffff'}",
],
"duration": "@{1.6}",
"locations": ["@{0.1}", "@{0.5}", "@{0.9}"],
"corner_radius": [
"top-left": "@{0}",
"top-right": "@{8}",
"bottom-left": "@{16}",
"bottom-right": "@{32}",
],
]
)
}
}
private let expectedStyle = ShimmerImagePreviewStyle(
colorsAndLocations: [
ColorAndLocation(color: .color(withHexString: "#ffffff")!, location: 0.1),
ColorAndLocation(color: .color(withHexString: "#ffffff00")!, location: 0.5),
ColorAndLocation(color: .color(withHexString: "#ffffff")!, location: 0.9),
],
angle: 15,
duration: 1.6,
cornerRadius: CornerRadii(topLeft: 0, topRight: 8, bottomLeft: 16, bottomRight: 32)
)