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
Original file line number Diff line number Diff line change
Expand Up @@ -237,42 +237,4 @@ pub async fn devices<'a>(
}

#[cfg(test)]
mod tests {
//! What a device's "Sign out" button is named.
use super::*;
use sourceorigin_common::events::{Browser, Platform};

/// Two devices of one name get Sign out buttons of different names, from
/// what their rows show: here, where they were last seen and when they
/// signed in.
#[test]
fn devices_of_one_name_are_signed_out_by_different_names() {
let now = Utc::now();
let firefox = DeviceRow {
id: SessionId::new(),
current: false,
device: Some(UserAgentFamily {
browser: Browser::Firefox,
platform: Platform::Linux,
}),
ip: Some(IpAddr::from([192, 0, 2, 1])),
methods: &[AuthenticationMethod::Passkey],
authenticated_at: now - TimeDelta::days(3),
last_seen_at: now,
dashboard: &[],
};
let other = DeviceRow {
id: SessionId::new(),
ip: Some(IpAddr::from([192, 0, 2, 2])),
authenticated_at: now - TimeDelta::days(1),
..firefox
};
let label = firefox.sign_out_label(now);
assert!(
label.starts_with("Sign out Firefox on Linux, Passkey, 192.0.2.1, "),
"{label}"
);
assert!(!label.contains('·'), "{label}");
assert_ne!(label, other.sign_out_label(now));
}
}
mod tests;
37 changes: 37 additions & 0 deletions crates/ui/src/settings/sessions/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! What a device's "Sign out" button is named.
use super::*;
use sourceorigin_common::events::{Browser, Platform};

/// Two devices of one name get Sign out buttons of different names, from
/// what their rows show: here, where they were last seen and when they
/// signed in.
#[test]
fn devices_of_one_name_are_signed_out_by_different_names() {
let now = Utc::now();
let firefox = DeviceRow {
id: SessionId::new(),
current: false,
device: Some(UserAgentFamily {
browser: Browser::Firefox,
platform: Platform::Linux,
}),
ip: Some(IpAddr::from([192, 0, 2, 1])),
methods: &[AuthenticationMethod::Passkey],
authenticated_at: now - TimeDelta::days(3),
last_seen_at: now,
dashboard: &[],
};
let other = DeviceRow {
id: SessionId::new(),
ip: Some(IpAddr::from([192, 0, 2, 2])),
authenticated_at: now - TimeDelta::days(1),
..firefox
};
let label = firefox.sign_out_label(now);
assert!(
label.starts_with("Sign out Firefox on Linux, Passkey, 192.0.2.1, "),
"{label}"
);
assert!(!label.contains('·'), "{label}");
assert_ne!(label, other.sign_out_label(now));
}