-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CORE-132] Autogenerate dataTable from Data Uploader (#5174)
- Loading branch information
1 parent
251a323
commit bc4f4ac
Showing
5 changed files
with
210 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ export const FIRECLOUD_UI_MIGRATION = 'firecloudUiMigration'; | |
export const COHORT_BUILDER_CARD = 'cohortBuilderCard'; | ||
export const GCP_BUCKET_LIFECYCLE_RULES = 'gcpBucketLifecycleRules'; | ||
export const SPEND_REPORTING = 'spendReporting'; | ||
export const AUTO_GENERATE_DATA_TABLES = 'autoGenerateDataTables'; | ||
|
||
// If the groups option is defined for a FeaturePreview, it must contain at least one group. | ||
type GroupsList = readonly [string, ...string[]]; | ||
|
@@ -126,6 +127,16 @@ const featurePreviewsConfig: readonly FeaturePreview[] = [ | |
)}`, | ||
lastUpdated: '11/19/2024', | ||
}, | ||
{ | ||
id: AUTO_GENERATE_DATA_TABLES, | ||
title: 'Autogenerate data table for single and paired end sequencing', | ||
description: | ||
'Enabling this feature will show a new option in the data uploader to autogenerate a data table instead of uploading your own TSV. This feature will attempt to automatch known file patterns for single and paired end sequencing and autogenerate a data table linking to those files.', | ||
feedbackUrl: `mailto:[email protected]?subject=${encodeURIComponent( | ||
'Feedback on Autogenerate data table for single and paired end sequencing' | ||
)}`, | ||
lastUpdated: '11/26/2024', | ||
}, | ||
]; | ||
|
||
export default featurePreviewsConfig; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { expect } from '@storybook/test'; | ||
import { act, fireEvent, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { Workspaces, WorkspacesAjaxContract } from 'src/libs/ajax/workspaces/Workspaces'; | ||
import { useRoute } from 'src/libs/nav'; | ||
import { asMockedFn, partial, renderWithAppContexts } from 'src/testing/test-utils'; | ||
|
||
import { UploadData } from './UploadData'; | ||
|
||
// Mock dependencies | ||
jest.mock('src/libs/ajax/GoogleStorage', () => ({ | ||
GoogleStorage: jest.fn().mockReturnValue({ | ||
list: jest.fn().mockResolvedValue({ prefixes: [] }), | ||
listAll: jest.fn().mockResolvedValue({ items: [] }), | ||
}), | ||
})); | ||
|
||
jest.mock('src/libs/ajax/workspaces/Workspaces', () => ({ | ||
Workspaces: jest.fn().mockReturnValue({ | ||
workspace: jest.fn().mockReturnValue({ | ||
importFlexibleEntitiesFileSynchronous: jest.fn().mockResolvedValue({}), | ||
autoGenerateTsv: jest.fn().mockResolvedValue(new File([], 'autoGenerated.tsv')), | ||
}), | ||
}), | ||
})); | ||
|
||
asMockedFn(Workspaces).mockReturnValue( | ||
partial<WorkspacesAjaxContract>({ | ||
getTags: jest.fn().mockResolvedValue([]), | ||
}) | ||
); | ||
|
||
jest.mock('src/libs/ajax/Metrics', () => ({ | ||
Metrics: jest.fn().mockReturnValue({ | ||
captureEvent: jest.fn(), | ||
}), | ||
})); | ||
|
||
type NavExports = typeof import('src/libs/nav'); | ||
jest.mock( | ||
'src/libs/nav', | ||
(): NavExports => ({ | ||
...jest.requireActual<NavExports>('src/libs/nav'), | ||
getLink: jest.fn(() => '/'), | ||
goToPath: jest.fn(), | ||
useRoute: jest.fn().mockReturnValue({ query: {} }), | ||
updateSearch: jest.fn(), | ||
}) | ||
); | ||
|
||
jest.mock('src/libs/state-history', () => ({ | ||
get: jest.fn().mockReturnValue({}), | ||
update: jest.fn(), | ||
})); | ||
|
||
jest.mock('src/workspaces/common/state/useWorkspaces', () => ({ | ||
useWorkspaces: jest.fn().mockReturnValue({ | ||
workspaces: [ | ||
{ | ||
workspace: { | ||
workspaceId: 'mockWorkspaceId', | ||
namespace: 'mockNamespace', | ||
name: 'mockWorkspaceName', | ||
attributes: {}, | ||
createdBy: '[email protected]', | ||
lastModified: '2023-01-01T00:00:00Z', | ||
}, | ||
accessLevel: 'OWNER', | ||
}, | ||
], | ||
refresh: jest.fn(), | ||
loading: false, | ||
}), | ||
})); | ||
|
||
jest.mock('src/libs/feature-previews', () => ({ | ||
isFeaturePreviewEnabled: jest.fn(), | ||
})); | ||
|
||
describe('UploadData Component', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const selectOptionAndGoToNext = async (option: any) => { | ||
(useRoute as jest.Mock).mockReturnValue({ | ||
query: { ...option }, | ||
}); | ||
|
||
await act(async () => { | ||
renderWithAppContexts(<UploadData />); | ||
}); | ||
|
||
fireEvent.click(screen.getByText('Next >')); | ||
}; | ||
|
||
it('Renders data uploader', () => { | ||
renderWithAppContexts(<UploadData />); | ||
expect(screen.getByRole('main')).toBeInTheDocument(); | ||
expect(screen.getByText('Data Uploader')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Displays option to select a workspace', () => { | ||
renderWithAppContexts(<UploadData />); | ||
expect(screen.getByText('Select a Workspace')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Allows selection of a workspace and move to the next step', async () => { | ||
// Select workspace | ||
await selectOptionAndGoToNext({ workspace: 'mockWorkspaceId' }); | ||
await expect(screen.getByText('Select a collection')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Allows selection of a collection and move to the next step', async () => { | ||
// Select workspace & collection | ||
await selectOptionAndGoToNext({ workspace: 'mockWorkspaceId', collection: 'collection1' }); | ||
await expect(screen.getByText('Upload Your Data Files')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Can manually upload a metadata TSV file', async () => { | ||
// Select workspace & collection | ||
await selectOptionAndGoToNext({ workspace: 'mockWorkspaceId', collection: 'collection1' }); | ||
|
||
// Upload metadata file | ||
const file = new File(['entity:collection1_id\tname\n1\tTest'], 'metadata.tsv', { | ||
type: 'text/tab-separated-values', | ||
}); | ||
const input = screen.getByTestId('dropzone-upload') as HTMLInputElement; | ||
Object.defineProperty(input, 'files', { value: [file], writable: false }); | ||
|
||
await act(async () => { | ||
fireEvent.change(input); | ||
}); | ||
|
||
await expect(screen.getByRole('table')).toBeInTheDocument(); | ||
}); | ||
}); |