import Testing import CoreGraphics @testable import OnyxNotch @Suite("Band neben der Notch") struct NotchBandTests { // Die nachgemessenen Werte des Zielgeräts: 1800 Punkte breiter Bildschirm, // Notch 220 breit, bei fünf Kacheln ein 972 Punkte breites Panel. private let notchWidth: CGFloat = 220 private let panelWidth: CGFloat = 972 @Test("Bei fünf Kacheln bleiben je 376 Punkte") func referenceMachine() { let band = NotchBandLayout.resolve(panelWidth: panelWidth, notchWidth: notchWidth) #expect(band.leading == 376) #expect(band.trailing == 376) #expect(!band.isEmpty) } @Test("Der gezeichnete Streifen ist wieder so breit wie das Panel") func totalMatchesPanel() { let band = NotchBandLayout.resolve(panelWidth: panelWidth, notchWidth: notchWidth) #expect(band.totalWidth(notchWidth: notchWidth) == panelWidth) } /// Zusammengezogen ist das Panel genau die Notch. Dann gibt es keine Arme — /// und erst recht keine negativen. @Test("Ist das Panel so breit wie die Notch, gibt es kein Band") func collapsedHasNoBand() { let band = NotchBandLayout.resolve(panelWidth: notchWidth, notchWidth: notchWidth) #expect(band == .none) #expect(band.isEmpty) } /// Kommt auf sehr schmalen Bildschirmen vor, wenn das Panel geklemmt wird. /// Eine negative Breite wäre in einer `frame`-Angabe ein Absturz. @Test("Ein Panel schmaler als die Notch ergibt keine negative Breite") func narrowerThanNotchStaysZero() { let band = NotchBandLayout.resolve(panelWidth: 120, notchWidth: notchWidth) #expect(band == .none) } @Test("Knapp unter dem Mindestmaß bleibt der Streifen leer") func belowMinimumIsEmpty() { let width = notchWidth + 2 * (NotchBandLayout.minimumUsableWidth - 1) #expect(NotchBandLayout.resolve(panelWidth: width, notchWidth: notchWidth) == .none) } @Test("Genau am Mindestmaß trägt er") func atMinimumIsUsed() { let width = notchWidth + 2 * NotchBandLayout.minimumUsableWidth let band = NotchBandLayout.resolve(panelWidth: width, notchWidth: notchWidth) #expect(band.leading == NotchBandLayout.minimumUsableWidth) } /// Ein Arm links ohne Gegenstück rechts liest sich als verrutschtes Panel. @Test("Beide Seiten sind immer gleich breit") func bothSidesMatch() { for width in stride(from: CGFloat(200), through: 2000, by: 37) { let band = NotchBandLayout.resolve(panelWidth: width, notchWidth: notchWidth) #expect(band.leading == band.trailing) } } }