forked from hms-dbmi-cellenics/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hms-dbmi-cellenics#898 from biomage-org/cell-level…
…-meta [Cell-level metadata] Update the Add metadata select
- Loading branch information
Showing
18 changed files
with
599 additions
and
90 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/__test__/components/data-management/CellLevelUploadModal.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { | ||
render, screen, | ||
} from '@testing-library/react'; | ||
import { act } from 'react-dom/test-utils'; | ||
import handleError from 'utils/http/handleError'; | ||
import readFileToString from 'utils/upload/readFileToString'; | ||
|
||
import componentFactory from '__test__/test-utils/testComponentFactory'; | ||
import CellLevelUploadModal from 'components/data-management/CellLevelUploadModal'; | ||
import { dropFilesIntoDropzone } from '__test__/test-utils/rtlHelpers'; | ||
|
||
jest.mock('utils/upload/readFileToString'); | ||
jest.mock('utils/http/handleError'); | ||
|
||
const defaultProps = { | ||
onUpload: jest.fn(), | ||
onCancel: jest.fn(), | ||
}; | ||
|
||
const CellLevelModalFactory = componentFactory(CellLevelUploadModal, defaultProps); | ||
|
||
const renderCellLevelUploadModal = async (customProps = {}) => { | ||
act(() => { | ||
render(CellLevelModalFactory(customProps)); | ||
}); | ||
}; | ||
|
||
describe('CellLevelUploadModal', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('shows required components required to upload the cell level file', async () => { | ||
await renderCellLevelUploadModal(); | ||
|
||
expect(screen.getByText(/File Upload/i)).toBeInTheDocument(); | ||
|
||
const uploadButtonText = screen.getAllByText(/Upload/i).pop(); | ||
const uploadButton = uploadButtonText.closest('button'); | ||
|
||
expect(uploadButton).toBeDisabled(); | ||
}); | ||
|
||
it('returns error for invalid file', async () => { | ||
readFileToString.mockReturnValue('bad-content'); | ||
await renderCellLevelUploadModal(); | ||
|
||
const inputEl = await screen.getByTestId('drop-input'); | ||
const file = new File(['content'], 'file.tsv', { type: 'text/plain' }); | ||
|
||
await dropFilesIntoDropzone(inputEl, [file]); | ||
const uploadButton = screen.getByRole('button', { | ||
name: /Upload/, | ||
}); | ||
|
||
expect(uploadButton).toBeDisabled(); | ||
expect(handleError).toHaveBeenCalled(); | ||
}); | ||
|
||
it('needs to have the barcodes column', async () => { | ||
const onUpload = jest.fn(); | ||
readFileToString.mockReturnValue('sample\tkey1\tval1'); | ||
await renderCellLevelUploadModal({ onUpload }); | ||
|
||
const inputEl = await screen.getByTestId('drop-input'); | ||
const file = new File(['content'], 'file.tsv', { type: 'text/plain' }); | ||
|
||
await dropFilesIntoDropzone(inputEl, [file]); | ||
|
||
expect(handleError).toBeCalledWith('error', 'The .tsv file needs to contain the column "barcodes"'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.