upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-03-08 14:37:56 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-03-08 14:39:21 +0000
commit6b3aecbcbde669859533716225e9c3bbfd2023b2 (patch)
tree06258c93893c57ae1ef3b3d709c364f00365fdb5 /test_utils
parent5622e384447fba354548aca0e39dcee3d95951c3 (diff)
feat(send): select commits from a list
when since_or_range isn't specified adds resilience as assuming master..HEAD can cause some issues eg when master is not up-to-date with origin/master
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/src/lib.rs85
1 files changed, 84 insertions, 1 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index b4f0360..2edbc60 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -1,6 +1,6 @@
1use std::{ffi::OsStr, path::PathBuf}; 1use std::{ffi::OsStr, path::PathBuf};
2 2
3use anyhow::{ensure, Context, Result}; 3use anyhow::{bail, ensure, Context, Result};
4use dialoguer::theme::{ColorfulTheme, Theme}; 4use dialoguer::theme::{ColorfulTheme, Theme};
5use directories::ProjectDirs; 5use directories::ProjectDirs;
6use nostr::{self, prelude::FromSkStr, Kind, Tag}; 6use nostr::{self, prelude::FromSkStr, Kind, Tag};
@@ -259,6 +259,20 @@ impl CliTester {
259 i.prompt(false).context("initial confirm prompt")?; 259 i.prompt(false).context("initial confirm prompt")?;
260 Ok(i) 260 Ok(i)
261 } 261 }
262
263 pub fn expect_multi_select(
264 &mut self,
265 prompt: &str,
266 choices: Vec<String>,
267 ) -> Result<CliTesterMultiSelectPrompt> {
268 let mut i = CliTesterMultiSelectPrompt {
269 tester: self,
270 prompt: prompt.to_string(),
271 choices,
272 };
273 i.prompt(false).context("initial confirm prompt")?;
274 Ok(i)
275 }
262} 276}
263 277
264pub struct CliTesterInputPrompt<'a> { 278pub struct CliTesterInputPrompt<'a> {
@@ -448,6 +462,75 @@ impl CliTesterConfirmPrompt<'_> {
448 } 462 }
449} 463}
450 464
465pub struct CliTesterMultiSelectPrompt<'a> {
466 tester: &'a mut CliTester,
467 prompt: String,
468 choices: Vec<String>,
469}
470
471impl CliTesterMultiSelectPrompt<'_> {
472 fn prompt(&mut self, eventually: bool) -> Result<&mut Self> {
473 if eventually {
474 self.tester
475 .expect_eventually(format!("{}:\r\n", self.prompt))
476 .context("expect multi-select prompt eventually")?;
477 } else {
478 self.tester
479 .expect(format!("{}:\r\n", self.prompt))
480 .context("expect multi-select prompt")?;
481 }
482 Ok(self)
483 }
484
485 pub fn succeeds_with(
486 &mut self,
487 chosen_indexes: Vec<usize>,
488 report: bool,
489 default_indexes: Vec<usize>,
490 ) -> Result<&mut Self> {
491 if report {
492 bail!("TODO: add support for report")
493 }
494
495 fn show_options(
496 tester: &mut CliTester,
497 choices: &[String],
498 active_index: usize,
499 selected_indexes: &[usize],
500 ) -> Result<()> {
501 for (index, item) in choices.iter().enumerate() {
502 tester.expect(format!(
503 "{}{}{}\r\n",
504 if active_index.eq(&index) { "> " } else { " " },
505 if selected_indexes.iter().any(|i| i.eq(&index)) {
506 "[x] "
507 } else {
508 "[ ] "
509 },
510 item,
511 ))?;
512 }
513 Ok(())
514 }
515
516 show_options(self.tester, &self.choices, 0, &default_indexes)?;
517
518 if default_indexes.eq(&chosen_indexes) {
519 self.tester.send("\r\n")?;
520 } else {
521 bail!("TODO: add support changing options");
522 }
523
524 for _ in self.choices.iter() {
525 self.tester.expect("\r")?;
526 }
527 // one for removing prompt maybe?
528 self.tester.expect("\r")?;
529
530 Ok(self)
531 }
532}
533
451pub struct CliTesterChoicePrompt<'a> { 534pub struct CliTesterChoicePrompt<'a> {
452 tester: &'a mut CliTester, 535 tester: &'a mut CliTester,
453 prompt: String, 536 prompt: String,