chiark / gitweb /
click elsewhere, or on pinned piece, deselects all
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 13 Jan 2021 22:18:12 +0000 (22:18 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 13 Jan 2021 22:18:12 +0000 (22:18 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
templates/script.ts
wdriver/wdt-simple.rs

index a425d421bb765e7eaca4d2d447e54b8a24ff8628..a9320c1e7e8b7af95764fc2a73f956e2d1d0f521 100644 (file)
@@ -671,7 +671,10 @@ function some_mousedown(e : MouseEvent) {
 function drag_mousedown(e : MouseEvent, shifted: boolean) {
   var target = e.target as SVGGraphicsElement; // we check this just now!
   var piece = target.dataset.piece!;
-  if (!piece) { return; }
+  if (!piece) {
+    ungrab_all();    
+    return;
+  }
   let p = pieces[piece]!;
   let held = p.held;
 
@@ -690,6 +693,7 @@ function drag_mousedown(e : MouseEvent, shifted: boolean) {
   } else if (held == null || wresting) {
     if (p.pinned && !wresting) {
       add_log_message('That piece is pinned to the table.');
+      ungrab_all();
       return;
     }
     if (!shifted) {
index 4691cde0874c4cae27324b9639324c11f7c3d6e1..f0a73974873ee3958e05a83b2b0e2c0f69cf6fbf 100644 (file)
@@ -48,19 +48,20 @@ impl Ctx {
   }
 
   #[throws(AE)]
-  fn rotate(&mut self){
+  fn rotate(&mut self) -> &'static str {
+    let pc = "4.1";
     let su = &mut self.su;
 
     let chk = |w: &WindowGuard<'_>| {
       let transform = format!("rotate(-90)");
-      let pd = w.find_element(By::Id("piece4.1"))?;
+      let pd = w.find_element(By::Id(&format!("piece{}",pc)))?;
       ensure_eq!(pd.get_attribute("transform")?, Some(transform));
       Ok::<_,AE>(())
     };
 
     {
       let mut w = su.w(&self.alice)?;
-      let p = w.find_piece("4.1")?;
+      let p = w.find_piece(pc)?;
       let (px,py) = p.posw()?;
       w.action_chain()
         .move_to(px,py)
@@ -80,6 +81,43 @@ impl Ctx {
       w.synch()?;
       chk(&w)?;
     }
+
+    pc
+  }
+
+  #[throws(AE)]
+  fn unselect(&mut self, pc: &'static str) {
+    let su = &mut self.su;
+
+    let chk = |w: &WindowGuard<'_>| {
+      let held = w.execute_script(&format!(r##"
+        let pc = pieces['{}'];
+        pc.held;
+                       "##, &pc))?;
+      let held = held.value();
+      dbg!(held);
+      ensure_eq!(held, &serde_json::Value::Null);
+      Ok::<_,AE>(())
+    };
+
+    {
+      let mut w = su.w(&self.alice)?;
+      w.action_chain()
+        .move_to(10,10)
+        .click()
+        .release()
+        .perform()
+        .always_context("unselect by clicking elsewhere")?;
+
+      chk(&w)?;
+      w.synch()?;
+    }
+
+    {
+      let mut w = su.w(&self.bob)?;
+      w.synch()?;
+      chk(&w)?;
+    }
   }
 }
 
@@ -94,7 +132,8 @@ fn main(){
     let mut c = Ctx { su, alice, bob };
 
     c.drag().always_context("drag")?;
-    c.rotate().always_context("rotate")?;
+    let pc = c.rotate().always_context("rotate")?;
+    c.unselect(pc).always_context("unselect")?;
 
     debug!("finishing");
   }