|
@@ -1,9 +1,27 @@
|
|
|
|
|
+// Licensed to Cloudera, Inc. under one
|
|
|
|
|
+// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
+// distributed with this work for additional information
|
|
|
|
|
+// regarding copyright ownership. Cloudera, Inc. licenses this file
|
|
|
|
|
+// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
+// "License"); you may not use this file except in compliance
|
|
|
|
|
+// with the License. You may obtain a copy of the License at
|
|
|
|
|
+//
|
|
|
|
|
+// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
+//
|
|
|
|
|
+// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
+// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
+// See the License for the specific language governing permissions and
|
|
|
|
|
+// limitations under the License.
|
|
|
|
|
+
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
|
import StorageFilePage from './StorageFilePage';
|
|
import StorageFilePage from './StorageFilePage';
|
|
|
import { PathAndFileData } from '../../../reactComponents/FileChooser/types';
|
|
import { PathAndFileData } from '../../../reactComponents/FileChooser/types';
|
|
|
import '@testing-library/jest-dom';
|
|
import '@testing-library/jest-dom';
|
|
|
import userEvent from '@testing-library/user-event';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
|
+import { DOWNLOAD_API_URL } from '../../../reactComponents/FileChooser/api';
|
|
|
|
|
+import huePubSub from '../../../utils/huePubSub';
|
|
|
|
|
|
|
|
jest.mock('../../../utils/dateTimeUtils', () => ({
|
|
jest.mock('../../../utils/dateTimeUtils', () => ({
|
|
|
...jest.requireActual('../../../utils/dateTimeUtils'),
|
|
...jest.requireActual('../../../utils/dateTimeUtils'),
|
|
@@ -12,6 +30,10 @@ jest.mock('../../../utils/dateTimeUtils', () => ({
|
|
|
}
|
|
}
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
|
|
+jest.mock('../../../utils/huePubSub', () => ({
|
|
|
|
|
+ publish: jest.fn()
|
|
|
|
|
+}));
|
|
|
|
|
+
|
|
|
// Mock data for fileData
|
|
// Mock data for fileData
|
|
|
const mockFileData: PathAndFileData = {
|
|
const mockFileData: PathAndFileData = {
|
|
|
path: '/path/to/file.txt',
|
|
path: '/path/to/file.txt',
|
|
@@ -40,7 +62,8 @@ const mockFileData: PathAndFileData = {
|
|
|
end_index: 1,
|
|
end_index: 1,
|
|
|
total_count: 1
|
|
total_count: 1
|
|
|
},
|
|
},
|
|
|
- pagesize: 100
|
|
|
|
|
|
|
+ pagesize: 100,
|
|
|
|
|
+ show_download_button: true
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
describe('StorageFilePage', () => {
|
|
describe('StorageFilePage', () => {
|
|
@@ -128,4 +151,44 @@ describe('StorageFilePage', () => {
|
|
|
expect(screen.queryByRole('button', { name: 'Cancel' })).toBeNull();
|
|
expect(screen.queryByRole('button', { name: 'Cancel' })).toBeNull();
|
|
|
expect(screen.getByRole('button', { name: 'Edit' })).toBeVisible();
|
|
expect(screen.getByRole('button', { name: 'Edit' })).toBeVisible();
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ it('downloads file when download button is clicked', async () => {
|
|
|
|
|
+ const user = userEvent.setup();
|
|
|
|
|
+ render(<StorageFilePage fileData={mockFileData} />);
|
|
|
|
|
+
|
|
|
|
|
+ await user.click(screen.getByRole('button', { name: 'Download' }));
|
|
|
|
|
+
|
|
|
|
|
+ expect(huePubSub.publish).toHaveBeenCalledWith('hue.global.info', {
|
|
|
|
|
+ message: 'Downloading your file, Please wait...'
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const downloadLink = screen.getByRole('link', { name: 'Download' });
|
|
|
|
|
+ expect(downloadLink).toHaveAttribute('href', `${DOWNLOAD_API_URL}${mockFileData.path}`);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('downloads file when download button is clicked', async () => {
|
|
|
|
|
+ const user = userEvent.setup();
|
|
|
|
|
+ render(<StorageFilePage fileData={mockFileData} />);
|
|
|
|
|
+
|
|
|
|
|
+ await user.click(screen.getByRole('button', { name: 'Download' }));
|
|
|
|
|
+
|
|
|
|
|
+ expect(huePubSub.publish).toHaveBeenCalledWith('hue.global.info', {
|
|
|
|
|
+ message: 'Downloading your file, Please wait...'
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const downloadLink = screen.getByRole('link', { name: 'Download' });
|
|
|
|
|
+ expect(downloadLink).toHaveAttribute('href', `${DOWNLOAD_API_URL}${mockFileData.path}`);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('does not render the download button when show_download_button is false', () => {
|
|
|
|
|
+ const mockFileDataWithoutDownload = {
|
|
|
|
|
+ ...mockFileData,
|
|
|
|
|
+ show_download_button: false
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ render(<StorageFilePage fileData={mockFileDataWithoutDownload} />);
|
|
|
|
|
+
|
|
|
|
|
+ expect(screen.queryByRole('button', { name: 'Download' })).toBeNull();
|
|
|
|
|
+ expect(screen.queryByRole('link', { name: 'Download' })).toBeNull();
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|