repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

hypr/tests/commands_test.lua

Raw
package.path = "./?.lua;./?/init.lua;" .. package.path

local calls = {}

hl = {
  dsp = {
    exec_cmd = function(command)
      table.insert(calls, { "exec_cmd", command })
      return { kind = "exec", command = command }
    end,
    focus = function(opts)
      table.insert(calls, { "focus", opts.workspace })
      return { kind = "focus", workspace = opts.workspace }
    end,
    window = {
      move = function(opts)
        table.insert(calls, { "move", opts.workspace })
        return { kind = "move", workspace = opts.workspace }
      end,
    },
  },
  dispatch = function(dispatcher)
    table.insert(calls, { "dispatch", dispatcher.kind, dispatcher.command or dispatcher.workspace })
    return "dispatched"
  end,
}

local commands = require("modules.commands")

assert(commands.to_dispatcher("firefox").command == "firefox")
assert(commands.to_dispatcher("firefox").kind == "exec")

local dispatcher = { kind = "raw" }
assert(commands.to_dispatcher(dispatcher) == dispatcher)

assert(commands.app("wifi") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "exec")
assert(calls[#calls][3] == "qs ipc -c nuguland call nuguland openWifi")

assert(commands.app("clipboard") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "exec")
assert(calls[#calls][3] == "qs ipc -c nuguland call nuguland openClipboardPicker ''")

assert(commands.app("bluetooth") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "exec")
assert(calls[#calls][3] == "qs ipc -c nuguland call nuguland openBluetooth")

assert(commands.app("audio_mixer") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "exec")
assert(calls[#calls][3] == "qs ipc -c nuguland call nuguland openAudio")

assert(commands.app("system_monitor") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "exec")
assert(calls[#calls][3] == "qs ipc -c nuguland call nuguland openSystem")

assert(commands.workspace("3") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "focus")
assert(calls[#calls][3] == "3")

assert(commands.move_to_workspace("4") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "move")
assert(calls[#calls][3] == "4")

local ok, err = pcall(commands.app, "missing")
assert(not ok)
assert(tostring(err):find("missing", 1, true))

print("commands ok")