Skip to content

Commit

Permalink
event/event_type: add assertion for each handler
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Aug 31, 2024
1 parent 62f4cf3 commit 44c5b22
Showing 1 changed file with 86 additions and 11 deletions.
97 changes: 86 additions & 11 deletions event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ package event

import (
"testing"
)

var (
h = &FakeEventHandler{}
c = &FakeEventClient{}
"github.com/thiagokokada/hyprland-go/internal/assert"
)

type FakeEventClient struct {
EventClient
}

type FakeEventHandler struct {
DefaultEventHandler
t *testing.T
EventHandler
}

func TestSubscribe(t *testing.T) {
h := &FakeEventHandler{t: t}
c := &FakeEventClient{}
err := SubscribeWithoutLoop(*c, h, AllEvents...)
assert.NoError(t, err)
}

func (f *FakeEventClient) Receive() ([]ReceivedData, error) {
Expand All @@ -30,7 +35,7 @@ func (f *FakeEventClient) Receive() ([]ReceivedData, error) {
},
{
Type: EventActiveWindow,
Data: "jetbrains-goland,hyprland-ipc-ipc – ipc.go",
Data: "nvim,nvim event/event_test.go",
},
{
Type: EventFullscreen,
Expand Down Expand Up @@ -96,11 +101,81 @@ func (f *FakeEventClient) Receive() ([]ReceivedData, error) {
}, nil
}

func TestSubscribe(t *testing.T) {
err := SubscribeWithoutLoop(*c, h, AllEvents...)
if err != nil {
t.Error(err)
}
func (h *FakeEventHandler) Workspace(w WorkspaceName) {
assert.Equal(h.t, w, "1")
}

func (h *FakeEventHandler) FocusedMonitor(m FocusedMonitor) {
assert.Equal(h.t, m.WorkspaceName, "1")
assert.Equal(h.t, m.MonitorName, "1")
}

func (h *FakeEventHandler) ActiveWindow(w ActiveWindow) {
assert.Equal(h.t, w.Name, "nvim")
assert.Equal(h.t, w.Title, "nvim event/event_test.go")
}

func (h *FakeEventHandler) Fullscreen(f Fullscreen) {
assert.Equal(h.t, f, true)
}

func (h *FakeEventHandler) MonitorRemoved(m MonitorName) {
assert.Equal(h.t, m, "1")
}

func (h *FakeEventHandler) MonitorAdded(m MonitorName) {
assert.Equal(h.t, m, "1")
}

func (h *FakeEventHandler) CreateWorkspace(w WorkspaceName) {
assert.Equal(h.t, w, "1")
}

func (h *FakeEventHandler) DestroyWorkspace(w WorkspaceName) {
assert.Equal(h.t, w, "1")
}

func (h *FakeEventHandler) MoveWorkspace(w MoveWorkspace) {
assert.Equal(h.t, w.WorkspaceName, "1")
assert.Equal(h.t, w.MonitorName, "1")
}

func (h *FakeEventHandler) ActiveLayout(l ActiveLayout) {
assert.Equal(h.t, l.Name, "Russian")
assert.Equal(h.t, l.Type, "AT Translated Set 2 keyboard")
}

func (h *FakeEventHandler) OpenWindow(o OpenWindow) {
assert.Equal(h.t, o.Address, "80e62df0")
assert.Equal(h.t, o.Class, "jetbrains-goland")
assert.Equal(h.t, o.Title, "win430")
assert.Equal(h.t, o.WorkspaceName, "2")
}

func (h *FakeEventHandler) CloseWindow(c CloseWindow) {
assert.Equal(h.t, c.Address, "80e62df0")
}

func (h *FakeEventHandler) MoveWindow(m MoveWindow) {
assert.Equal(h.t, m.Address, "80e62df0")
assert.Equal(h.t, m.WorkspaceName, "1")
}

func (h *FakeEventHandler) OpenLayer(l OpenLayer) {
assert.Equal(h.t, l, "wofi")
}

func (h *FakeEventHandler) CloseLayer(l CloseLayer) {
assert.Equal(h.t, l, "wofi")
}

func (h *FakeEventHandler) SubMap(s SubMap) {
assert.Equal(h.t, s, "1")
}

func (h *FakeEventHandler) Screencast(s Screencast) {
assert.Equal(h.t, s.Owner, "0")
assert.Equal(h.t, s.Sharing, true)
}

func SubscribeWithoutLoop(c FakeEventClient, ev EventHandler, events ...EventType) error {
Expand Down

0 comments on commit 44c5b22

Please sign in to comment.