Skip to main content
April 12, 2024
Question

Testing interface that with different "loggedInUsers"

  • April 12, 2024
  • 7 replies
  • 0 views

My interface hides or shows buttons based on the users role, determined by "loggedInUser()".   I would like to test the interface mocking different logged in users.   Is there a way to achieve that?

7 replies

karumurua531442
April 12, 2024

Hi [mention:2d0cc1a668b6458992897652c53bf812:e9ed411860ed4f2ba0265705b8793d05] Yes you can do that for buttons you will have showWhen condition, check the loggedInUsser is part that of that group based on that you can display the buttons

konduruc733182
April 12, 2024

Hello [mention:2d0cc1a668b6458992897652c53bf812:e9ed411860ed4f2ba0265705b8793d05] 

You would simply have to have a list of usernames in a constant and keep testing it in place of the loggedInUser(). Also you can add/remove yourself in the groups and try it out.

csteward
April 12, 2024

I always recommend storing the loggedInUser() to a local variable, and using the local variable throughout the interface.  This way, you can test all interface differences based on the user by temporarily updating the local!user variable in one place:

a!localVariables(
  /*local!user: loggedInUser(),*/
  local!user: touser("user.name"),
  
  ...
)

Further preferred on my end, by using something such as a constant on each server holding the name of your server, this code is safer by preventing unwanted functionality if you forget to change the commenting back prior to deployment (happens..):

a!localVariables(
  local!user: if(
    cons!SERVER_NAME="DEV",
    touser("user.name"),
    loggedInUser()
  ),
  
  ...
)

April 12, 2024

Thank you Chris - that is what I am doing, however I want to be able to pass in user as logged in User so I can test the interface through different scenarios without having to touch the code itself.

mikes0011
Brainy
April 12, 2024
however I want to be able to pass in user as logged in User

local!currentUser: a!defaultValue(ri!overrideUsername, loggedinuser()),