Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ mach2 = "0.6.0"
[dev-dependencies]
insta = "1"
mockall = "0.13"
parking_lot = "0.12"
tempfile = "3"
anyhow = "1"

Expand Down
1 change: 1 addition & 0 deletions src/tui/components/generator_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ mod tests {

#[test]
fn render_embedded_has_no_style_selector() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let state = GeneratorState::new();
let lines = render_generator_panel(&state, true, 56, true);
let style_label = t!("tui.generator.style_label").to_string();
Expand Down
4 changes: 4 additions & 0 deletions src/tui/components/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ mod tests {

#[test]
fn render_text_input_shows_label() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let lines = render_text_input("name", "GitHub", false, false, true, false, 60);
assert_eq!(lines.len(), 1);
}
Expand All @@ -298,13 +299,15 @@ mod tests {

#[test]
fn render_masked_input_shows_dots() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let lines = render_text_input("pass", "secret", false, false, true, true, 60);
let text: String = lines[0].spans.iter().map(|s| s.content.as_ref()).collect();
assert!(text.contains("\u{2022}\u{2022}\u{2022}\u{2022}\u{2022}\u{2022}"));
}

#[test]
fn render_password_input_visible_shows_plaintext() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let buttons = [
PasswordButton {
label: "显示".to_string(),
Expand All @@ -324,6 +327,7 @@ mod tests {

#[test]
fn render_password_input_masked_shows_bullets() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let buttons = [PasswordButton {
label: "显示".to_string(),
focus_variant: PasswordFieldFocus::Show,
Expand Down
10 changes: 6 additions & 4 deletions src/tui/i18n/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,22 @@ pub fn switch_locale(locale: &str) {
}

#[cfg(test)]
static LOCALE_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
static LOCALE_LOCK: parking_lot::ReentrantMutex<()> = parking_lot::const_reentrant_mutex(());

/// RAII guard that serializes locale-dependent tests and restores locale on drop.
/// Uses a process-wide mutex so no two locale-sensitive tests run concurrently.
/// Uses a process-wide reentrant mutex so no two locale-sensitive tests run
/// concurrently, while still allowing a single test to nest guards (e.g. an
/// outer manual guard plus an inner render-helper guard) without deadlocking.
#[cfg(test)]
pub struct LocaleGuard {
original: String,
_lock: std::sync::MutexGuard<'static, ()>,
_lock: parking_lot::ReentrantMutexGuard<'static, ()>,
}

#[cfg(test)]
impl LocaleGuard {
pub fn new(locale: &str) -> Self {
let lock = LOCALE_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let lock = LOCALE_LOCK.lock();
let original = rust_i18n::locale().to_string();
init(locale);
Self {
Expand Down
1 change: 1 addition & 0 deletions src/tui/screens/database_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@ mod tests {

#[test]
fn enter_on_okb_without_path_sets_error() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let mut screen = DatabaseRecoveryScreen::new(DatabaseRecoveryOrigin::StartupKeyOnly);
screen.focus = DatabaseRecoveryFocus::Okb;
screen.mode = DatabaseRecoveryMode::OkbPathInput;
Expand Down
2 changes: 2 additions & 0 deletions src/tui/screens/form/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ mod tests {

#[test]
fn weak_password_dialog_renders_actions_and_newlook_warning_icon() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let backend = TestBackend::new(80, 24);
let mut terminal = Terminal::new(backend).unwrap();
terminal
Expand All @@ -955,6 +956,7 @@ mod tests {

#[test]
fn unfocused_notes_textarea_does_not_render_cursor_style() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let mut state = FormState::new_edit(uuid::Uuid::nil(), CredentialType::Login);
state.fields.name = "Example".into();
state.fields.set_notes_text("internal notes");
Expand Down
1 change: 1 addition & 0 deletions src/tui/screens/key_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ mod tests {

#[test]
fn confirm_with_incomplete_words_sets_inline_error() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let mut screen = KeyRecoveryScreen::new(KeyRecoveryOrigin::OnboardingRestore);
screen.focus = KeyRecoveryFocus::Confirm;
let result = screen.handle_key_for_test(key(KeyCode::Enter));
Expand Down
1 change: 1 addition & 0 deletions src/tui/screens/main/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,7 @@ mod tests {

#[test]
fn render_trash_detail_empty() {
let _guard = crate::tui::i18n::LocaleGuard::en();
let mut state = DetailPanelState::default();
state.set_trash_context(true, 30);
let result = render_detail_snapshot(&state, 60, 20, true, true);
Expand Down
Loading
Loading