|
|
@@ -15,14 +15,14 @@
|
|
|
// limitations under the License.
|
|
|
|
|
|
import React from 'react';
|
|
|
-import { render, screen } from '@testing-library/react';
|
|
|
+import { act, render, screen, waitFor } from '@testing-library/react';
|
|
|
import userEvent from '@testing-library/user-event';
|
|
|
import '@testing-library/jest-dom';
|
|
|
|
|
|
import FileAndFolderActions from './FileAndFolderActions';
|
|
|
import { StorageDirectoryTableData } from '../../../types';
|
|
|
import { get } from '../../../../../api/utils';
|
|
|
-import huePubSub from '../../../../../utils/huePubSub';
|
|
|
+import { DOWNLOAD_API_URL } from '../../../api';
|
|
|
|
|
|
jest.mock('../../../../../api/utils', () => ({
|
|
|
get: jest.fn()
|
|
|
@@ -45,6 +45,10 @@ jest.mock('config/hueConfig', () => ({
|
|
|
const mockGet = get as jest.MockedFunction<typeof get>;
|
|
|
|
|
|
describe('FileAndFolderActions', () => {
|
|
|
+ beforeEach(() => {
|
|
|
+ jest.clearAllMocks();
|
|
|
+ });
|
|
|
+
|
|
|
//View summary option is enabled and added to the actions menu when the row data is either hdfs/ofs and a single file
|
|
|
const mockTwoRecords: StorageDirectoryTableData[] = [
|
|
|
{
|
|
|
@@ -111,7 +115,7 @@ describe('FileAndFolderActions', () => {
|
|
|
currentPath="/path/to/folder"
|
|
|
/>
|
|
|
);
|
|
|
- await user.click(getByRole('button'));
|
|
|
+ await act(() => user.click(getByRole('button')));
|
|
|
};
|
|
|
|
|
|
describe('Summary option', () => {
|
|
|
@@ -143,136 +147,153 @@ describe('FileAndFolderActions', () => {
|
|
|
|
|
|
it('should not render summary option when there are multiple records selected', async () => {
|
|
|
await setUpActionMenu(mockTwoRecords);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Summary' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Summary' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render summary option when record is a hdfs file', async () => {
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Summary' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Summary' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render summary option when record is a ofs file', async () => {
|
|
|
await setUpActionMenu([mockRecord], 'ofs://demo/test', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Summary' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Summary' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render summary option when record is a hdfs folder', async () => {
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test', 'dir');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Summary' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Summary' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render summary option when record is a an abfs file', async () => {
|
|
|
await setUpActionMenu([mockRecord], 'abfs://demo/test', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Summary' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Summary' })).toBeNull());
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('Rename option', () => {
|
|
|
it('should not render rename option when there are multiple records selected', async () => {
|
|
|
await setUpActionMenu(mockTwoRecords);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull());
|
|
|
});
|
|
|
it('should 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();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should 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();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should 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();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should 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();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should 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();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should 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();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Rename' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render 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();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Rename' })).not.toBeNull());
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('Set replication option', () => {
|
|
|
it('should not render set replication option when there are multiple records selected', async () => {
|
|
|
await setUpActionMenu(mockTwoRecords);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render set replication option when selected record is a hdfs file', async () => {
|
|
|
await setUpActionMenu([mockRecord], 'hdfs://test', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).not.toBeNull();
|
|
|
+ waitFor(() =>
|
|
|
+ expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).not.toBeNull()
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
it('should not render set replication option when selected record is a hdfs folder', async () => {
|
|
|
await setUpActionMenu([mockRecord], 'hdfs://', 'dir');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render set replication option when selected record is a gs file/folder', async () => {
|
|
|
await setUpActionMenu([mockRecord], 'gs://', 'dir');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render set replication option when selected record is a s3 file/folder', async () => {
|
|
|
await setUpActionMenu([mockRecord], 's3a://', 'dir');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render set replication option when selected record is a ofs file/folder', async () => {
|
|
|
await setUpActionMenu([mockRecord], 'ofs://', 'dir');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Set Replication' })).toBeNull());
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('Delete option', () => {
|
|
|
it('should render delete option for multiple selected records', async () => {
|
|
|
await setUpActionMenu(mockTwoRecords, mockRecord.path);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Delete' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Delete' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render delete option for a single selected file/folder', async () => {
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Delete' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Delete' })).not.toBeNull());
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('Download option', () => {
|
|
|
+ const originalLocation = window.location;
|
|
|
+ beforeEach(() => {
|
|
|
+ Object.defineProperty(window, 'location', {
|
|
|
+ writable: true,
|
|
|
+ value: { href: '' }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ afterAll(() => {
|
|
|
+ Object.defineProperty(window, 'location', {
|
|
|
+ writable: true,
|
|
|
+ value: originalLocation
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
it('should not render download option for multiple selected records', async () => {
|
|
|
await setUpActionMenu(mockTwoRecords);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Download' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Download' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render download option for a single selected file', async () => {
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Download' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Download' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render download option for a folder', async () => {
|
|
|
const mockFolder = { ...mockRecord, type: 'dir' };
|
|
|
await setUpActionMenu([mockFolder], '/user/demo/test', 'dir');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Download' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Download' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render download option when enable_file_download_button is false', async () => {
|
|
|
mockLastConfig.storage_browser.enable_file_download_button = false;
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Download' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Download' })).toBeNull());
|
|
|
mockLastConfig.storage_browser.enable_file_download_button = true;
|
|
|
});
|
|
|
|
|
|
@@ -280,64 +301,64 @@ describe('FileAndFolderActions', () => {
|
|
|
const user = userEvent.setup();
|
|
|
await setUpActionMenu([mockRecord], mockRecord.path, 'file');
|
|
|
await user.click(screen.getByRole('menuitem', { name: 'Download' }));
|
|
|
- expect(huePubSub.publish).toHaveBeenCalled();
|
|
|
+ waitFor(() => expect(window.location.href).toContain(DOWNLOAD_API_URL));
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('Copy Action', () => {
|
|
|
it('should render copy option when record is a file', async () => {
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Copy' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Copy' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render copy option when record is a folder', async () => {
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test', 'dir');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Copy' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Copy' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render copy option when multiple records are selected', async () => {
|
|
|
await setUpActionMenu(mockTwoRecords);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Copy' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Copy' })).not.toBeNull());
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('Move Action', () => {
|
|
|
it('should render move option when record is a file', async () => {
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Move' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Move' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render move option when record is a folder', async () => {
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test', 'dir');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Move' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Move' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render move option when multiple records are selected', async () => {
|
|
|
await setUpActionMenu(mockTwoRecords);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Move' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Move' })).not.toBeNull());
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('Compress Action', () => {
|
|
|
it('should render compress option when record is a hdfs file', async () => {
|
|
|
await setUpActionMenu([mockRecord], mockRecord.path, mockRecord.type);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Compress' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Compress' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render compress option when multiple records are hdfs file', async () => {
|
|
|
await setUpActionMenu(mockTwoRecords);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Compress' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Compress' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should render compress option when record is not hdfs file', async () => {
|
|
|
await setUpActionMenu([mockRecord], 's3a://', 'dir');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Compress' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Compress' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render compress option when enable_extract_uploaded_archive is false', async () => {
|
|
|
mockLastConfig.storage_browser.enable_extract_uploaded_archive = false;
|
|
|
await setUpActionMenu(mockTwoRecords);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Compress' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Compress' })).toBeNull());
|
|
|
mockLastConfig.storage_browser.enable_extract_uploaded_archive = true;
|
|
|
});
|
|
|
});
|
|
|
@@ -346,24 +367,24 @@ describe('FileAndFolderActions', () => {
|
|
|
it('should render extract option when record is a compressed file', async () => {
|
|
|
mockRecord.path = '/user/demo/test.zip';
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test.zip', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Extract' })).not.toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Extract' })).not.toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render extract option when multiple records are files', async () => {
|
|
|
await setUpActionMenu(mockTwoRecords);
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Extract' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Extract' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render extract option when file type is not supported', async () => {
|
|
|
mockRecord.path = '/user/demo/test.zip1';
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test.zip1', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Extract' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Extract' })).toBeNull());
|
|
|
});
|
|
|
|
|
|
it('should not render extract option when enable_extract_uploaded_archive is false', async () => {
|
|
|
mockLastConfig.storage_browser.enable_extract_uploaded_archive = false;
|
|
|
await setUpActionMenu([mockRecord], '/user/demo/test.zip', 'file');
|
|
|
- expect(screen.queryByRole('menuitem', { name: 'Extract' })).toBeNull();
|
|
|
+ waitFor(() => expect(screen.queryByRole('menuitem', { name: 'Extract' })).toBeNull());
|
|
|
mockLastConfig.storage_browser.enable_extract_uploaded_archive = true;
|
|
|
});
|
|
|
});
|