|
|
@@ -1,12 +1,11 @@
|
|
|
import '@testing-library/jest-dom/vitest';
|
|
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
-import { PointerEventsCheckLevel, userEvent } from '@testing-library/user-event';
|
|
|
import {
|
|
|
describe, it, expect, vi,
|
|
|
} from 'vitest';
|
|
|
|
|
|
-import { CommentControl } from './PageComment/CommentControl';
|
|
|
+import { NotAvailableIfReadOnlyUserNotAllowedToComment } from './NotAvailableForReadOnlyUser';
|
|
|
|
|
|
const useIsReadOnlyUser = vi.hoisted(() => vi.fn().mockReturnValue({ data: true }));
|
|
|
const useIsRomUserAllowedToComment = vi.hoisted(() => vi.fn().mockReturnValue({ data: true }));
|
|
|
@@ -18,28 +17,21 @@ vi.mock('~/stores-universal/context', () => ({
|
|
|
|
|
|
describe('NotAvailableForReadOnlyUser.tsx', () => {
|
|
|
|
|
|
- const onClickEditBtnMock = vi.fn();
|
|
|
- const onClickDeleteBtnMock = vi.fn();
|
|
|
- const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
|
|
|
-
|
|
|
it('renders NotAvailable component as enable when user is read-only and comments by rom users is allowed', async() => {
|
|
|
useIsReadOnlyUser.mockReturnValue({ data: true });
|
|
|
useIsRomUserAllowedToComment.mockReturnValue({ data: true });
|
|
|
|
|
|
render(
|
|
|
- <CommentControl
|
|
|
- onClickEditBtn={onClickEditBtnMock}
|
|
|
- onClickDeleteBtn={onClickDeleteBtnMock}
|
|
|
- />,
|
|
|
+ <NotAvailableIfReadOnlyUserNotAllowedToComment>
|
|
|
+ <div data-testid="test-child">Test Child</div>
|
|
|
+ </NotAvailableIfReadOnlyUserNotAllowedToComment>,
|
|
|
);
|
|
|
|
|
|
// when
|
|
|
- const button = screen.getByTestId('comment-delete-button');
|
|
|
- const wrapperElement = button.parentElement;
|
|
|
- await user.click(button);
|
|
|
+ const element = screen.getByTestId('test-child');
|
|
|
+ const wrapperElement = element.parentElement;
|
|
|
|
|
|
// then
|
|
|
- expect(onClickDeleteBtnMock).toHaveBeenCalled();
|
|
|
expect(wrapperElement).not.toHaveAttribute('aria-hidden', 'true');
|
|
|
});
|
|
|
|
|
|
@@ -48,15 +40,14 @@ describe('NotAvailableForReadOnlyUser.tsx', () => {
|
|
|
useIsRomUserAllowedToComment.mockReturnValue({ data: false });
|
|
|
|
|
|
render(
|
|
|
- <CommentControl
|
|
|
- onClickEditBtn={onClickEditBtnMock}
|
|
|
- onClickDeleteBtn={onClickDeleteBtnMock}
|
|
|
- />,
|
|
|
+ <NotAvailableIfReadOnlyUserNotAllowedToComment>
|
|
|
+ <div data-testid="test-child">Test Child</div>
|
|
|
+ </NotAvailableIfReadOnlyUserNotAllowedToComment>,
|
|
|
);
|
|
|
|
|
|
// when
|
|
|
- const button = screen.getByTestId('comment-delete-button');
|
|
|
- const wrapperElement = button.parentElement;
|
|
|
+ const element = screen.getByTestId('test-child');
|
|
|
+ const wrapperElement = element.parentElement;
|
|
|
|
|
|
// then
|
|
|
expect(wrapperElement).toHaveAttribute('aria-hidden', 'true');
|
|
|
@@ -67,19 +58,16 @@ describe('NotAvailableForReadOnlyUser.tsx', () => {
|
|
|
useIsRomUserAllowedToComment.mockReturnValue({ data: true });
|
|
|
|
|
|
render(
|
|
|
- <CommentControl
|
|
|
- onClickEditBtn={onClickEditBtnMock}
|
|
|
- onClickDeleteBtn={onClickDeleteBtnMock}
|
|
|
- />,
|
|
|
+ <NotAvailableIfReadOnlyUserNotAllowedToComment>
|
|
|
+ <div data-testid="test-child">Test Child</div>
|
|
|
+ </NotAvailableIfReadOnlyUserNotAllowedToComment>,
|
|
|
);
|
|
|
|
|
|
// when
|
|
|
- const button = screen.getByTestId('comment-delete-button');
|
|
|
- const wrapperElement = button.parentElement;
|
|
|
- await user.click(button);
|
|
|
+ const element = screen.getByTestId('test-child');
|
|
|
+ const wrapperElement = element.parentElement;
|
|
|
|
|
|
// then
|
|
|
- expect(onClickDeleteBtnMock).toHaveBeenCalled();
|
|
|
expect(wrapperElement).not.toHaveAttribute('aria-hidden', 'true');
|
|
|
});
|
|
|
|
|
|
@@ -88,19 +76,16 @@ describe('NotAvailableForReadOnlyUser.tsx', () => {
|
|
|
useIsRomUserAllowedToComment.mockReturnValue({ data: false });
|
|
|
|
|
|
render(
|
|
|
- <CommentControl
|
|
|
- onClickEditBtn={onClickEditBtnMock}
|
|
|
- onClickDeleteBtn={onClickDeleteBtnMock}
|
|
|
- />,
|
|
|
+ <NotAvailableIfReadOnlyUserNotAllowedToComment>
|
|
|
+ <div data-testid="test-child">Test Child</div>
|
|
|
+ </NotAvailableIfReadOnlyUserNotAllowedToComment>,
|
|
|
);
|
|
|
|
|
|
// when
|
|
|
- const button = screen.getByTestId('comment-delete-button');
|
|
|
- const wrapperElement = button.parentElement;
|
|
|
- await user.click(button);
|
|
|
+ const element = screen.getByTestId('test-child');
|
|
|
+ const wrapperElement = element.parentElement;
|
|
|
|
|
|
// then
|
|
|
- expect(onClickDeleteBtnMock).toHaveBeenCalled();
|
|
|
expect(wrapperElement).not.toHaveAttribute('aria-hidden', 'true');
|
|
|
});
|
|
|
|