Avoid automatic open of generated docx in unit tests

This commit is contained in:
2026-01-21 19:40:25 +02:00
parent 334b009749
commit c9e1d3ab67

View File

@@ -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(())
}