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