From 44c5b224dd3517e43dc4c9f6bf2ba2dbaca47f9c Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sat, 31 Aug 2024 17:53:53 +0100 Subject: [PATCH] event/event_type: add assertion for each handler --- event/event_test.go | 97 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/event/event_test.go b/event/event_test.go index 7ee04c7..54cf75a 100644 --- a/event/event_test.go +++ b/event/event_test.go @@ -2,11 +2,8 @@ package event import ( "testing" -) -var ( - h = &FakeEventHandler{} - c = &FakeEventClient{} + "github.com/thiagokokada/hyprland-go/internal/assert" ) type FakeEventClient struct { @@ -14,7 +11,15 @@ type FakeEventClient struct { } 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) { @@ -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, @@ -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 {