FEAT [GUI] Display signed-in user info in top bar and populate operator label with username#1636
FEAT [GUI] Display signed-in user info in top bar and populate operator label with username#1636behnam-o wants to merge 17 commits intomicrosoft:mainfrom
Conversation
|
Needs tests for when it can't resolve the user. For example, if you're running it locally and aren't logged in. Also, this should auto-populate the operator (with alias presumably?) so that people don't have to keep re-setting that. |
| </TestWrapper> | ||
| ) | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: /log in/i })) |
There was a problem hiding this comment.
this should prob be userEvent instead of fireEvent
you can do something like
const user = userEvent.setup()
// ...render...
await user.click(screen.getByRole('button', { name: /log in/i }))
For the popover test (Sign Out), you do two sequential clicks — 1) open the popover, 2) click "Sign Out" inside it. With fireEvent you won't care about whether it has actually rendered or whether the element is visible/interactable vs w the userEvent.click you simulate the full browser interaction chain
| fireEvent.click(screen.getByRole('button', { name: /alice smith/i })) | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: /sign out/i })) | ||
|
|
There was a problem hiding this comment.
similarly here think it should be something like:
const user = userEvent.setup()
// ...render...
await user.click(screen.getByRole('button', { name: /alice smith/i }))
await user.click(screen.getByRole('button', { name: /sign out/i }))
expect(mockLogoutRedirect).toHaveBeenCalled()
})
| import { render, screen, fireEvent } from '@testing-library/react' | ||
| import { FluentProvider, webLightTheme } from '@fluentui/react-components' | ||
| import { UserAccountButton } from './UserAccountButton' | ||
|
|
There was a problem hiding this comment.
add import userEvent from '@testing-library/user-event'
| expect.any(String) | ||
| ) | ||
| }) | ||
|
|
There was a problem hiding this comment.
are these new lines needed? i don't think they are but correct me if I'm wrong :)
| ) | ||
| } | ||
|
|
||
| const displayName = account.name ?? account.username ?? 'User' |
There was a problem hiding this comment.
nit: maybe change to || instead of ?? to catch the empty string vs the ?? will let it pass through i think!
| <Button | ||
| appearance="subtle" | ||
| icon={<PersonRegular />} | ||
| onClick={() => instance.loginRedirect(buildLoginRequest(config.clientId))} |
There was a problem hiding this comment.
nit: add checking for failure here?
onClick={() => {
instance.loginRedirect(buildLoginRequest(config.clientId)).catch((err) => {
console.error('Login redirect failed:', err)
})
}}
| )} | ||
| <Button | ||
| appearance="secondary" | ||
| onClick={() => instance.logoutRedirect()} |
There was a problem hiding this comment.
nit: and add similar error catch here too?
Adds a component to display the currently-signed-in user on the top right of the GUI, and sets the operator label value as the username on load/login
This is what it looks like:

If running locally, the top bar component is not added, and the label value is not updated. i.e.

Note:
Testing in local is a little tricky in our current setup, because we have some logic in place to bypass auth altogether if a local env is detected. We need to fix that, but this is the workaround I used to force auth on local env, to test this change:
ENTRA_TENANT_IDandENTRA_CLIENT_IDevn variables (from above) before runningpython dev.py start(which starts the backend and front end)["openid"]instead of["api://***"](this basically means 'https://graph.microsoft.com/openid')