Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Refactor DblClick in mouse to use click
Browse files Browse the repository at this point in the history
The mouse implementation of DblClick should work with the new fixed
click method. The old dblClick method only resolves one of the two
behaviours that are required (the counter will increase but the
onDblClick event will not fire).
  • Loading branch information
ankur22 committed Dec 5, 2023
1 parent b9f3e4b commit d571123
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
26 changes: 1 addition & 25 deletions common/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,6 @@ func (m *Mouse) click(x float64, y float64, opts *MouseClickOptions) error {
return nil
}

func (m *Mouse) dblClick(x float64, y float64, opts *MouseDblClickOptions) error {
mouseDownUpOpts := opts.ToMouseDownUpOptions()
if err := m.move(x, y, NewMouseMoveOptions()); err != nil {
return err
}
for i := 0; i < 2; i++ {
if err := m.down(x, y, mouseDownUpOpts); err != nil {
return err
}
if opts.Delay != 0 {
t := time.NewTimer(time.Duration(opts.Delay) * time.Millisecond)
select {
case <-m.ctx.Done():
t.Stop()
case <-t.C:
}
}
if err := m.up(x, y, mouseDownUpOpts); err != nil {
return err
}
}
return nil
}

func (m *Mouse) down(x float64, y float64, opts *MouseDownUpOptions) error {
m.button = input.MouseButton(opts.Button)
action := input.DispatchMouseEvent(input.MousePressed, m.x, m.y).
Expand Down Expand Up @@ -141,7 +117,7 @@ func (m *Mouse) DblClick(x float64, y float64, opts goja.Value) {
if err := mouseOpts.Parse(m.ctx, opts); err != nil {
k6ext.Panic(m.ctx, "parsing double click options: %w", err)
}
if err := m.dblClick(x, y, mouseOpts); err != nil {
if err := m.click(x, y, mouseOpts.ToMouseClickOptions()); err != nil {
k6ext.Panic(m.ctx, "double clicking on x:%f y:%f: %w", x, y, err)
}
}
Expand Down
7 changes: 5 additions & 2 deletions common/mouse_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ func (o *MouseDblClickOptions) Parse(ctx context.Context, opts goja.Value) error
return nil
}

func (o *MouseDblClickOptions) ToMouseDownUpOptions() *MouseDownUpOptions {
o2 := NewMouseDownUpOptions()
// ToMouseClickOptions converts MouseDblClickOptions to a MouseClickOptions.
func (o *MouseDblClickOptions) ToMouseClickOptions() *MouseClickOptions {
o2 := NewMouseClickOptions()
o2.Button = o.Button
o2.ClickCount = 2
o2.Delay = o.Delay
return o2
}

Expand Down

0 comments on commit d571123

Please # to comment.