Skip to content

Commit

Permalink
Add syncMapKeyboard
Browse files Browse the repository at this point in the history
This is to enable us to still work with the sync keyboard APIs with the
Sobek changes removed from the business logic side of keyboard.
  • Loading branch information
ankur22 committed Oct 7, 2024
1 parent 7294a4c commit eb1d417
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions browser/sync_keyboard_mapping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package browser

import (
"fmt"

"github.com/grafana/sobek"

"github.com/grafana/xk6-browser/common"
)

func syncMapKeyboard(vu moduleVU, kb *common.Keyboard) mapping {
return mapping{
"down": kb.Down,
"up": kb.Up,
"press": func(key string, opts sobek.Value) error {
kbdOpts := common.NewKeyboardOptions()
if err := kbdOpts.Parse(vu.Context(), opts); err != nil {
return fmt.Errorf("parsing keyboard options: %w", err)
}

return kb.Press(key, kbdOpts) //nolint:wrapcheck
},
"type": func(text string, opts sobek.Value) error {
kbdOpts := common.NewKeyboardOptions()
if err := kbdOpts.Parse(vu.Context(), opts); err != nil {
return fmt.Errorf("parsing keyboard options: %w", err)
}

return kb.Type(text, kbdOpts) //nolint:wrapcheck
},
"insertText": kb.InsertText,
}
}
2 changes: 1 addition & 1 deletion browser/sync_page_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop
"isEnabled": p.IsEnabled,
"isHidden": p.IsHidden,
"isVisible": p.IsVisible,
"keyboard": rt.ToValue(p.GetKeyboard()).ToObject(rt),
"keyboard": syncMapKeyboard(vu, p.GetKeyboard()),
"locator": func(selector string, opts sobek.Value) *sobek.Object {
ml := syncMapLocator(vu, p.Locator(selector, opts))
return rt.ToValue(ml).ToObject(rt)
Expand Down

0 comments on commit eb1d417

Please sign in to comment.