Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix editing mode #1350

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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