Skip to content

Commit

Permalink
fix editing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
akellbl4 authored and umputun committed May 10, 2022
1 parent b82ed82 commit 9053668
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
30 changes: 21 additions & 9 deletions frontend/app/components/comment/comment-actions.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { h } from 'preact';
import '@testing-library/jest-dom';
import { CommentActions, Props } from './comment-actions';
import { render } from 'tests/utils';
import { screen, waitFor } from '@testing-library/preact';
import { fireEvent, screen, waitFor } from '@testing-library/preact';

function getProps(): Props {
return {
Expand All @@ -14,14 +14,15 @@ function getProps(): Props {
readOnly: false,
editing: false,
replying: false,
onCopy() {},
onDelete() {},
onTogglePin() {},
onToggleReplying() {},
onHideUser() {},
onBlockUser() {},
onUnblockUser() {},
onDisableEditing() {},
onCopy: jest.fn(),
onDelete: jest.fn(),
onToggleEditing: jest.fn(),
onTogglePin: jest.fn(),
onToggleReplying: jest.fn(),
onHideUser: jest.fn(),
onBlockUser: jest.fn(),
onUnblockUser: jest.fn(),
onDisableEditing: jest.fn(),
editable: false,
editDeadline: undefined,
};
Expand All @@ -32,6 +33,9 @@ describe('<CommentActions/>', () => {
beforeEach(() => {
props = getProps();
});
afterEach(() => {
jest.resetAllMocks();
})

it('should render "Reply"', () => {
render(<CommentActions {...props} />);
Expand Down Expand Up @@ -139,5 +143,13 @@ describe('<CommentActions/>', () => {
expect(screen.getByTestId('comment-actions-additional').children[3]).toHaveTextContent('Block');
expect(screen.getByTestId('comment-actions-additional').children[4]).toHaveTextContent('Delete');
});

it('calls `onToggleEditing` when edit button is pressed', () => {
render(<CommentActions {...props} />);
fireEvent(screen.getByText('Edit'), new MouseEvent('click', { bubbles: true }));
expect(props.onToggleEditing).toHaveBeenCalledTimes(1);
fireEvent(screen.getByText('Cancel'), new MouseEvent('click', { bubbles: true }));
expect(props.onToggleEditing).toHaveBeenCalledTimes(2);
})
});
});
4 changes: 3 additions & 1 deletion frontend/app/components/comment/comment-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type Props = {
editable: boolean;
editDeadline: number | undefined;
onCopy(): void;
onToggleEditing(): void;
onDelete(): void;
onTogglePin(): void;
onToggleReplying(): void;
Expand All @@ -43,6 +44,7 @@ export function CommentActions({
bannedUser,
editDeadline,
onCopy,
onToggleEditing,
onDelete,
onTogglePin,
onToggleReplying,
Expand All @@ -68,7 +70,7 @@ export function CommentActions({
)}
{editable && editDeadline && (
<>
<Button kind="link" size="sm">
<Button kind="link" size="sm" onClick={onToggleEditing}>
{intl.formatMessage(editing ? messages.cancel : messages.edit)}
</Button>
<span
Expand Down
1 change: 1 addition & 0 deletions frontend/app/components/comment/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ export class Comment extends Component<CommentProps, State> {
bannedUser={props.isUserBanned}
onCopy={this.copyComment}
onTogglePin={this.togglePin}
onToggleEditing={this.toggleEditing}
onDelete={this.deleteComment}
onHideUser={this.hideUser}
onBlockUser={this.blockUser}
Expand Down

0 comments on commit 9053668

Please sign in to comment.