MCPcopy
hub / github.com/mum4k/termdash / TestKeyboard

Function TestKeyboard

container/container_test.go:1377–1785  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1375}
1376
1377func TestKeyboard(t *testing.T) {
1378 tests := []struct {
1379 desc string
1380 termSize image.Point
1381 container func(ft *faketerm.Terminal) (*Container, error)
1382 events []terminalapi.Event
1383 // If specified, waits for this number of events.
1384 // Otherwise waits for len(events).
1385 wantProcessed int
1386 want func(size image.Point) *faketerm.Terminal
1387 wantErr bool
1388 }{
1389 {
1390 desc: "event not forwarded if container has no widget",
1391 termSize: image.Point{10, 10},
1392 container: func(ft *faketerm.Terminal) (*Container, error) {
1393 return New(ft)
1394 },
1395 events: []terminalapi.Event{
1396 &terminalapi.Keyboard{Key: keyboard.KeyEnter},
1397 },
1398 want: func(size image.Point) *faketerm.Terminal {
1399 return faketerm.MustNew(size)
1400 },
1401 },
1402 {
1403 desc: "event forwarded to focused container only",
1404 termSize: image.Point{40, 20},
1405 container: func(ft *faketerm.Terminal) (*Container, error) {
1406 return New(
1407 ft,
1408 SplitVertical(
1409 Left(
1410 PlaceWidget(fakewidget.New(widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused})),
1411 ),
1412 Right(
1413 SplitHorizontal(
1414 Top(
1415 PlaceWidget(fakewidget.New(widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused})),
1416 ),
1417 Bottom(
1418 PlaceWidget(fakewidget.New(widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused})),
1419 ),
1420 ),
1421 ),
1422 ),
1423 )
1424 },
1425 events: []terminalapi.Event{
1426 // Move focus to the target container.
1427 &terminalapi.Mouse{Position: image.Point{39, 19}, Button: mouse.ButtonLeft},
1428 &terminalapi.Mouse{Position: image.Point{39, 19}, Button: mouse.ButtonRelease},
1429 // Send the keyboard event.
1430 &terminalapi.Keyboard{Key: keyboard.KeyEnter},
1431 },
1432 want: func(size image.Point) *faketerm.Terminal {
1433 ft := faketerm.MustNew(size)
1434

Callers

nothing calls this directly

Calls 15

SubscribeMethod · 0.95
handleMethod · 0.95
EventMethod · 0.95
ProcessedMethod · 0.95
getMethod · 0.95
MustNewFunction · 0.92
NewFunction · 0.92
MustDrawFunction · 0.92
MustNewFunction · 0.92
NewFunction · 0.92
NewDistributionSystemFunction · 0.92
NewErrorFunction · 0.92

Tested by

no test coverage detected