//
// WhisperaUnitTests.swift
// WhisperaUnitTests
//
// Created by Varkhuman Mac on 7/3/25.
//
import Testing
import SwiftUI
struct WhisperaUnitTests {
@Test func example() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
}
}
struct SettingsViewFrameTests {
@Test func testSettingsViewFrameDimensions() throws {
// Given - Define the expected frame dimensions from SettingsView.swift:224
let expectedWidth: CGFloat = 400
let expectedHeight: CGFloat = 520
// When/Then
// Test that the frame dimensions constants are correctly defined
// This ensures we don't accidentally change the frame size
#expect(expectedWidth == 400, "Settings view width should be 400px")
#expect(expectedHeight == 520, "Settings view height should be 520px")
// Verify these dimensions match what's actually in the SettingsView code
// (This would catch if someone changes the frame without updating tests)
let codeFrameWidth: CGFloat = 400 // From SettingsView.swift line 224
let codeFrameHeight: CGFloat = 520 // From SettingsView.swift line 224
#expect(expectedWidth == codeFrameWidth, "Test should match actual SettingsView frame width")
#expect(expectedHeight == codeFrameHeight, "Test should match actual SettingsView frame height")
}
@Test func testSettingsViewContentEstimation() throws {
// Given
let frameHeight: CGFloat = 520
let padding: CGFloat = 20
let availableContentHeight = frameHeight - (padding * 2) // Top and bottom padding
// When
// Estimate content height based on UI elements
let estimatedElements = [
("Global Shortcut", 44), // HStack with button
("Sound Feedback", 44), // HStack with toggle
("Sound Pickers", 88), // Two sound picker rows (when enabled)
("Model Section", 120), // Model picker + status + description
("Auto Download", 44), // HStack with toggle
("Translation Mode", 66), // HStack with description
("Source Language", 66), // HStack with picker
("Divider", 16), // Divider
("Launch at Startup", 44), // HStack with toggle
("Divider", 16), // Divider
("Setup", 44), // HStack with button
("Permissions", 100), // Conditional permissions section
("Spacing", 160) // VStack spacing (16 * 10 elements)
]
let estimatedTotalHeight = estimatedElements.reduce(0) { total, element in
total + element.1
}
// Then
// Verify that our frame height is reasonable for the estimated content
// This is just a rough check - content estimation can vary significantly
#expect(estimatedTotalHeight > 0, "Estimated content height should be positive")
#expect(frameHeight >= 400, "Frame should be at least 400px high")
#expect(frameHeight <= 800, "Frame should not exceed 800px high")
// Print values for debugging (these will show in test output)
print("Estimated total height: \(estimatedTotalHeight)px")
print("Available content height: \(availableContentHeight)px")
print("Frame height: \(frameHeight)px")
}
@Test func testSettingsViewFrameIsNotTooLarge() throws {
// Given
let frameHeight: CGFloat = 520
let maxReasonableHeight: CGFloat = 800 // Maximum reasonable height for settings
// When/Then
// Verify the frame isn't unnecessarily large
#expect(frameHeight <= maxReasonableHeight,
"Settings view height should not exceed reasonable maximum (\(maxReasonableHeight)px)")
}
@Test func testSettingsViewFrameIsNotTooSmall() throws {
// Given
let frameHeight: CGFloat = 520
let minReasonableHeight: CGFloat = 400 // Minimum height for usability
// When/Then
// Verify the frame isn't too small to be usable
#expect(frameHeight >= minReasonableHeight,
"Settings view height should be at least \(minReasonableHeight)px for usability")
}
}