Skip to content

Commit e799702

Browse files
committed
feat(question): for "load.retry", unify action IDs from yes no to Yes No
while using with_action_ids For consistency, apply the refactoring also to question test cases
1 parent 0bd7518 commit e799702

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

rust/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/agama-autoinstall/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ tempfile = "3.20.0"
1313
thiserror = "2.0.12"
1414
tokio = "1.46.0"
1515
url = "2.5.4"
16+
agama-l10n = { path = "../agama-l10n" }

rust/agama-autoinstall/src/questions.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
//! This module offers a mechanism to ask questions to users.
2222
23+
use agama_l10n::helpers::gettext_noop;
2324
use agama_lib::{http::BaseHTTPClient, questions::http_client::HTTPClient as QuestionsHTTPClient};
2425
use agama_utils::api::question::QuestionSpec;
2526

@@ -37,12 +38,12 @@ impl UserQuestions {
3738
/// Asks the user whether to retry loading the profile.
3839
pub async fn should_retry(&self, text: &str, error: &str) -> anyhow::Result<bool> {
3940
let question = QuestionSpec::new(text, "load.retry")
40-
.with_actions(&[("yes", "Yes"), ("no", "No")])
41-
.with_default_action("no")
41+
.with_action_ids(&[gettext_noop("Yes"), gettext_noop("No")])
42+
.with_default_action("No")
4243
.with_data(&[("error", error)]);
4344

4445
let question = self.questions.create_question(&question).await?;
4546
let answer = self.questions.get_answer(question.id).await?;
46-
Ok(answer.action == "yes")
47+
Ok(answer.action == "Yes")
4748
}
4849
}

rust/agama-utils/src/api/question.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -403,55 +403,55 @@ mod tests {
403403
fn test_string_question() {
404404
let q = QuestionSpec::new("Please, enter a username", "username")
405405
.as_string()
406-
.with_actions(&[("next", "Next"), ("cancel", "Cancel")]);
406+
.with_action_ids(&[gettext_noop("Next"), gettext_noop("Cancel")]);
407407

408408
let q_str = serde_json::to_string_pretty(&q).unwrap();
409409
println!("{}", &q_str);
410410
assert!(matches!(q.field, QuestionField::String));
411-
assert_eq!(q.actions[0], Action::new("next", "Next"));
412-
assert_eq!(q.actions[1], Action::new("cancel", "Cancel"));
411+
assert_eq!(q.actions[0], Action::new("Next", "Next"));
412+
assert_eq!(q.actions[1], Action::new("Cancel", "Cancel"));
413413
}
414414

415415
#[test]
416416
fn test_password_question() {
417417
let q = QuestionSpec::new("Decrypt the device", "luks")
418418
.as_password()
419-
.with_actions(&[("decrypt", "Decrypt"), ("skip", "Skip")]);
419+
.with_action_ids(&[gettext_noop("Decrypt"), gettext_noop("Skip")]);
420420

421421
let q_str = serde_json::to_string_pretty(&q).unwrap();
422422
println!("{}", &q_str);
423423
assert!(matches!(q.field, QuestionField::Password));
424-
assert_eq!(q.actions[0], Action::new("decrypt", "Decrypt"));
425-
assert_eq!(q.actions[1], Action::new("skip", "Skip"));
424+
assert_eq!(q.actions[0], Action::new("Decrypt", "Decrypt"));
425+
assert_eq!(q.actions[1], Action::new("Skip", "Skip"));
426426
}
427427

428428
#[test]
429429
fn test_select_question() {
430430
let q = QuestionSpec::new("There is a solver conflict...", "conflict")
431431
.as_select(&[("opt1", "Option 1"), ("opt2", "Option 2")])
432-
.with_actions(&[("decrypt", "Decrypt"), ("skip", "Skip")]);
432+
.with_action_ids(&[gettext_noop("Decrypt"), gettext_noop("Skip")]);
433433

434434
let q_str = serde_json::to_string_pretty(&q).unwrap();
435435
println!("{}", &q_str);
436436
assert!(matches!(
437437
q.field,
438438
QuestionField::Select { options: _options }
439439
));
440-
assert_eq!(q.actions[0], Action::new("decrypt", "Decrypt"));
441-
assert_eq!(q.actions[1], Action::new("skip", "Skip"));
440+
assert_eq!(q.actions[0], Action::new("Decrypt", "Decrypt"));
441+
assert_eq!(q.actions[1], Action::new("Skip", "Skip"));
442442
}
443443

444444
#[test]
445445
fn test_answers_to() {
446446
let answer = Answer {
447-
action: "cancel".to_string(),
447+
action: "Cancel".to_string(),
448448
value: None,
449449
};
450450

451451
let q = QuestionSpec::new("Please, enter a username", "username")
452452
.as_string()
453453
.with_data(&[("id", "1")])
454-
.with_actions(&[("next", "Next"), ("cancel", "Cancel")]);
454+
.with_action_ids(&[gettext_noop("Next"), gettext_noop("Cancel")]);
455455

456456
let rule_by_text = AnswerRule {
457457
text: Some("Please, enter a username".to_string()),

rust/agama-utils/src/question/start.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ mod tests {
4444
question::{Answer, AnswerRule, Config, Policy, QuestionSpec},
4545
Event,
4646
},
47+
gettext_noop,
4748
question::{self, message},
4849
};
4950
use tokio::sync::broadcast;
5051

5152
fn build_question_spec() -> QuestionSpec {
5253
QuestionSpec::new("Do you want to continue?", "continue")
53-
.with_actions(&[("yes", "Yes"), ("no", "No")])
54-
.with_default_action("no")
54+
.with_action_ids(&[gettext_noop("Yes"), gettext_noop("No")])
55+
.with_default_action("No")
5556
}
5657

5758
#[tokio::test]
@@ -67,7 +68,7 @@ mod tests {
6768

6869
// Answer the question
6970
let answer = Answer {
70-
action: "yes".to_string(),
71+
action: "Yes".to_string(),
7172
value: None,
7273
};
7374
questions
@@ -119,7 +120,7 @@ mod tests {
119120

120121
// Define a rule and an answer.
121122
let answer = Answer {
122-
action: "no".to_string(),
123+
action: "No".to_string(),
123124
value: None,
124125
};
125126
let rule_by_class = AnswerRule {

0 commit comments

Comments
 (0)