-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide review box if user cannot review access requests (#49937)
oss counterpart for gravitational/teleport.e#5628 This adds some testing to the view as well as the equivalent to the web solution for Connect. Connect was missing the [recently added](#48536) `ReviewRequests` field in the user ACL, so I added it here. Because this is handled in the tsh code, we don't have to worry about backward compatibility here for Connect right?
- Loading branch information
Showing
12 changed files
with
272 additions
and
159 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...packages/shared/components/AccessRequests/ReviewRequests/RequestView/RequestView.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { render, screen } from 'design/utils/testing'; | ||
|
||
import { makeEmptyAttempt, makeSuccessAttempt } from 'shared/hooks/useAsync'; | ||
|
||
import { requestRolePending } from '../../fixtures'; | ||
|
||
import { RequestView, RequestViewProps } from './RequestView'; | ||
import { RequestFlags } from './types'; | ||
|
||
const sampleFlags: RequestFlags = { | ||
canAssume: false, | ||
isAssumed: false, | ||
canDelete: false, | ||
canReview: true, | ||
ownRequest: false, | ||
isPromoted: false, | ||
}; | ||
|
||
const props: RequestViewProps = { | ||
user: 'loggedInUsername', | ||
fetchRequestAttempt: makeSuccessAttempt(requestRolePending), | ||
submitReviewAttempt: makeEmptyAttempt(), | ||
getFlags: () => sampleFlags, | ||
confirmDelete: false, | ||
toggleConfirmDelete: () => null, | ||
submitReview: () => null, | ||
assumeRole: () => null, | ||
fetchSuggestedAccessListsAttempt: makeSuccessAttempt([]), | ||
assumeRoleAttempt: makeEmptyAttempt(), | ||
assumeAccessList: () => null, | ||
deleteRequestAttempt: makeEmptyAttempt(), | ||
deleteRequest: () => null, | ||
}; | ||
|
||
const reviewBoxText = `${props.user} - add a review`; | ||
|
||
test('renders review box if user can review', async () => { | ||
render(<RequestView {...props} />); | ||
expect(screen.getByText(reviewBoxText)).toBeInTheDocument(); | ||
}); | ||
|
||
test('does not render review box if user cannot review', async () => { | ||
render( | ||
<RequestView | ||
{...props} | ||
getFlags={() => ({ | ||
...sampleFlags, | ||
canReview: false, | ||
})} | ||
/> | ||
); | ||
expect(screen.queryByText(reviewBoxText)).not.toBeInTheDocument(); | ||
}); |
Oops, something went wrong.