Skip to content

Commit

Permalink
hide delete button for non-admin users after edit period expires
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal authored and umputun committed Mar 17, 2024
1 parent e574318 commit 5a78169
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function CommentActions({
)}
</>
)}
{(currentUser || admin) && deleteJSX}
{((currentUser && editDeadline !== undefined) || admin) && deleteJSX}
</div>
</div>
);
Expand Down

0 comments on commit 5a78169

Please sign in to comment.