From c9e1d3ab67379650f2e45e897045704645097c73 Mon Sep 17 00:00:00 2001 From: stefiosif Date: Wed, 21 Jan 2026 19:40:25 +0200 Subject: [PATCH] Avoid automatic open of generated docx in unit tests --- src-tauri/src/export.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/export.rs b/src-tauri/src/export.rs index e56502d..6ab04c1 100644 --- a/src-tauri/src/export.rs +++ b/src-tauri/src/export.rs @@ -34,7 +34,7 @@ impl Export for MonthlySchedule { ) -> anyhow::Result<()> { match file_type { FileType::Txt => self.export_as_txt(config, tracker)?, - FileType::Docx => self.export_as_doc(config)?, + FileType::Docx => self.export_as_docx(config)?, }; Ok(()) @@ -51,18 +51,13 @@ impl MonthlySchedule { let mut writer = std::io::BufWriter::new(file); writer.write_all(self.pretty_print(config).as_bytes())?; - writer.write_all(self.report(config, tracker).as_bytes())?; - writer.flush()?; Ok(()) } - pub fn export_as_doc(&self, config: &UserConfig) -> anyhow::Result<()> { - let path = std::path::Path::new("rota.docx"); - let file = std::fs::File::create(path)?; - + pub fn generate_docx(&self, config: &UserConfig) -> Docx { let header = Table::new(vec![ TableRow::new(vec![TableCell::new().add_paragraph( Paragraph::new() @@ -159,6 +154,13 @@ impl MonthlySchedule { } doc = doc.add_table(residents_table); + doc + } + + pub fn export_as_docx(&self, config: &UserConfig) -> anyhow::Result<()> { + let path = std::path::Path::new("rota.docx"); + let file = std::fs::File::create(path)?; + let doc = self.generate_docx(config); doc.build().pack(file)?; @@ -229,14 +231,14 @@ mod tests { } #[rstest] - pub fn test_export_as_doc( + pub fn test_generate_docx( mut schedule: MonthlySchedule, mut tracker: WorkloadTracker, scheduler: Scheduler, ) -> anyhow::Result<()> { assert!(scheduler.run(&mut schedule, &mut tracker)?); - schedule.export(FileType::Docx, &scheduler.config, &tracker)?; + schedule.generate_docx(&scheduler.config); Ok(()) }