Skip to content

Commit

Permalink
AddFile disabled if user has no create permission.
Browse files Browse the repository at this point in the history
  • Loading branch information
adcoelho committed Mar 27, 2023
1 parent 9fefef4 commit bccf790
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
11 changes: 11 additions & 0 deletions x-pack/plugins/cases/public/components/files/add_file.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { AppMockRenderer } from '../../common/mock';

import { constructFileKindIdByOwner } from '../../../common/constants';
import {
buildCasesPermissions,
createAppMockRenderer,
mockedTestProvidersOwner,
mockedFilesClient,
Expand Down Expand Up @@ -107,6 +108,16 @@ describe('AddFile', () => {
expect(await screen.findByTestId('cases-files-add')).toBeInTheDocument();
});

it('add button disable if user has no creat permission', async () => {
appMockRender = createAppMockRenderer({
permissions: buildCasesPermissions({ create: false }),
});

appMockRender.render(<AddFile caseId={'foobar'} />);

expect(await screen.findByTestId('cases-files-add')).toBeDisabled();
});

it('clicking button renders modal', async () => {
appMockRender.render(<AddFile caseId={'foobar'} />);

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/components/files/add_file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface AddFileProps {
}

const AddFileComponent: React.FC<AddFileProps> = ({ caseId }) => {
const { owner } = useCasesContext();
const { owner, permissions } = useCasesContext();
const { client: filesClient } = useFilesContext();
const { showDangerToast, showErrorToast, showSuccessToast } = useCasesToast();
const { isLoading, createAttachments } = useCreateAttachments();
Expand Down Expand Up @@ -122,7 +122,7 @@ const AddFileComponent: React.FC<AddFileProps> = ({ caseId }) => {
<EuiButton
data-test-subj="cases-files-add"
iconType="plusInCircle"
isDisabled={isLoading}
isDisabled={isLoading || !permissions.create}
isLoading={isLoading}
onClick={showModal}
>
Expand Down
20 changes: 0 additions & 20 deletions x-pack/plugins/cases/public/components/files/file_preview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import React from 'react';

import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import type { AppMockRenderer } from '../../common/mock';

Expand Down Expand Up @@ -44,23 +43,4 @@ describe('FilePreview', () => {

expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument();
});

// I cannot get this test to work
it.skip('clicking outside Image triggers closePreview', () => {
const mockClosePreview = jest.fn();

appMockRender.render(
<>
<div data-test-subj="outsideClickDummy" />
<FilePreview
closePreview={mockClosePreview}
selectedFile={basicFileMock}
getDownloadHref={jest.fn()}
/>
</>
);

userEvent.click(screen.getByTestId('outsideClickDummy'));
expect(mockClosePreview).toBeCalled();
});
});

0 comments on commit bccf790

Please sign in to comment.