add credentials screen
This commit is contained in:
1 parent
b1c8762981
commit
31edd55b0a
5 files changed
+206
-5
No files matched your search
+55
-4
@@ -18,7 +18,7 @@ mod test_data;
|
||||
|
||||
use config::AppConfig;
|
||||
use session::AppSession;
|
||||
use screens::{HomeScreen, UnlockScreen, WelcomeScreen};
|
||||
use screens::{CredentialsScreen, HomeScreen, Screen, UnlockScreen, WelcomeScreen};
|
||||
|
||||
struct CreddyApp {}
|
||||
|
||||
@@ -34,9 +34,14 @@ impl Render for CreddyApp {
|
||||
AppSession::Locked => window
|
||||
.use_keyed_state("unlock", cx, |window, cx| UnlockScreen::new(window, cx))
|
||||
.into_any_element(),
|
||||
AppSession::Unlocked { .. } => window
|
||||
.use_keyed_state("home", cx, |_, _| HomeScreen {})
|
||||
.into_any_element(),
|
||||
AppSession::Unlocked { .. } => match cx.global::<Screen>() {
|
||||
Screen::Home => window
|
||||
.use_keyed_state("home", cx, |_, _| HomeScreen {})
|
||||
.into_any_element(),
|
||||
Screen::Credentials => window
|
||||
.use_keyed_state("credentials", cx, |_, cx| CredentialsScreen::new(cx))
|
||||
.into_any_element(),
|
||||
},
|
||||
};
|
||||
|
||||
let theme = cx.omarchy();
|
||||
@@ -54,10 +59,12 @@ fn launch(cx: &mut App, config: AppConfig, session: AppSession) -> WindowHandle<
|
||||
gpui_omarchy::init(cx);
|
||||
cx.set_global(config);
|
||||
cx.set_global(session);
|
||||
cx.set_global(Screen::Home);
|
||||
// refresh_windows() forces everything to re-render, which is kind of a nuclear solution,
|
||||
// but these values aren't expected to change very frequently, so it shouldn't be a problem
|
||||
cx.observe_global::<AppConfig>(|cx| cx.refresh_windows()).detach();
|
||||
cx.observe_global::<AppSession>(|cx| cx.refresh_windows()).detach();
|
||||
cx.observe_global::<Screen>(|cx| cx.refresh_windows()).detach();
|
||||
|
||||
cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| CreddyApp {}))
|
||||
.expect("open window")
|
||||
@@ -83,6 +90,7 @@ mod tests {
|
||||
use gpui_kit::{AnyWindowHandle, TestAppContext};
|
||||
use gpui_kit::test::TestWindowExt;
|
||||
use super::*;
|
||||
use crate::credentials::AwsCredential;
|
||||
use crate::test_data::{TEST_PASSPHRASE, TestEnv};
|
||||
|
||||
/// Start the app against the test environment, as `main` would.
|
||||
@@ -225,4 +233,47 @@ mod tests {
|
||||
assert_eq!(error_message(window, cx).as_deref(), Some("Passphrase is empty."));
|
||||
assert!(!is_unlocked(cx));
|
||||
}
|
||||
|
||||
fn is_visible(window: AnyWindowHandle, id: &'static str, cx: &mut TestAppContext) -> bool {
|
||||
cx.update_window(window, |_, window, _| window.try_find(id).is_some()).unwrap()
|
||||
}
|
||||
|
||||
#[gpui_kit::test]
|
||||
fn test_credentials_navigation(cx: &mut TestAppContext) {
|
||||
let env = TestEnv::new().unwrap();
|
||||
env.db().unwrap();
|
||||
let window = open_app(&env, cx);
|
||||
fill(window, "passphrase", TEST_PASSPHRASE, cx);
|
||||
click(window, "submit", cx);
|
||||
|
||||
click(window, "credentials", cx);
|
||||
assert_eq!(cx.read(|cx| *cx.global::<Screen>()), Screen::Credentials);
|
||||
assert!(is_visible(window, "back", cx));
|
||||
|
||||
click(window, "back", cx);
|
||||
assert_eq!(cx.read(|cx| *cx.global::<Screen>()), Screen::Home);
|
||||
assert!(is_visible(window, "credentials", cx));
|
||||
}
|
||||
|
||||
#[gpui_kit::test]
|
||||
fn test_credentials_tabs(cx: &mut TestAppContext) {
|
||||
let env = TestEnv::new().unwrap();
|
||||
let cred = AwsCredential {
|
||||
access_key_id: "AKIAEXAMPLE".into(),
|
||||
secret_access_key: "EXAMPLESECRET".into(),
|
||||
};
|
||||
env.db().unwrap().save_aws_credential("work", &cred).unwrap();
|
||||
let window = open_app(&env, cx);
|
||||
fill(window, "passphrase", TEST_PASSPHRASE, cx);
|
||||
click(window, "submit", cx);
|
||||
click(window, "credentials", cx);
|
||||
|
||||
assert!(is_visible(window, "work", cx));
|
||||
|
||||
act(window, cx, |window, cx| window.within("credential-tabs").click(1usize, cx));
|
||||
assert!(!is_visible(window, "work", cx));
|
||||
|
||||
act(window, cx, |window, cx| window.within("credential-tabs").click(0usize, cx));
|
||||
assert!(is_visible(window, "work", cx));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user