move test account creation & apply to global popup

Signed-off-by: kernelkind <kernelkind@gmail.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
kernelkind
2024-05-17 11:47:43 -04:00
committed by William Casarin
parent 17d0c97c78
commit 88a3a2d088
3 changed files with 41 additions and 38 deletions

View File

@@ -1,6 +1,8 @@
use enostr::RelayPool;
use enostr::{FullKeypair, Pubkey, RelayPool};
use nostrdb::ProfileRecord;
use crate::account_manager::UserAccount;
#[allow(unused_must_use)]
pub fn sample_pool() -> RelayPool {
let mut pool = RelayPool::new();
@@ -54,3 +56,33 @@ const TEST_PROFILE_DATA: [u8; 448] = [
pub fn test_profile_record() -> ProfileRecord<'static> {
ProfileRecord::new_owned(&TEST_PROFILE_DATA).unwrap()
}
const TEN_ACCOUNT_HEXES: [&str; 10] = [
"3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
"bd1e19980e2c91e6dc657e92c25762ca882eb9272d2579e221f037f93788de91",
"5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"4c96d763eb2fe01910f7e7220b7c7ecdbe1a70057f344b9f79c28af080c3ee30",
"edf16b1dd61eab353a83af470cc13557029bff6827b4cb9b7fc9bdb632a2b8e6",
"3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
];
pub fn get_test_accounts() -> Vec<UserAccount> {
TEN_ACCOUNT_HEXES
.iter()
.map(|account_hex| {
let key = FullKeypair::new(
Pubkey::from_hex(account_hex).unwrap(),
FullKeypair::generate().secret_key,
);
UserAccount {
key,
relays: sample_pool(),
}
})
.collect()
}

View File

@@ -285,51 +285,21 @@ impl<'a> AccountSelectionWidget<'a> {
// PREVIEWS
mod preview {
use enostr::{FullKeypair, Pubkey};
use nostrdb::{Config, Ndb};
use super::*;
use crate::imgcache::ImageCache;
use crate::key_storage::KeyStorage;
use crate::relay_generation::RelayGenerator;
use crate::{imgcache::ImageCache, test_data};
use crate::test_data;
use std::path::Path;
const ACCOUNT_HEXES: [&str; 10] = [
"3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
"bd1e19980e2c91e6dc657e92c25762ca882eb9272d2579e221f037f93788de91",
"5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"4c96d763eb2fe01910f7e7220b7c7ecdbe1a70057f344b9f79c28af080c3ee30",
"edf16b1dd61eab353a83af470cc13557029bff6827b4cb9b7fc9bdb632a2b8e6",
"3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
];
pub struct AccountManagementPreview {
accounts: Vec<UserAccount>,
ndb: Ndb,
img_cache: ImageCache,
}
fn get_accounts() -> Vec<UserAccount> {
ACCOUNT_HEXES
.iter()
.map(|account_hex| {
let key = FullKeypair::new(
Pubkey::from_hex(account_hex).unwrap(),
FullKeypair::generate().secret_key,
);
UserAccount {
key,
relays: test_data::sample_pool(),
}
})
.collect()
}
fn get_ndb_and_img_cache() -> (Ndb, ImageCache) {
let mut config = Config::new();
config.set_ingester_threads(2);
@@ -344,7 +314,7 @@ mod preview {
impl AccountManagementPreview {
fn new() -> Self {
let accounts = get_accounts();
let accounts = test_data::get_test_accounts();
let (ndb, img_cache) = get_ndb_and_img_cache();
AccountManagementPreview {
@@ -388,7 +358,7 @@ mod preview {
impl AccountSelectionPreview {
fn new() -> Self {
let accounts = get_accounts();
let accounts = test_data::get_test_accounts();
let (ndb, img_cache) = get_ndb_and_img_cache();
AccountSelectionPreview {
accounts,

View File

@@ -91,6 +91,7 @@ impl<'a> DesktopGlobalPopup<'a> {
mod preview {
use crate::{
test_data::get_test_accounts,
ui::{DesktopSidePanel, Preview, View},
Damus,
};
@@ -111,9 +112,9 @@ mod preview {
impl GlobalPopupPreview {
fn new() -> Self {
GlobalPopupPreview {
app: Damus::mock("."),
}
let mut app = Damus::mock(".");
app.accounts = get_test_accounts();
GlobalPopupPreview { app }
}
}