|
| 1 | +// Licensed to Cloudera, Inc. under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. Cloudera, Inc. licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | + |
| 17 | +import React from 'react'; |
| 18 | +import { render } from '@testing-library/react'; |
| 19 | +import '@testing-library/jest-dom'; |
| 20 | +import StorageDirectoryActions from './StorageDirectoryActions'; |
| 21 | + |
| 22 | +const mockOnActionSuccess = jest.fn(); |
| 23 | +const mockSetLoadingFiles = jest.fn(); |
| 24 | +const mockOnFilesDrop = jest.fn(); |
| 25 | +const mockOnFilePathChange = jest.fn(); |
| 26 | + |
| 27 | +describe('StorageDirectoryActions Component', () => { |
| 28 | + beforeEach(() => { |
| 29 | + jest.clearAllMocks(); |
| 30 | + }); |
| 31 | + |
| 32 | + const mockSelectedFiles = [ |
| 33 | + { |
| 34 | + name: 'file1.txt', |
| 35 | + size: '0 Byte', |
| 36 | + type: 'file', |
| 37 | + permission: 'rwxrwxrwx', |
| 38 | + mtime: '2021-01-01 00:00:00', |
| 39 | + path: '/user/path/.Trash/Current/file1.txt', |
| 40 | + user: 'test', |
| 41 | + group: 'test', |
| 42 | + replication: 1 |
| 43 | + } |
| 44 | + ]; |
| 45 | + |
| 46 | + const mockFileStats = { |
| 47 | + name: 'file1.txt', |
| 48 | + type: 'file', |
| 49 | + permission: 'rwxrwxrwx', |
| 50 | + mtime: 123, |
| 51 | + path: '/user/path/file1.txt', |
| 52 | + user: 'test', |
| 53 | + group: 'test', |
| 54 | + replication: 1, |
| 55 | + atime: 123, |
| 56 | + blockSize: 123, |
| 57 | + mode: 123, |
| 58 | + rwx: 'rwxrwxrwx', |
| 59 | + size: 123 |
| 60 | + }; |
| 61 | + |
| 62 | + const mockFileSystem = { |
| 63 | + file_system: 'hdfs', |
| 64 | + user_home_directory: '/user/hue' |
| 65 | + }; |
| 66 | + |
| 67 | + const mockTrashPath = '/user/path/.Trash/Current'; |
| 68 | + const mockIsTrashEmpty = !mockSelectedFiles.length; |
| 69 | + |
| 70 | + it('should render the Trash actions when path is in Trash', () => { |
| 71 | + const { getByRole, queryByRole } = render( |
| 72 | + <StorageDirectoryActions |
| 73 | + selectedFiles={mockSelectedFiles} |
| 74 | + isFolderEmpty={mockIsTrashEmpty} |
| 75 | + onActionSuccess={mockOnActionSuccess} |
| 76 | + setLoadingFiles={mockSetLoadingFiles} |
| 77 | + fileStats={{ ...mockFileStats, path: mockTrashPath }} |
| 78 | + fileSystem={mockFileSystem} |
| 79 | + onFilePathChange={mockOnFilePathChange} |
| 80 | + onFilesDrop={mockOnFilesDrop} |
| 81 | + /> |
| 82 | + ); |
| 83 | + |
| 84 | + expect(getByRole('button', { name: 'Restore' })).toBeInTheDocument(); |
| 85 | + expect(getByRole('button', { name: 'Empty trash' })).toBeInTheDocument(); |
| 86 | + expect(queryByRole('button', { name: 'Actions' })).not.toBeInTheDocument(); |
| 87 | + expect(queryByRole('button', { name: 'New' })).not.toBeInTheDocument(); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should render the regular actions when path is not in Trash', () => { |
| 91 | + const { getByRole, queryByRole } = render( |
| 92 | + <StorageDirectoryActions |
| 93 | + selectedFiles={mockSelectedFiles} |
| 94 | + isFolderEmpty={mockIsTrashEmpty} |
| 95 | + onActionSuccess={mockOnActionSuccess} |
| 96 | + setLoadingFiles={mockSetLoadingFiles} |
| 97 | + fileStats={mockFileStats} |
| 98 | + fileSystem={mockFileSystem} |
| 99 | + onFilePathChange={mockOnFilePathChange} |
| 100 | + onFilesDrop={mockOnFilesDrop} |
| 101 | + /> |
| 102 | + ); |
| 103 | + |
| 104 | + expect(getByRole('button', { name: 'Actions' })).toBeInTheDocument(); |
| 105 | + expect(getByRole('button', { name: 'New' })).toBeInTheDocument(); |
| 106 | + expect(queryByRole('button', { name: 'Restore' })).not.toBeInTheDocument(); |
| 107 | + expect(queryByRole('button', { name: 'Empty trash' })).not.toBeInTheDocument(); |
| 108 | + }); |
| 109 | +}); |
0 commit comments