feat: adiciona funcionalidade de remoção de faixas externas e atualiza o layout da UI
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
use crate::domain::entities::Project;
|
||||
use crate::domain::value_objects::TrackId;
|
||||
use anyhow::{Result, anyhow};
|
||||
|
||||
/// Remove uma faixa externa do projeto pelo seu TrackId.
|
||||
pub struct RemoveTrack;
|
||||
|
||||
impl RemoveTrack {
|
||||
pub fn execute(project: &mut Project, id: TrackId) -> Result<()> {
|
||||
if project.remove_track(id) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("Faixa com id {:?} não encontrada.", id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::domain::entities::{AudioTrack, MkvOutput, Project, Track, VideoFile};
|
||||
use crate::domain::value_objects::{FilePath, SyncOffset, TrackId, TrackLanguage};
|
||||
|
||||
fn make_project() -> Project {
|
||||
Project::new(
|
||||
VideoFile::new(FilePath::from("input.mkv")),
|
||||
MkvOutput::new(FilePath::from("output.mkv")),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_faixa_existente() {
|
||||
let mut project = make_project();
|
||||
let id = project.next_track_id();
|
||||
project.tracks.push(Track::Audio(AudioTrack::new(
|
||||
id,
|
||||
FilePath::from("audio.aac"),
|
||||
SyncOffset::from_ms(0),
|
||||
TrackLanguage::new("por").unwrap(),
|
||||
)));
|
||||
assert_eq!(project.tracks.len(), 1);
|
||||
|
||||
RemoveTrack::execute(&mut project, id).unwrap();
|
||||
assert!(project.tracks.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn erro_se_id_inexistente() {
|
||||
let mut project = make_project();
|
||||
let result = RemoveTrack::execute(&mut project, TrackId::new(99));
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user