Skip to content

Commit

Permalink
Fix broken mobile tests and add a test for double clicking on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
okratitan committed Oct 10, 2020
1 parent bd15c5e commit f91191c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
69 changes: 69 additions & 0 deletions internal/driver/gomobile/canvas_test.go
Expand Up @@ -78,6 +78,8 @@ func TestCanvas_Tapped(t *testing.T) {
}, func(wid fyne.SecondaryTappable, ev *fyne.PointEvent) {
altTapped = true
wid.TappedSecondary(ev)
}, func (wid fyne.DoubleTappable, ev *fyne.PointEvent) {
wid.DoubleTapped(ev)
}, func(wid fyne.Draggable, ev *fyne.DragEvent) {
})

Expand Down Expand Up @@ -106,6 +108,8 @@ func TestCanvas_Tapped_Multi(t *testing.T) {
c.tapUp(tapPos, 1, func(wid fyne.Tappable, ev *fyne.PointEvent) { // different tapID
wid.Tapped(ev)
}, func(wid fyne.SecondaryTappable, ev *fyne.PointEvent) {
}, func (wid fyne.DoubleTappable, ev *fyne.PointEvent) {
wid.DoubleTapped(ev)
}, func(wid fyne.Draggable, ev *fyne.DragEvent) {
})

Expand Down Expand Up @@ -133,6 +137,8 @@ func TestCanvas_TappedSecondary(t *testing.T) {
altTappedObj = wid
pointEvent = ev
wid.TappedSecondary(ev)
}, func (wid fyne.DoubleTappable, ev *fyne.PointEvent) {
wid.DoubleTapped(ev)
}, func(wid fyne.Draggable, ev *fyne.DragEvent) {
})

Expand Down Expand Up @@ -184,6 +190,7 @@ func TestCanvas_Tappable(t *testing.T) {

c.tapUp(fyne.NewPos(15, 15), 0, func(wid fyne.Tappable, ev *fyne.PointEvent) {
}, func(wid fyne.SecondaryTappable, ev *fyne.PointEvent) {
}, func (wid fyne.DoubleTappable, ev *fyne.PointEvent) {
}, func(wid fyne.Draggable, ev *fyne.DragEvent) {
})
assert.True(t, content.up)
Expand All @@ -195,6 +202,51 @@ func TestCanvas_Tappable(t *testing.T) {
assert.True(t, content.cancel)
}

func TestWindow_TappedAndDoubleTapped(t *testing.T) {
tapped := 0
but := newDoubleTappableButton()
but.OnTapped = func() {
tapped = 1
}
but.onDoubleTap = func() {
tapped = 2
}

c := NewCanvas().(*mobileCanvas)
c.SetContent(fyne.NewContainerWithLayout(layout.NewMaxLayout(), but))
c.resize(fyne.NewSize(36, 24))

c.tapDown(fyne.NewPos(15, 15), 0)
c.tapUp(fyne.NewPos(15, 15), 0, func(wid fyne.Tappable, ev *fyne.PointEvent) {
wid.Tapped(ev)
}, func(wid fyne.SecondaryTappable, ev *fyne.PointEvent) {
}, func (wid fyne.DoubleTappable, ev *fyne.PointEvent) {
wid.DoubleTapped(ev)
}, func(wid fyne.Draggable, ev *fyne.DragEvent) {
})
time.Sleep(700 * time.Millisecond)
assert.Equal(t, tapped, 1)

c.tapDown(fyne.NewPos(15, 15), 0)
c.tapUp(fyne.NewPos(15, 15), 0, func(wid fyne.Tappable, ev *fyne.PointEvent) {
wid.Tapped(ev)
}, func(wid fyne.SecondaryTappable, ev *fyne.PointEvent) {
}, func (wid fyne.DoubleTappable, ev *fyne.PointEvent) {
wid.DoubleTapped(ev)
}, func(wid fyne.Draggable, ev *fyne.DragEvent) {
})
c.tapDown(fyne.NewPos(15, 15), 0)
c.tapUp(fyne.NewPos(15, 15), 0, func(wid fyne.Tappable, ev *fyne.PointEvent) {
wid.Tapped(ev)
}, func(wid fyne.SecondaryTappable, ev *fyne.PointEvent) {
}, func (wid fyne.DoubleTappable, ev *fyne.PointEvent) {
wid.DoubleTapped(ev)
}, func(wid fyne.Draggable, ev *fyne.DragEvent) {
})
time.Sleep(700 * time.Millisecond)
assert.Equal(t, tapped, 1)
}

func TestCanvas_Focusable(t *testing.T) {
content := newFocusableEntry()
c := NewCanvas().(*mobileCanvas)
Expand Down Expand Up @@ -277,3 +329,20 @@ func (f *focusableEntry) FocusLost() {
f.unfocusedTimes++
f.Entry.FocusLost()
}

type doubleTappableButton struct {
widget.Button

onDoubleTap func()
}

func (t *doubleTappableButton) DoubleTapped(_ *fyne.PointEvent) {
t.onDoubleTap()
}

func newDoubleTappableButton() *doubleTappableButton {
but := &doubleTappableButton{}
but.ExtendBaseWidget(but)

return but
}
2 changes: 1 addition & 1 deletion internal/driver/gomobile/menu_test.go
Expand Up @@ -25,7 +25,7 @@ func TestMobileCanvas_DismissBar(t *testing.T) {
assert.NotNil(t, c.menu)
// simulate tap as the test util does not know about our menu...
c.tapDown(fyne.NewPos(80, 20), 1)
c.tapUp(fyne.NewPos(80, 20), 1, nil, nil, nil)
c.tapUp(fyne.NewPos(80, 20), 1, nil, nil, nil,nil)
assert.Nil(t, c.menu)
}

Expand Down

0 comments on commit f91191c

Please sign in to comment.