Revision control
Copy as Markdown
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
import UIKit
import Testing
@testable import SummarizeKit
@Suite
struct LayoutContextTests {
@Test
func test_isLandscapeLayout_whenPortraitOrientation() {
let subject = createSubject(width: 375, height: 667)
#expect(!subject.isLandscapeLayout)
}
@Test
func test_isLandscapeLayout_whenLandscapeOrientation() {
let subject = createSubject(width: 667, height: 375)
#expect(subject.isLandscapeLayout)
}
@Test
func test_isLandscapeLayout_whenRegularSizeClass() {
let subject = createSubject(width: 1024, height: 768, horizontalSizeClass: .regular)
// iPad with regular horizontal size class should use portrait layout even if width > height
#expect(!subject.isLandscapeLayout)
}
@Test
func test_isRotated_whenInInitialOrientation() {
let subject = createSubject(width: 375, height: 667, isInitialLandscape: false)
#expect(!subject.isRotated)
}
@Test
func test_isRotated_whenNotInInitialOrientation() {
let subject = createSubject(width: 375, height: 667, isInitialLandscape: true)
#expect(subject.isRotated)
}
private func createSubject(
width: CGFloat,
height: CGFloat,
horizontalSizeClass: UIUserInterfaceSizeClass = .compact,
isInitialLandscape: Bool = false
) -> LayoutContext {
let traitCollection = UITraitCollection(horizontalSizeClass: horizontalSizeClass)
return LayoutContext(
viewSize: CGSize(width: width, height: height),
traitCollection: traitCollection,
tabSnapshotTopOffset: 0.0,
isInitialLandscape: isInitialLandscape
)
}
}