removed unused import and fixed tests for swift testing
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
|
||||
@@ -41,9 +41,9 @@ protocol AudioPlayerProtocol: AnyObject {
|
||||
var playbackURL: URL? { get }
|
||||
var state: MediaPlayerState { get }
|
||||
var playbackSpeed: Float { get }
|
||||
|
||||
|
||||
var actions: AnyPublisher<AudioPlayerAction, Never> { get }
|
||||
|
||||
|
||||
func load(sourceURL: URL, playbackURL: URL, autoplay: Bool)
|
||||
func reset()
|
||||
func play()
|
||||
|
||||
@@ -37,12 +37,12 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
/// updates are delayed by a fixed amount of time
|
||||
@Published private(set) var playerButtonPlaybackState: AudioPlayerPlaybackState
|
||||
@Published private(set) var playbackSpeed: VoiceMessagePlaybackSpeed
|
||||
|
||||
|
||||
private weak var audioPlayer: AudioPlayerProtocol?
|
||||
private var audioPlayerSubscription: AnyCancellable?
|
||||
private var playbackStateSubscription: AnyCancellable?
|
||||
private var displayLink: CADisplayLink?
|
||||
|
||||
|
||||
/// The file url that the last player attached to this object has loaded.
|
||||
/// The file url persists even if the AudioPlayer will be detached later.
|
||||
private(set) var fileURL: URL?
|
||||
@@ -58,7 +58,7 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
var isPublishingProgress: Bool {
|
||||
displayLink != nil
|
||||
}
|
||||
|
||||
|
||||
init(id: AudioPlayerStateIdentifier, title: String,
|
||||
duration: Double,
|
||||
waveform: EstimatedWaveform? = nil,
|
||||
@@ -119,7 +119,7 @@ class AudioPlayerState: ObservableObject, Identifiable {
|
||||
func reportError() {
|
||||
playbackState = .error
|
||||
}
|
||||
|
||||
|
||||
func setPlaybackSpeed(_ speed: VoiceMessagePlaybackSpeed) {
|
||||
playbackSpeed = speed
|
||||
audioPlayer?.setPlaybackSpeed(speed.rawValue)
|
||||
|
||||
@@ -275,29 +275,23 @@ struct AudioPlayerStateTests {
|
||||
#expect(!audioPlayerState.showProgressIndicator)
|
||||
}
|
||||
|
||||
func testSetPlaybackSpeed() {
|
||||
@Test
|
||||
func setPlaybackSpeed() {
|
||||
audioPlayerState.attachAudioPlayer(audioPlayerMock)
|
||||
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 1.0)
|
||||
#expect(audioPlayerState.playbackSpeed == .default)
|
||||
|
||||
audioPlayerState.setPlaybackSpeed(1.5)
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 1.5)
|
||||
XCTAssertEqual(audioPlayerMock.setPlaybackSpeedReceivedSpeed, 1.5)
|
||||
audioPlayerState.setPlaybackSpeed(.fast)
|
||||
#expect(audioPlayerState.playbackSpeed == .fast)
|
||||
#expect(audioPlayerMock.setPlaybackSpeedReceivedSpeed == 1.5)
|
||||
|
||||
audioPlayerState.setPlaybackSpeed(2.0)
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 2.0)
|
||||
XCTAssertEqual(audioPlayerMock.setPlaybackSpeedReceivedSpeed, 2.0)
|
||||
audioPlayerState.setPlaybackSpeed(.fastest)
|
||||
#expect(audioPlayerState.playbackSpeed == .fastest)
|
||||
#expect(audioPlayerMock.setPlaybackSpeedReceivedSpeed == 2.0)
|
||||
|
||||
audioPlayerState.setPlaybackSpeed(0.5)
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 0.5)
|
||||
XCTAssertEqual(audioPlayerMock.setPlaybackSpeedReceivedSpeed, 0.5)
|
||||
}
|
||||
|
||||
func testSetPlaybackSpeedWithoutPlayer() {
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 1.0)
|
||||
|
||||
audioPlayerState.setPlaybackSpeed(2.0)
|
||||
XCTAssertEqual(audioPlayerState.playbackSpeed, 2.0)
|
||||
audioPlayerState.setPlaybackSpeed(.slow)
|
||||
#expect(audioPlayerState.playbackSpeed == .slow)
|
||||
#expect(audioPlayerMock.setPlaybackSpeedReceivedSpeed == 0.5)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user