Skip to content

Commit

Permalink
Added monarch.is_loaded()
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Oct 26, 2023
1 parent c473aa0 commit 84944f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions monarch/monarch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ function M.is_visible(id)
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
-- @param id Screen id
-- @return true if the screen is a popup
Expand Down
15 changes: 13 additions & 2 deletions test/test_monarch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,30 @@ return function()
monarch.show(SCREEN1)
assert(wait_until_stack({ SCREEN1 }))
assert(wait_until_visible(SCREEN1))

monarch.show(SCREEN2)
assert(wait_until_stack({ SCREEN1, SCREEN2 }))
assert(wait_until_hidden(SCREEN1))
assert(wait_until_visible(SCREEN2))

monarch.show(POPUP1)
assert(wait_until_stack({ SCREEN1, SCREEN2, POPUP1 }))
assert(wait_until_hidden(SCREEN1))
assert(wait_until_visible(SCREEN2))
assert(wait_until_visible(POPUP1))
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()
monarch.show(BACKGROUND, { no_stack = true })
assert(wait_until_visible(BACKGROUND), "Background was never shown")
Expand Down

0 comments on commit 84944f3

Please sign in to comment.