This repository has been archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor integration keyboard tests to unit tests
Some of the integration tests can easily be converted to unit tests which makes running them quicker, as well as making the tests simpler. It also helps group similar tests. Resolves: #326 (comment)
- Loading branch information
Showing
2 changed files
with
77 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/grafana/xk6-browser/k6ext/k6test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSplit(t *testing.T) { | ||
type args struct { | ||
keys string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []string | ||
}{ | ||
{ | ||
name: "empty slice on empty string", | ||
args: args{ | ||
keys: "", | ||
}, | ||
want: []string{""}, | ||
}, | ||
{ | ||
name: "empty slice on string without separator", | ||
args: args{ | ||
keys: "HelloWorld!", | ||
}, | ||
want: []string{"HelloWorld!"}, | ||
}, | ||
{ | ||
name: "string split with separator", | ||
args: args{ | ||
keys: "Hello+World+!", | ||
}, | ||
want: []string{"Hello", "World", "!"}, | ||
}, | ||
{ | ||
name: "do not split on single +", | ||
args: args{ | ||
keys: "+", | ||
}, | ||
want: []string{"+"}, | ||
}, | ||
{ | ||
name: "split ++ to + and ''", | ||
args: args{ | ||
keys: "++", | ||
}, | ||
want: []string{"+", ""}, | ||
}, | ||
{ | ||
name: "split +++ to + and +", | ||
args: args{ | ||
keys: "+++", | ||
}, | ||
want: []string{"+", "+"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := split(tt.args.keys) | ||
|
||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} | ||
|
||
func TestKeyboardPress(t *testing.T) { | ||
t.Run("panics when '' empty key passed in", func(t *testing.T) { | ||
vu := k6test.NewVU(t) | ||
k := NewKeyboard(vu.Context(), nil) | ||
assert.Panics(t, func() { k.Press("", nil) }) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters