Debian Codegraph @

CorsixTH/Luatest/spec/dialogs/bottom_pannel_spec.lua

raw
1 --[[ Copyright (c) 2018 Stephen E. Baker
2
3 Permission is hereby granted, free of charge, to any person obtaining a copy of
4 this software and associated documentation files (the "Software"), to deal in
5 the Software without restriction, including without limitation the rights to
6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7 of the Software, and to permit persons to whom the Software is furnished to do
8 so, subject to the following conditions:
9
10 The above copyright notice and this permission notice shall be included in all
11 copies or substantial portions of the Software.
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 SOFTWARE. --]]
20
21 describe("Bottom Panel:", function()
22 local bottom_panel;
23 local mock_canvas;
24 local font;
25
26 setup(function()
27 require("corsixth")
28 require("class_test_base")
29 require("TH")
30
31 require("window")
32 require("dialogs/bottom_panel")
33 end)
34
35 before_each(function()
36 TheApp.world.gameLog = function() end
37
38 font = {
39 draw = function() end,
40 drawWrapped = function() end,
41 }
42 TheApp.gfx.loadFontAndSpriteTable = function() return font end
43
44 local mock_ui = {}
45 mock_ui.app = _G['TheApp']
46 mock_ui.addKeyHandler = function() end
47
48 mock_canvas = {}
49
50 bottom_panel = UIBottomPanel(mock_ui)
51
52 mock(font, 'draw')
53 mock(font, 'drawWrapped')
54 mock(TheApp.world, 'gameLog')
55 end)
56
57 it("Set nil dynamic info", function()
58 bottom_panel:setDynamicInfo(nil)
59 bottom_panel:drawDynamicInfo(mock_canvas, 0, 0)
60
61 assert.stub(TheApp.world.gameLog).was_not.called_with(TheApp.world, "Dynamic info is missing text!")
62 end)
63
64 it("Set dynamic info without text", function()
65 local dynamic_info = {}
66
67 bottom_panel:setDynamicInfo(dynamic_info)
68 bottom_panel:drawDynamicInfo(mock_canvas, 0, 0)
69
70 assert.stub(TheApp.world.gameLog).was.called_with(TheApp.world, "Dynamic info is missing text!")
71 end)
72
73 it("Set dynamic info with text", function()
74 local dynamic_info = { text = { "test text" } }
75
76 bottom_panel:setDynamicInfo(dynamic_info)
77 bottom_panel:drawDynamicInfo(mock_canvas, 0, 0)
78
79 assert.stub(TheApp.world.gameLog).was_not.called_with(TheApp.world, "Dynamic info is missing text!")
80 assert.stub(font.drawWrapped).was.called_with(font, mock_canvas, "test text", 20, 10, 240)
81 end)
82 end)