Skip to content

Commit 2295d6b

Browse files
authored
feat: Testing events utils (#864)
1 parent a53e134 commit 2295d6b

32 files changed

+124
-545
lines changed

crates/components/src/accordion.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,12 @@ mod test {
176176
let content = root.get(0).get(1).get(0);
177177
let label = content.get(0);
178178
utils.wait_for_update().await;
179-
utils.wait_for_update().await;
180179

181180
// Accordion is closed, therefore label is hidden.
182181
assert!(!label.is_visible());
183182

184183
// Click on the accordion
185-
utils.push_event(PlatformEvent::Mouse {
186-
name: EventName::Click,
187-
cursor: (5., 5.).into(),
188-
button: Some(MouseButton::Left),
189-
});
190-
191-
utils.wait_for_update().await;
184+
utils.click_cursor((5., 5.)).await;
192185

193186
// State somewhere in the middle
194187
sleep(Duration::from_millis(70)).await;

crates/components/src/button.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,7 @@ mod test {
224224

225225
assert_eq!(label.get(0).text(), Some("false"));
226226

227-
utils.push_event(PlatformEvent::Mouse {
228-
name: EventName::Click,
229-
cursor: (15.0, 15.0).into(),
230-
button: Some(MouseButton::Left),
231-
});
232-
233-
utils.wait_for_update().await;
227+
utils.click_cursor((15.0, 15.0)).await;
234228

235229
assert_eq!(label.get(0).text(), Some("true"));
236230

crates/components/src/checkbox.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,39 +176,21 @@ mod test {
176176
assert!(root.get(1).get(0).get(0).get(0).is_placeholder());
177177
assert!(root.get(2).get(0).get(0).get(0).is_placeholder());
178178

179-
utils.push_event(PlatformEvent::Mouse {
180-
name: EventName::Click,
181-
cursor: (20.0, 50.0).into(),
182-
button: Some(MouseButton::Left),
183-
});
184-
utils.wait_for_update().await;
179+
utils.click_cursor((20., 50.)).await;
185180

186181
assert!(root.get(0).get(0).get(0).get(0).is_placeholder());
187182
assert!(root.get(1).get(0).get(0).get(0).is_element());
188183
assert!(root.get(2).get(0).get(0).get(0).is_placeholder());
189184

190-
utils.push_event(PlatformEvent::Mouse {
191-
name: EventName::Click,
192-
cursor: (10.0, 90.0).into(),
193-
button: Some(MouseButton::Left),
194-
});
185+
utils.click_cursor((10., 90.)).await;
195186
utils.wait_for_update().await;
196187

197188
assert!(root.get(0).get(0).get(0).get(0).is_placeholder());
198189
assert!(root.get(1).get(0).get(0).get(0).is_element());
199190
assert!(root.get(2).get(0).get(0).get(0).is_element());
200191

201-
utils.push_event(PlatformEvent::Mouse {
202-
name: EventName::Click,
203-
cursor: (10.0, 10.0).into(),
204-
button: Some(MouseButton::Left),
205-
});
206-
utils.wait_for_update().await;
207-
utils.push_event(PlatformEvent::Mouse {
208-
name: EventName::Click,
209-
cursor: (10.0, 50.0).into(),
210-
button: Some(MouseButton::Left),
211-
});
192+
utils.click_cursor((10., 10.)).await;
193+
utils.click_cursor((10., 50.)).await;
212194
utils.wait_for_update().await;
213195

214196
assert!(root.get(0).get(0).get(0).get(0).is_element());

crates/components/src/cursor_area.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,35 +97,17 @@ mod test {
9797
// Initial cursor
9898
assert_eq!(utils.cursor_icon(), CursorIcon::default());
9999

100-
utils.push_event(PlatformEvent::Mouse {
101-
name: EventName::MouseOver,
102-
cursor: (100., 100.).into(),
103-
button: Some(MouseButton::Left),
104-
});
105-
106-
utils.wait_for_update().await;
100+
utils.move_cursor((100., 100.)).await;
107101

108102
// Cursor after hovering the first half
109103
assert_eq!(utils.cursor_icon(), CursorIcon::Progress);
110104

111-
utils.push_event(PlatformEvent::Mouse {
112-
name: EventName::MouseOver,
113-
cursor: (100., 300.).into(),
114-
button: Some(MouseButton::Left),
115-
});
116-
117-
utils.wait_for_update().await;
105+
utils.move_cursor((100., 300.)).await;
118106

119107
// Cursor after hovering the second half
120108
assert_eq!(utils.cursor_icon(), CursorIcon::Pointer);
121109

122-
utils.push_event(PlatformEvent::Mouse {
123-
name: EventName::MouseOver,
124-
cursor: (-1., -1.).into(),
125-
button: Some(MouseButton::Left),
126-
});
127-
128-
utils.wait_for_update().await;
110+
utils.move_cursor((-1., -1.)).await;
129111

130112
// Cursor after leaving the window
131113
assert_eq!(utils.cursor_icon(), CursorIcon::default());

crates/components/src/drag_drop.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,9 @@ mod test {
188188

189189
utils.wait_for_update().await;
190190

191-
utils.push_event(PlatformEvent::Mouse {
192-
name: EventName::MouseOver,
193-
cursor: (5.0, 5.0).into(),
194-
button: Some(MouseButton::Left),
195-
});
196-
197-
utils.wait_for_update().await;
191+
utils.move_cursor((5., 5.)).await;
198192

199-
utils.push_event(PlatformEvent::Mouse {
200-
name: EventName::MouseOver,
201-
cursor: (5.0, 300.0).into(),
202-
button: Some(MouseButton::Left),
203-
});
204-
205-
utils.wait_for_update().await;
193+
utils.move_cursor((5., 300.)).await;
206194

207195
assert_eq!(root.get(0).get(0).get(0).get(0).text(), Some("Moving"));
208196

crates/components/src/dropdown.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -364,42 +364,23 @@ mod test {
364364
assert_eq!(label.get(0).text(), Some("Value A"));
365365

366366
// Open the dropdown
367-
utils.push_event(PlatformEvent::Mouse {
368-
name: EventName::Click,
369-
cursor: (15.0, 15.0).into(),
370-
button: Some(MouseButton::Left),
371-
});
367+
utils.click_cursor((15., 15.)).await;
372368
utils.wait_for_update().await;
373369

374370
// Now that the dropwdown is opened, there are more nodes in the layout
375371
assert!(utils.sdom().get().layout().size() > start_size);
376372

377373
// Close the dropdown by clicking outside of it
378-
utils.push_event(PlatformEvent::Mouse {
379-
name: EventName::Click,
380-
cursor: (200.0, 200.0).into(),
381-
button: Some(MouseButton::Left),
382-
});
383-
utils.wait_for_update().await;
374+
utils.click_cursor((200., 200.)).await;
384375

385376
// Now the layout size is like in the begining
386377
assert_eq!(utils.sdom().get().layout().size(), start_size);
387378

388379
// Open the dropdown again
389-
utils.push_event(PlatformEvent::Mouse {
390-
name: EventName::Click,
391-
cursor: (15.0, 15.0).into(),
392-
button: Some(MouseButton::Left),
393-
});
394-
utils.wait_for_update().await;
380+
utils.click_cursor((15., 15.)).await;
395381

396382
// Click on the second option
397-
utils.push_event(PlatformEvent::Mouse {
398-
name: EventName::Click,
399-
cursor: (45.0, 100.0).into(),
400-
button: Some(MouseButton::Left),
401-
});
402-
utils.wait_for_update().await;
383+
utils.click_cursor((45., 100.)).await;
403384
utils.wait_for_update().await;
404385
utils.wait_for_update().await;
405386

crates/components/src/link.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -273,32 +273,19 @@ mod test {
273273

274274
let mut utils = launch_test(link_app);
275275

276-
utils.wait_for_update().await;
277-
utils.wait_for_update().await;
278-
279276
// Check route is Home
280277
assert_eq!(utils.root().get(2).get(0).text(), Some("Home"));
281278

282279
// Go to the "Somewhere" route
283-
utils.push_event(PlatformEvent::Mouse {
284-
name: EventName::Click,
285-
cursor: (5., 60.).into(),
286-
button: Some(MouseButton::Left),
287-
});
288-
289-
utils.wait_for_update().await;
290-
utils.wait_for_update().await;
280+
utils.click_cursor((5., 60.)).await;
291281

292282
// Check route is Somewhere
293283
assert_eq!(utils.root().get(2).get(0).text(), Some("Somewhere"));
294284

295285
// Go to the "Home" route again
296-
utils.push_event(PlatformEvent::Mouse {
297-
name: EventName::Click,
298-
cursor: (5., 5.).into(),
299-
button: Some(MouseButton::Left),
300-
});
286+
utils.click_cursor((5., 5.)).await;
301287

302-
utils.wait_for_update().await;
288+
// Check route is Home
289+
assert_eq!(utils.root().get(2).get(0).text(), Some("Home"));
303290
}
304291
}

crates/components/src/menu.rs

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,7 @@ mod test {
381381
assert_eq!(utils.sdom().get().layout().size(), 5);
382382

383383
// Open the Menu
384-
utils.push_event(PlatformEvent::Mouse {
385-
name: EventName::Click,
386-
cursor: (15.0, 15.0).into(),
387-
button: Some(MouseButton::Left),
388-
});
389-
utils.wait_for_update().await;
384+
utils.click_cursor((15., 15.)).await;
390385

391386
// Check the `Open` button exists
392387
assert_eq!(
@@ -405,34 +400,18 @@ mod test {
405400
assert!(utils.sdom().get().layout().size() > start_size);
406401

407402
// Close the Menu
408-
utils.push_event(PlatformEvent::Mouse {
409-
name: EventName::Click,
410-
cursor: (15.0, 60.0).into(),
411-
button: Some(MouseButton::Left),
412-
});
413-
utils.wait_for_update().await;
403+
utils.click_cursor((15., 60.)).await;
414404

415405
assert_eq!(utils.sdom().get().layout().size(), start_size);
416406

417407
// Open the Menu again
418-
utils.push_event(PlatformEvent::Mouse {
419-
name: EventName::Click,
420-
cursor: (15.0, 15.0).into(),
421-
button: Some(MouseButton::Left),
422-
});
423-
utils.wait_for_update().await;
424-
utils.wait_for_update().await;
408+
utils.click_cursor((15., 15.)).await;
425409

426410
let one_submenu_opened = utils.sdom().get().layout().size();
427411
assert!(one_submenu_opened > start_size);
428412

429413
// Open the SubMenu
430-
utils.push_event(PlatformEvent::Mouse {
431-
name: EventName::MouseOver,
432-
cursor: (15.0, 130.0).into(),
433-
button: Some(MouseButton::Left),
434-
});
435-
utils.wait_for_update().await;
414+
utils.move_cursor((15., 130.)).await;
436415

437416
// Check the `Option 1` button exists
438417
assert_eq!(
@@ -455,22 +434,12 @@ mod test {
455434
assert!(utils.sdom().get().layout().size() > one_submenu_opened);
456435

457436
// Stop showing the submenu
458-
utils.push_event(PlatformEvent::Mouse {
459-
name: EventName::MouseOver,
460-
cursor: (15.0, 90.0).into(),
461-
button: Some(MouseButton::Left),
462-
});
463-
utils.wait_for_update().await;
437+
utils.move_cursor((15., 90.)).await;
464438

465439
assert_eq!(utils.sdom().get().layout().size(), one_submenu_opened);
466440

467441
// Click somewhere also so all the menus hide
468-
utils.push_event(PlatformEvent::Mouse {
469-
name: EventName::Click,
470-
cursor: (333.0, 333.0).into(),
471-
button: Some(MouseButton::Left),
472-
});
473-
utils.wait_for_update().await;
442+
utils.click_cursor((333., 333.)).await;
474443

475444
assert_eq!(utils.sdom().get().layout().size(), start_size);
476445
}

crates/components/src/native_router.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,7 @@ mod test {
114114

115115
assert_eq!(utils.root().get(0).get(1).get(0).text(), Some("A"));
116116

117-
utils.push_event(PlatformEvent::Mouse {
118-
name: EventName::Click,
119-
cursor: (5.0, 5.0).into(),
120-
button: Some(MouseButton::Left),
121-
});
122-
123-
utils.wait_for_update().await;
117+
utils.click_cursor((5., 5.)).await;
124118

125119
assert_eq!(utils.root().get(0).get(1).get(0).text(), Some("B"));
126120

@@ -129,7 +123,6 @@ mod test {
129123
cursor: (5.0, 5.0).into(),
130124
button: Some(MouseButton::Back),
131125
});
132-
133126
utils.wait_for_update().await;
134127

135128
assert_eq!(utils.root().get(0).get(1).get(0).text(), Some("A"));
@@ -139,7 +132,6 @@ mod test {
139132
cursor: (5.0, 5.0).into(),
140133
button: Some(MouseButton::Forward),
141134
});
142-
143135
utils.wait_for_update().await;
144136

145137
assert_eq!(utils.root().get(0).get(1).get(0).text(), Some("B"));

crates/components/src/popup.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,33 +216,18 @@ mod test {
216216
assert_eq!(utils.sdom().get().layout().size(), 4);
217217

218218
// Open the popup
219-
utils.push_event(PlatformEvent::Mouse {
220-
name: EventName::Click,
221-
cursor: (15.0, 15.0).into(),
222-
button: Some(MouseButton::Left),
223-
});
224-
utils.wait_for_update().await;
219+
utils.click_cursor((15., 15.)).await;
225220

226221
// Check the popup is opened
227222
assert_eq!(utils.sdom().get().layout().size(), 10);
228223

229-
utils.push_event(PlatformEvent::Mouse {
230-
name: EventName::Click,
231-
cursor: (395.0, 180.0).into(),
232-
button: Some(MouseButton::Left),
233-
});
234-
utils.wait_for_update().await;
224+
utils.click_cursor((395., 180.)).await;
235225

236226
// Check the popup is closed
237227
assert_eq!(utils.sdom().get().layout().size(), 4);
238228

239229
// Open the popup
240-
utils.push_event(PlatformEvent::Mouse {
241-
name: EventName::Click,
242-
cursor: (15.0, 15.0).into(),
243-
button: Some(MouseButton::Left),
244-
});
245-
utils.wait_for_update().await;
230+
utils.click_cursor((15., 15.)).await;
246231

247232
// Send a random keydown event
248233
utils.push_event(PlatformEvent::Keyboard {

0 commit comments

Comments
 (0)