Skip to content

Commit

Permalink
chore(tests): add test for renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvirtin committed Jul 4, 2024
1 parent e59c5f7 commit a0c8928
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/unit/core/renderer_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
local spy = require('luassert.spy')
local renderer = require('vgit.core.renderer')

describe('renderer', function()
local buffer = { bufnr = 1, on_render = function() end }

before_each(function()
renderer.buffers = {}
renderer.registered = false
end)

describe('register_module', function()
it('should register the module if not already registered', function()
local spy_vim_set_decoration_provider = spy.on(vim.api, 'nvim_set_decoration_provider')

renderer.register_module()

assert.is_true(renderer.registered)
assert.spy(spy_vim_set_decoration_provider).was.called()
end)

it('should not register the module if already registered', function()
local spy_vim_set_decoration_provider = spy.on(vim.api, 'nvim_set_decoration_provider')

renderer.registered = true
renderer.register_module()

assert.is_true(renderer.registered)
assert.spy(spy_vim_set_decoration_provider).was_not.called()
end)
end)

describe('attach', function()
it('should attach a buffer', function()
renderer.attach(buffer)
assert.is_not_nil(renderer.buffers[buffer.bufnr])
end)
end)

describe('detach', function()
it('should detach a buffer', function()
renderer.attach(buffer)
renderer.detach(buffer)
assert.is_nil(renderer.buffers[buffer.bufnr])
end)
end)
end)

0 comments on commit a0c8928

Please sign in to comment.