|
@@ -14,12 +14,17 @@
|
|
|
// See the License for the specific language governing permissions and
|
|
// See the License for the specific language governing permissions and
|
|
|
// limitations under the License.
|
|
// limitations under the License.
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
-import { render } from '@testing-library/react';
|
|
|
|
|
|
|
+import { render, screen } from '@testing-library/react';
|
|
|
import userEvent from '@testing-library/user-event';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
import '@testing-library/jest-dom';
|
|
import '@testing-library/jest-dom';
|
|
|
|
|
|
|
|
import StorageBrowserActions from './StorageBrowserActions';
|
|
import StorageBrowserActions from './StorageBrowserActions';
|
|
|
-import { StorageBrowserTableData } from '../../../../reactComponents/FileChooser/types';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ StorageBrowserTableData,
|
|
|
|
|
+ ContentSummary
|
|
|
|
|
+} from '../../../../reactComponents/FileChooser/types';
|
|
|
|
|
+import * as StorageBrowserApi from '../../../../reactComponents/FileChooser/api';
|
|
|
|
|
+import { CancellablePromise } from '../../../../api/cancellablePromise';
|
|
|
|
|
|
|
|
describe('StorageBrowserRowActions', () => {
|
|
describe('StorageBrowserRowActions', () => {
|
|
|
//View summary option is enabled and added to the actions menu when the row data is either hdfs/ofs and a single file
|
|
//View summary option is enabled and added to the actions menu when the row data is either hdfs/ofs and a single file
|
|
@@ -33,7 +38,7 @@ describe('StorageBrowserRowActions', () => {
|
|
|
type: '',
|
|
type: '',
|
|
|
path: ''
|
|
path: ''
|
|
|
};
|
|
};
|
|
|
- const mockRecord2: StorageBrowserTableData[] = [
|
|
|
|
|
|
|
+ const mockTwoRecords: StorageBrowserTableData[] = [
|
|
|
{
|
|
{
|
|
|
name: 'test',
|
|
name: 'test',
|
|
|
size: '0\u00a0bytes',
|
|
size: '0\u00a0bytes',
|
|
@@ -56,56 +61,137 @@ describe('StorageBrowserRowActions', () => {
|
|
|
}
|
|
}
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- test('does not render view summary option when there are multiple records', async () => {
|
|
|
|
|
- const user = userEvent.setup();
|
|
|
|
|
- const { getByRole, queryByRole } = render(
|
|
|
|
|
- <StorageBrowserActions selectedFiles={mockRecord2} />
|
|
|
|
|
- );
|
|
|
|
|
- await user.click(getByRole('button'));
|
|
|
|
|
- expect(queryByRole('menuitem', { name: 'View Summary' })).toBeNull();
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const setLoadingFiles = jest.fn();
|
|
|
|
|
+ const onSuccessfulAction = jest.fn();
|
|
|
|
|
|
|
|
- test('renders view summary option when record is a hdfs file', async () => {
|
|
|
|
|
|
|
+ const setUpActionMenu = async (
|
|
|
|
|
+ records: StorageBrowserTableData[],
|
|
|
|
|
+ recordPath?: string,
|
|
|
|
|
+ recordType?: string
|
|
|
|
|
+ ) => {
|
|
|
const user = userEvent.setup();
|
|
const user = userEvent.setup();
|
|
|
- mockRecord.path = '/user/demo/test';
|
|
|
|
|
- mockRecord.type = 'file';
|
|
|
|
|
- const { getByRole, queryByRole } = render(
|
|
|
|
|
- <StorageBrowserActions selectedFiles={[mockRecord]} />
|
|
|
|
|
|
|
+ if (recordPath) {
|
|
|
|
|
+ records[0].path = recordPath;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (recordType) {
|
|
|
|
|
+ records[0].type = recordType;
|
|
|
|
|
+ }
|
|
|
|
|
+ const { getByRole } = render(
|
|
|
|
|
+ <StorageBrowserActions
|
|
|
|
|
+ setLoadingFiles={setLoadingFiles}
|
|
|
|
|
+ onSuccessfulAction={onSuccessfulAction}
|
|
|
|
|
+ selectedFiles={records}
|
|
|
|
|
+ />
|
|
|
);
|
|
);
|
|
|
await user.click(getByRole('button'));
|
|
await user.click(getByRole('button'));
|
|
|
- expect(queryByRole('menuitem', { name: 'View Summary' })).not.toBeNull();
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- test('renders view summary option when record is a ofs file', async () => {
|
|
|
|
|
- const user = userEvent.setup();
|
|
|
|
|
- mockRecord.path = 'ofs://demo/test';
|
|
|
|
|
- mockRecord.type = 'file';
|
|
|
|
|
- const { getByRole, queryByRole } = render(
|
|
|
|
|
- <StorageBrowserActions selectedFiles={[mockRecord]} />
|
|
|
|
|
- );
|
|
|
|
|
- await user.click(getByRole('button'));
|
|
|
|
|
- expect(queryByRole('menuitem', { name: 'View Summary' })).not.toBeNull();
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ describe('Summary option', () => {
|
|
|
|
|
+ let summaryApiMock;
|
|
|
|
|
|
|
|
- test('does not render view summary option when record is a hdfs folder', async () => {
|
|
|
|
|
- const user = userEvent.setup();
|
|
|
|
|
- mockRecord.path = '/user/demo/test';
|
|
|
|
|
- mockRecord.type = 'dir';
|
|
|
|
|
- const { getByRole, queryByRole } = render(
|
|
|
|
|
- <StorageBrowserActions selectedFiles={[mockRecord]} />
|
|
|
|
|
- );
|
|
|
|
|
- await user.click(getByRole('button'));
|
|
|
|
|
- expect(queryByRole('menuitem', { name: 'View Summary' })).toBeNull();
|
|
|
|
|
|
|
+ const mockSummaryData = {
|
|
|
|
|
+ summary: {
|
|
|
|
|
+ directoryCount: 0,
|
|
|
|
|
+ ecPolicy: 'Replicated',
|
|
|
|
|
+ fileCount: 1,
|
|
|
|
|
+ length: 0,
|
|
|
|
|
+ quota: -1,
|
|
|
|
|
+ spaceConsumed: 0,
|
|
|
|
|
+ spaceQuota: -1,
|
|
|
|
|
+ typeQuota: -1,
|
|
|
|
|
+ replication: 3
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const setUpMock = () => {
|
|
|
|
|
+ summaryApiMock = jest
|
|
|
|
|
+ .spyOn(StorageBrowserApi, 'fetchContentSummary')
|
|
|
|
|
+ .mockReturnValue(CancellablePromise.resolve<ContentSummary>(mockSummaryData));
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ afterEach(() => {
|
|
|
|
|
+ summaryApiMock?.mockClear();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('does not render view summary option when there are multiple records selected', async () => {
|
|
|
|
|
+ await setUpActionMenu(mockTwoRecords);
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'View Summary' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('renders view summary option when record is a hdfs file', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], '/user/demo/test', 'file');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'View Summary' })).not.toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('renders view summary option when record is a ofs file', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 'ofs://demo/test', 'file');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'View Summary' })).not.toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('does not render view summary option when record is a hdfs folder', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], '/user/demo/test', 'dir');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'View Summary' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('does not render view summary option when record is a an abfs file', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 'abfs://demo/test', 'file');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'View Summary' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('renders summary modal when view summary option is clicked', async () => {
|
|
|
|
|
+ const user = userEvent.setup();
|
|
|
|
|
+ setUpMock();
|
|
|
|
|
+ await setUpActionMenu([mockRecord], '/user/demo/test', 'file');
|
|
|
|
|
+ await user.click(screen.queryByRole('menuitem', { name: 'View Summary' }));
|
|
|
|
|
+ expect(await screen.findByText('Summary for /user/demo/test')).toBeInTheDocument();
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- test('does not render view summary option when record is a an abfs file', async () => {
|
|
|
|
|
- const user = userEvent.setup();
|
|
|
|
|
- mockRecord.path = 'abfs://demo/test';
|
|
|
|
|
- mockRecord.type = 'file';
|
|
|
|
|
- const { getByRole, queryByRole } = render(
|
|
|
|
|
- <StorageBrowserActions selectedFiles={[mockRecord]} />
|
|
|
|
|
- );
|
|
|
|
|
- await user.click(getByRole('button'));
|
|
|
|
|
- expect(queryByRole('menuitem', { name: 'View Summary' })).toBeNull();
|
|
|
|
|
|
|
+ describe('Rename option', () => {
|
|
|
|
|
+ test('does not render view summary option when there are multiple records selected', async () => {
|
|
|
|
|
+ await setUpActionMenu(mockTwoRecords);
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+ test('does not render rename option when selected record is a abfs root folder', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 'abfs://', 'dir');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('does not render rename option when selected record is a gs root folder', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 'gs://', 'dir');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('does not render rename option when selected record is a s3 root folder', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 's3a://', 'dir');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('does not render rename option when selected record is a ofs root folder', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 'ofs://', 'dir');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('does not render rename option when selected record is a ofs service ID folder', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 'ofs://serviceID', 'dir');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('does not render rename option when selected record is a ofs volume folder', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 'ofs://serviceID/volume', 'dir');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('renders rename option when selected record is a file or a folder', async () => {
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 'abfs://test', 'dir');
|
|
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'Rename' })).not.toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('renders rename modal when rename option is clicked', async () => {
|
|
|
|
|
+ const user = userEvent.setup();
|
|
|
|
|
+ await setUpActionMenu([mockRecord], 'abfs://test', 'dir');
|
|
|
|
|
+ await user.click(screen.queryByRole('menuitem', { name: 'Rename' }));
|
|
|
|
|
+ expect(await screen.findByText('Enter new name here')).toBeInTheDocument();
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|