Skip to content

Commit 12ae89c

Browse files
committed
refactor: remove redundant HUD tests for volume key presses and formatting
1 parent 076179d commit 12ae89c

3 files changed

Lines changed: 15 additions & 894 deletions

File tree

VolumeGridTests/HUDTests.swift

Lines changed: 0 additions & 288 deletions
Original file line numberDiff line numberDiff line change
@@ -324,294 +324,6 @@ final class HUDScenarioTests: XCTestCase {
324324
super.tearDown()
325325
}
326326

327-
// MARK: - Volume Key Press Scenarios
328-
329-
func testHUDShowsWhenVolumeKeyPressed() {
330-
let expectation = XCTestExpectation(
331-
description: "HUD should be visible after volume key press")
332-
mockSystemEventMonitor?.simulateVolumeKeyPress(keyCode: 0)
333-
334-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
335-
expectation.fulfill()
336-
}
337-
338-
wait(for: [expectation], timeout: 1.0)
339-
}
340-
341-
func testHUDShowsWhenMuteKeyPressed() {
342-
let expectation = XCTestExpectation(
343-
description: "HUD should be visible after mute key press")
344-
345-
let hudDisplayed = {
346-
expectation.fulfill()
347-
}
348-
349-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
350-
hudDisplayed()
351-
}
352-
353-
wait(for: [expectation], timeout: 1.0)
354-
}
355-
356-
func testHUDShowsWhenIncreaseVolumeKeyPressed() {
357-
let expectation = XCTestExpectation(
358-
description: "HUD should display when volume increase key is pressed")
359-
360-
mockSystemEventMonitor?.simulateVolumeKeyPress(keyCode: 0)
361-
362-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
363-
expectation.fulfill()
364-
}
365-
366-
wait(for: [expectation], timeout: 1.0)
367-
}
368-
369-
func testHUDShowsWhenDecreaseVolumeKeyPressed() {
370-
let expectation = XCTestExpectation(
371-
description: "HUD should display when volume decrease key is pressed")
372-
373-
mockSystemEventMonitor?.simulateVolumeKeyPress(keyCode: 1)
374-
375-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
376-
expectation.fulfill()
377-
}
378-
379-
wait(for: [expectation], timeout: 1.0)
380-
}
381-
382-
func testHUDShowsWhenMuteKeyPressedAtZeroVolume() {
383-
let expectation = XCTestExpectation(
384-
description: "HUD should display when mute key is pressed even when volume is at 0")
385-
386-
let mutedEvent = HUDEvent(volumeScalar: 0.0, deviceName: "Speaker", isUnsupported: false)
387-
XCTAssertEqual(mutedEvent.volumeScalar, 0.0)
388-
389-
mockSystemEventMonitor?.simulateVolumeKeyPress(keyCode: 7)
390-
391-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
392-
expectation.fulfill()
393-
}
394-
395-
wait(for: [expectation], timeout: 1.0)
396-
}
397-
398-
func testMuteStateTransitionFromZeroVolume() {
399-
let expectation = XCTestExpectation(
400-
description: "When volume is 0 and mute state changes, HUD should still be shown")
401-
402-
let zeroMutedEvent = HUDEvent(
403-
volumeScalar: 0.0, deviceName: "Speaker", isUnsupported: false)
404-
XCTAssertEqual(zeroMutedEvent.volumeScalar, 0.0)
405-
406-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
407-
expectation.fulfill()
408-
}
409-
410-
wait(for: [expectation], timeout: 1.0)
411-
}
412-
413-
func testVolumeChangeFromZeroToNonZero() {
414-
let expectation = XCTestExpectation(
415-
description: "HUD should display when volume increases from 0")
416-
417-
let zeroEvent = HUDEvent(volumeScalar: 0.0, deviceName: "Speaker", isUnsupported: false)
418-
XCTAssertEqual(zeroEvent.volumeScalar, 0.0)
419-
420-
let nonZeroEvent = HUDEvent(volumeScalar: 0.3, deviceName: "Speaker", isUnsupported: false)
421-
XCTAssertEqual(nonZeroEvent.volumeScalar, 0.3)
422-
XCTAssertNotEqual(zeroEvent.volumeScalar, nonZeroEvent.volumeScalar)
423-
424-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
425-
expectation.fulfill()
426-
}
427-
428-
wait(for: [expectation], timeout: 1.0)
429-
}
430-
431-
func testHUDEventEmittedWhenVolumeIsZero() {
432-
let expectation = XCTestExpectation(
433-
description: "HUD event should be emitted with zero volume scalar")
434-
435-
let event = HUDEvent(volumeScalar: 0.0, deviceName: "Speaker", isUnsupported: false)
436-
XCTAssertEqual(event.volumeScalar, 0.0)
437-
XCTAssertEqual(event.deviceName, "Speaker")
438-
439-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
440-
expectation.fulfill()
441-
}
442-
443-
wait(for: [expectation], timeout: 1.0)
444-
}
445-
446-
func testRapidVolumeKeyPresses() {
447-
let expectation = XCTestExpectation(
448-
description: "Rapid consecutive volume key presses should show correct HUD values")
449-
450-
let volumes: [CGFloat] = [0.3, 0.4, 0.5, 0.6, 0.7]
451-
var events: [HUDEvent] = []
452-
453-
for volume in volumes {
454-
let event = HUDEvent(volumeScalar: volume, deviceName: "Speaker", isUnsupported: false)
455-
events.append(event)
456-
XCTAssertEqual(event.volumeScalar, volume)
457-
}
458-
459-
XCTAssertEqual(events.last?.volumeScalar, 0.7)
460-
461-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
462-
expectation.fulfill()
463-
}
464-
465-
wait(for: [expectation], timeout: 1.0)
466-
}
467-
468-
func testDebounceDoesNotDisplayIntermediateValues() {
469-
let expectation = XCTestExpectation(
470-
description:
471-
"HUD events should not show intermediate values that differ from what was pressed")
472-
473-
let event1 = HUDEvent(volumeScalar: 0.19, deviceName: "Speaker", isUnsupported: false)
474-
XCTAssertEqual(event1.volumeScalar, 0.19)
475-
476-
let event2 = HUDEvent(volumeScalar: 0.22, deviceName: "Speaker", isUnsupported: false)
477-
let event3 = HUDEvent(volumeScalar: 0.25, deviceName: "Speaker", isUnsupported: false)
478-
479-
XCTAssert(event3.volumeScalar > event2.volumeScalar)
480-
XCTAssert(event2.volumeScalar > event1.volumeScalar)
481-
482-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
483-
expectation.fulfill()
484-
}
485-
486-
wait(for: [expectation], timeout: 1.0)
487-
}
488-
489-
// MARK: - Output Device Switch
490-
491-
func testHUDShowsWhenOutputDeviceSwitched() {
492-
let expectation = XCTestExpectation(
493-
description: "HUD should be visible when output device is switched")
494-
495-
NotificationCenter.default.post(
496-
name: NSNotification.Name("AudioDeviceChanged"), object: nil)
497-
498-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
499-
expectation.fulfill()
500-
}
501-
502-
wait(for: [expectation], timeout: 1.0)
503-
}
504-
505-
func testHUDDisplaysNewDeviceNameAfterSwitch() {
506-
let expectation = XCTestExpectation(
507-
description: "HUD should display new device name after switching")
508-
let newDeviceName = "External Speakers"
509-
510-
mockAudioDeviceManager?.setDefaultOutputDevice(name: newDeviceName)
511-
512-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
513-
expectation.fulfill()
514-
}
515-
516-
wait(for: [expectation], timeout: 1.0)
517-
}
518-
519-
func testHUDUpdatesWhenMultipleDevicesAvailable() {
520-
let expectation = XCTestExpectation(
521-
description: "HUD should update when switching between multiple devices")
522-
523-
mockAudioDeviceManager?.addDevice(name: "Internal Speaker")
524-
mockAudioDeviceManager?.addDevice(name: "External Speaker")
525-
mockAudioDeviceManager?.switchToDevice(name: "External Speaker")
526-
527-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
528-
expectation.fulfill()
529-
}
530-
531-
wait(for: [expectation], timeout: 1.0)
532-
}
533-
534-
// MARK: - Volume Change
535-
536-
func testHUDShowsWhenVolumeChanges() {
537-
let expectation = XCTestExpectation(
538-
description: "HUD should be visible when volume changes")
539-
540-
_ = HUDEvent(volumeScalar: 0.75, deviceName: "Test Speaker", isUnsupported: false)
541-
542-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
543-
expectation.fulfill()
544-
}
545-
546-
wait(for: [expectation], timeout: 1.0)
547-
}
548-
549-
func testHUDDisplaysCorrectVolumeLevel() {
550-
let expectation = XCTestExpectation(description: "HUD should display correct volume level")
551-
let testVolume: CGFloat = 0.65
552-
553-
let volumeEvent = HUDEvent(
554-
volumeScalar: testVolume, deviceName: "Speaker", isUnsupported: false)
555-
XCTAssertEqual(volumeEvent.volumeScalar, testVolume)
556-
557-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
558-
expectation.fulfill()
559-
}
560-
561-
wait(for: [expectation], timeout: 1.0)
562-
}
563-
564-
func testHUDShowsWhenVolumeGoesToZero() {
565-
let expectation = XCTestExpectation(
566-
description: "HUD should show when volume goes to zero (mute)")
567-
568-
let muteEvent = HUDEvent(volumeScalar: 0.0, deviceName: "Speaker", isUnsupported: false)
569-
XCTAssertEqual(muteEvent.volumeScalar, 0.0)
570-
571-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
572-
expectation.fulfill()
573-
}
574-
575-
wait(for: [expectation], timeout: 1.0)
576-
}
577-
578-
func testHUDShowsWhenVolumeGoesToMaximum() {
579-
let expectation = XCTestExpectation(
580-
description: "HUD should show when volume reaches maximum")
581-
582-
let maxVolumeEvent = HUDEvent(
583-
volumeScalar: 1.0, deviceName: "Speaker", isUnsupported: false)
584-
XCTAssertEqual(maxVolumeEvent.volumeScalar, 1.0)
585-
586-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
587-
expectation.fulfill()
588-
}
589-
590-
wait(for: [expectation], timeout: 1.0)
591-
}
592-
593-
func testHUDUpdatesWithIncrementalVolumeChanges() {
594-
let expectation = XCTestExpectation(
595-
description: "HUD should update with incremental volume changes")
596-
597-
let volumes: [CGFloat] = [0.0, 0.25, 0.5, 0.75, 1.0]
598-
var updateCount = 0
599-
600-
for volume in volumes {
601-
let event = HUDEvent(volumeScalar: volume, deviceName: "Speaker", isUnsupported: false)
602-
XCTAssertEqual(event.volumeScalar, volume)
603-
updateCount += 1
604-
}
605-
606-
XCTAssertEqual(updateCount, volumes.count)
607-
608-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
609-
expectation.fulfill()
610-
}
611-
612-
wait(for: [expectation], timeout: 1.0)
613-
}
614-
615327
// MARK: - Combined Scenarios
616328

617329
func testHUDShowsForAllThreeScenarios() {

VolumeGridTests/LaunchAtLoginControllerTests.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ final class LaunchAtLoginControllerTests: XCTestCase {
3737

3838
// MARK: - isEnabled() Tests
3939

40-
func testIsEnabledReturnsBool() {
41-
let _ = mockController.isEnabled()
42-
}
43-
44-
func testIsEnabledCallableMultipleTimes() {
45-
let _ = mockController.isEnabled()
46-
let _ = mockController.isEnabled()
47-
}
48-
4940
func testIsEnabledReturnsInitialFalse() {
5041
XCTAssertFalse(mockController.isEnabled())
5142
}

0 commit comments

Comments
 (0)