mirror of
https://github.com/britzl/monarch.git
synced 2025-11-26 19:00:53 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
742779d749 | ||
|
|
84944f3f22 |
@@ -228,6 +228,17 @@ function M.is_visible(id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check if a screen is loaded
|
||||||
|
-- @param id (string|hash)
|
||||||
|
-- @return true if the screen is loaded
|
||||||
|
function M.is_loaded(id)
|
||||||
|
assert(id, "You must provide a screen id")
|
||||||
|
id = tohash(id)
|
||||||
|
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
|
||||||
|
return screens[id].loaded
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Check if a screen is a popup
|
--- Check if a screen is a popup
|
||||||
-- @param id Screen id
|
-- @param id Screen id
|
||||||
-- @return true if the screen is a popup
|
-- @return true if the screen is a popup
|
||||||
@@ -1178,8 +1189,8 @@ end
|
|||||||
-- @return error (string|nil) Error message if unable to send message
|
-- @return error (string|nil) Error message if unable to send message
|
||||||
function M.post(id, message_id, message)
|
function M.post(id, message_id, message)
|
||||||
assert(id, "You must provide a screen id")
|
assert(id, "You must provide a screen id")
|
||||||
if not M.is_visible(id) then
|
if not M.is_loaded(id) then
|
||||||
return false, "Unable to post message to screen if it isn't visible"
|
return false, "Unable to post message to screen if it isn't loaded"
|
||||||
end
|
end
|
||||||
|
|
||||||
assert(message_id, "You must provide a message_id")
|
assert(message_id, "You must provide a message_id")
|
||||||
|
|||||||
@@ -142,12 +142,12 @@ return function()
|
|||||||
monarch.show(SCREEN1)
|
monarch.show(SCREEN1)
|
||||||
assert(wait_until_stack({ SCREEN1 }))
|
assert(wait_until_stack({ SCREEN1 }))
|
||||||
assert(wait_until_visible(SCREEN1))
|
assert(wait_until_visible(SCREEN1))
|
||||||
|
|
||||||
monarch.show(SCREEN2)
|
monarch.show(SCREEN2)
|
||||||
assert(wait_until_stack({ SCREEN1, SCREEN2 }))
|
assert(wait_until_stack({ SCREEN1, SCREEN2 }))
|
||||||
assert(wait_until_hidden(SCREEN1))
|
assert(wait_until_hidden(SCREEN1))
|
||||||
assert(wait_until_visible(SCREEN2))
|
assert(wait_until_visible(SCREEN2))
|
||||||
|
|
||||||
monarch.show(POPUP1)
|
monarch.show(POPUP1)
|
||||||
assert(wait_until_stack({ SCREEN1, SCREEN2, POPUP1 }))
|
assert(wait_until_stack({ SCREEN1, SCREEN2, POPUP1 }))
|
||||||
assert(wait_until_hidden(SCREEN1))
|
assert(wait_until_hidden(SCREEN1))
|
||||||
@@ -155,6 +155,17 @@ return function()
|
|||||||
assert(wait_until_visible(POPUP1))
|
assert(wait_until_visible(POPUP1))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("should be able to tell if a screen is loaded or not", function()
|
||||||
|
assert(not monarch.is_loaded(SCREEN1))
|
||||||
|
monarch.show(SCREEN1)
|
||||||
|
assert(wait_until_visible(SCREEN1))
|
||||||
|
assert(monarch.is_loaded(SCREEN1))
|
||||||
|
|
||||||
|
monarch.hide(SCREEN1)
|
||||||
|
assert(wait_until_hidden(SCREEN1))
|
||||||
|
assert(not monarch.is_loaded(SCREEN1))
|
||||||
|
end)
|
||||||
|
|
||||||
it("should be able to show a screen without adding it to the stack", function()
|
it("should be able to show a screen without adding it to the stack", function()
|
||||||
monarch.show(BACKGROUND, { no_stack = true })
|
monarch.show(BACKGROUND, { no_stack = true })
|
||||||
assert(wait_until_visible(BACKGROUND), "Background was never shown")
|
assert(wait_until_visible(BACKGROUND), "Background was never shown")
|
||||||
|
|||||||
Reference in New Issue
Block a user