mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 19:14:26 +00:00
- top-w3: written by an agent - top-w3: review fixes (review-1) - top-w3: remove sits beside lookup and insert in draft.rs (review-1 item 5)
100 lines
5.1 KiB
Rust
100 lines
5.1 KiB
Rust
//! New Workspace and Delete Workspace answer what `WorkspaceAsk` asks, with the set's refusals.
|
|
|
|
use craft_behavior::dock::{NamedWorkspace, Workspace, WorkspaceChrome, WorkspaceKeeps, WorkspaceSet};
|
|
use craft_ui::dialog::{DialogHost, DialogResult, StackDialog};
|
|
use craft_ui::patterns::dock::{DeleteWorkspaceDialog, HostedNewWorkspace, NewWorkspace, NewWorkspaceDialog};
|
|
use craft_ui::testing::{Fixture, trial};
|
|
use egui::Vec2;
|
|
use serde_json::json;
|
|
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
|
|
/// Essentials built in; Review and Mine saved, Mine current.
|
|
fn workspaces() -> WorkspaceSet<u32> {
|
|
let mut set = WorkspaceSet::new(vec![NamedWorkspace::new("essentials", "Essentials", Workspace::default())]);
|
|
for name in ["Review", "Mine"] {
|
|
set.save(name, Workspace::default(), WorkspaceChrome::default(), WorkspaceKeeps::NONE).unwrap();
|
|
}
|
|
set
|
|
}
|
|
|
|
fn shows(fixture: &Fixture, text: &str) -> bool {
|
|
fixture.texts().iter().any(|painted| painted.text == text)
|
|
}
|
|
|
|
fn disabled(fixture: &Fixture, label: &str) -> bool {
|
|
let target = fixture.by_label(label).unwrap_or_else(|| panic!("{label} is shown"));
|
|
fixture.tree().is_disabled_key(target.node)
|
|
}
|
|
|
|
#[trial]
|
|
fn new_workspace_refuses_a_built_in_name_and_answers_a_new_one_with_its_captures() {
|
|
let answers: Rc<RefCell<Vec<NewWorkspace>>> = Rc::default();
|
|
let seen = answers.clone();
|
|
let set = workspaces();
|
|
let mut fixture = Fixture::new(move |ui| seen.borrow_mut().extend(NewWorkspaceDialog::new(&set).show(ui).accepted));
|
|
fixture.idle(30);
|
|
assert!(disabled(&fixture, "OK"), "OK waits for a name");
|
|
let name = fixture.by_label("Name").expect("the dialog asks for a name");
|
|
fixture.click(&name).idle(4);
|
|
fixture.type_text("essentials").idle(4);
|
|
assert!(shows(&fixture, "A built-in workspace has this name."), "a built-in's name says why it is refused");
|
|
assert!(disabled(&fixture, "OK"), "and OK refuses it");
|
|
fixture.type_text(" 2").idle(4);
|
|
let toolbar = fixture.by_label("Toolbar").expect("the Capture group offers Toolbar");
|
|
fixture.click(&toolbar).idle(4);
|
|
let ok = fixture.by_label("OK").unwrap();
|
|
fixture.click(&ok).idle(10);
|
|
let answers = answers.borrow();
|
|
assert_eq!(answers.len(), 1, "OK answers once");
|
|
assert_eq!(answers[0].name, "essentials 2");
|
|
assert_eq!(answers[0].keeps, WorkspaceKeeps::new(false, false, true), "the boxes that were on are the captures");
|
|
}
|
|
|
|
#[trial]
|
|
fn delete_workspace_answers_the_picked_saved_workspace_and_refuses_the_current_one() {
|
|
let answers: Rc<RefCell<Vec<String>>> = Rc::default();
|
|
let seen = answers.clone();
|
|
let set = workspaces();
|
|
let mut fixture = Fixture::new(move |ui| seen.borrow_mut().extend(DeleteWorkspaceDialog::new(&set).show(ui).accepted));
|
|
fixture.idle(30);
|
|
let list = fixture.by_label("Workspace").expect("the dialog lists the saved workspaces");
|
|
fixture.click(&list).idle(10);
|
|
assert!(disabled(&fixture, "Mine"), "the current workspace is listed disabled");
|
|
assert!(!disabled(&fixture, "Review"), "the others can be picked");
|
|
let review = fixture.by_label("Review").unwrap();
|
|
fixture.click(&review).idle(10);
|
|
let ok = fixture.by_label("OK").unwrap();
|
|
fixture.click(&ok).idle(10);
|
|
assert_eq!(*answers.borrow(), ["review"], "the pick starts on the first saved workspace that is not current");
|
|
}
|
|
|
|
#[trial]
|
|
fn the_hosted_new_workspace_refuses_a_built_in_name_and_answers_through_the_host() {
|
|
type Hosted = HostedNewWorkspace<u32>;
|
|
let host = Rc::new(RefCell::new(DialogHost::new()));
|
|
let shown = Rc::clone(&host);
|
|
let mut fixture = Fixture::new(move |ui| shown.borrow_mut().run(ui));
|
|
fixture.room(Vec2::new(1400.0, 1000.0));
|
|
let id = host.borrow_mut().open(HostedNewWorkspace::new(&workspaces()));
|
|
fixture.idle(10);
|
|
let ctx = fixture.ctx().clone();
|
|
|
|
let fields = host.borrow().get::<Hosted>().and_then(|dialog| dialog.json_fields()).expect("the dialog lists its fields");
|
|
let mut names: Vec<&str> = fields.as_object().expect("an object").keys().map(String::as_str).collect();
|
|
names.sort();
|
|
assert_eq!(names, ["keyboardShortcuts", "menus", "name", "toolbar"]);
|
|
|
|
host.borrow_mut().set_json_field(&ctx, id, "name", json!("essentials")).expect("the name field takes text");
|
|
assert!(!host.borrow_mut().confirm::<Hosted>(&ctx), "a built-in's name is refused as the drawn OK refuses it");
|
|
assert!(host.borrow().is_open::<Hosted>(), "a refused confirm keeps the dialog open");
|
|
|
|
host.borrow_mut().set_json_field(&ctx, id, "name", json!("Mine 2")).expect("the name field takes text");
|
|
host.borrow_mut().set_json_field(&ctx, id, "toolbar", json!(true)).expect("the toolbar box is offered");
|
|
assert!(host.borrow_mut().set_json_field(&ctx, id, "menus", json!("yes")).is_err(), "a box takes a bool");
|
|
assert!(host.borrow_mut().confirm::<Hosted>(&ctx), "a new name is accepted");
|
|
let answer = host.borrow_mut().take::<Hosted>().and_then(DialogResult::ok).expect("the answer reaches the app");
|
|
assert_eq!(answer.name, "Mine 2");
|
|
assert_eq!(answer.keeps, WorkspaceKeeps::new(false, false, true), "the boxes set through the fields are the captures");
|
|
}
|