diff --git a/game.project b/game.project index cdb6d21..8601249 100644 --- a/game.project +++ b/game.project @@ -1,7 +1,7 @@ [project] title = Monarch version = 0.9 -dependencies = https://github.com/britzl/deftest/archive/2.4.3.zip +dependencies = https://github.com/britzl/deftest/archive/2.7.0.zip [bootstrap] main_collection = /test/test.collectionc diff --git a/test/test.script b/test/test.script index 1c793ad..e9477ed 100644 --- a/test/test.script +++ b/test/test.script @@ -5,5 +5,8 @@ local test_monarch = require "test.test_monarch" function init(self) deftest.add(test_monarch) - deftest.run({ coverage = { enabled = true }}) + deftest.run({ + coverage = { enabled = true }, + --pattern = "preload", + }) end diff --git a/test/test_monarch.lua b/test/test_monarch.lua index 3b2b0ff..2b0a213 100644 --- a/test/test_monarch.lua +++ b/test/test_monarch.lua @@ -34,6 +34,14 @@ return function() return fn(...) end + local function wait_until_done(fn) + local is_done = false + local function done() + is_done = true + end + fn(done) + wait_timeout(function() return is_done end) + end local function wait_until_visible(screen_id) return wait_timeout(is_visible, screen_id) end @@ -302,6 +310,16 @@ return function() assert(wait_until_not_busy()) end) + it("should be able to preload a screen and wait for it", function() + assert(not monarch.is_preloading(TRANSITION1)) + monarch.preload(TRANSITION1) + assert(monarch.is_preloading(TRANSITION1)) + wait_until_done(function(done) + monarch.when_preloaded(TRANSITION1, done) + end) + assert(not monarch.is_preloading(TRANSITION1)) + end) + it("should ignore any preload calls while busy", function() monarch.show(TRANSITION1) -- previously a call to preload() while also showing a screen would @@ -357,7 +375,12 @@ return function() assert(mock_msg.messages(URL1)[10].message.screen == SCREEN1) end) - + it("should be able to show a screen even while it is preloading", function() + assert(monarch.is_preloading(SCREEN_PRELOAD)) + monarch.show(SCREEN_PRELOAD, nil, { count = 1 }) + assert(wait_until_shown(SCREEN_PRELOAD), "Screen_preload was never shown") + end) + it("should be able to preload a screen and always keep it loaded", function() monarch.show(SCREEN_PRELOAD, nil, { count = 1 }) assert(wait_until_shown(SCREEN_PRELOAD), "Screen_preload was never shown")