hide delete button for non-admin users after edit period expires

This commit is contained in:
Dmitry Verkhoturov
2024-03-17 16:47:28 -05:00
committed by Umputun
parent e5743185b0
commit 5a781693aa
2 changed files with 10 additions and 2 deletions
@@ -89,12 +89,20 @@ describe('<CommentActions/>', () => {
expect(screen.getByText('Hide')).toBeInTheDocument();
});
it('should render "Delete" for current user comments', () => {
it('should render "Delete" for current user comments when editing is available', () => {
props.currentUser = true;
props.editDeadline = Date.now() + 300 * 1000; // set editDeadline to a future timestamp
render(<CommentActions {...props} />);
expect(screen.getByText('Delete')).toBeInTheDocument();
});
it('should not render "Delete" for current user comments when editDeadline is undefined', () => {
props.currentUser = true;
props.editDeadline = undefined; // set editDeadline to undefined
render(<CommentActions {...props} />);
expect(screen.queryByText('Delete')).not.toBeInTheDocument();
});
it('should not render "Delete" for other users comments', () => {
render(<CommentActions {...props} />);
expect(screen.queryByText('Delete')).not.toBeInTheDocument();
@@ -113,7 +113,7 @@ export function CommentActions({
)}
</>
)}
{(currentUser || admin) && deleteJSX}
{((currentUser && editDeadline !== undefined) || admin) && deleteJSX}
</div>
</div>
);