forked from openedx/frontend-app-authoring
-
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.
- Loading branch information
Showing
9 changed files
with
240 additions
and
61 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 |
---|---|---|
@@ -1,71 +1,25 @@ | ||
import { useQuery, useMutation } from '@tanstack/react-query'; | ||
import { useTaxonomyListData, useExportTaxonomy } from './api'; | ||
import { downloadDataAsFile } from '../../../utils'; | ||
|
||
const mockHttpClient = { | ||
get: jest.fn(), | ||
}; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import useTaxonomyListData from './api'; | ||
Check failure on line 2 in src/taxonomy/api/hooks/api.test.js GitHub Actions / tests
|
||
|
||
jest.mock('@tanstack/react-query', () => ({ | ||
useQuery: jest.fn(), | ||
useMutation: jest.fn(), | ||
})); | ||
|
||
jest.mock('@edx/frontend-platform/auth', () => ({ | ||
getAuthenticatedHttpClient: jest.fn(() => mockHttpClient), | ||
})); | ||
|
||
jest.mock('../../../utils', () => ({ | ||
downloadDataAsFile: jest.fn(), | ||
getAuthenticatedHttpClient: jest.fn(), | ||
})); | ||
|
||
describe('taxonomy API', () => { | ||
describe('taxonomy API: useTaxonomyListData', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('useTaxonomyListData should call useQuery with the correct parameters', () => { | ||
it('should call useQuery with the correct parameters', () => { | ||
useTaxonomyListData(); | ||
|
||
expect(useQuery).toHaveBeenCalledWith({ | ||
queryKey: ['taxonomyList'], | ||
queryFn: expect.any(Function), | ||
}); | ||
}); | ||
|
||
it('useExportTaxonomy should export data correctly', async () => { | ||
useMutation.mockImplementation((exportFunc) => exportFunc); | ||
|
||
const mockResponseJson = { | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
data: { tags: 'tags' }, | ||
}; | ||
const mockResponseCsv = { | ||
headers: { | ||
'content-type': 'text', | ||
}, | ||
data: 'This is a CSV', | ||
}; | ||
|
||
const exportTaxonomy = useExportTaxonomy(); | ||
|
||
mockHttpClient.get.mockResolvedValue(mockResponseJson); | ||
await exportTaxonomy({ pk: 1, format: 'json', name: 'testFile' }); | ||
|
||
expect(downloadDataAsFile).toHaveBeenCalledWith( | ||
JSON.stringify(mockResponseJson.data, null, 2), | ||
'application/json', | ||
'testFile.json', | ||
); | ||
|
||
mockHttpClient.get.mockResolvedValue(mockResponseCsv); | ||
await exportTaxonomy({ pk: 1, format: 'csv', name: 'testFile' }); | ||
expect(downloadDataAsFile).toHaveBeenCalledWith( | ||
mockResponseCsv.data, | ||
'text', | ||
'testFile.csv', | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as TaxonomyListPage } from './TaxonomyListPage'; | ||
export { TaxonomyDetailPage } from './taxonomy-detail'; |
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,42 @@ | ||
import { | ||
DataTable, | ||
TextFilter, | ||
} from '@edx/paragon'; | ||
import Proptypes from 'prop-types'; | ||
|
||
const tagsSample = [ | ||
{ name: 'Tag 1' }, | ||
{ name: 'Tag 2' }, | ||
{ name: 'Tag 3' }, | ||
{ name: 'Tag 4' }, | ||
{ name: 'Tag 5' }, | ||
{ name: 'Tag 6' }, | ||
{ name: 'Tag 7' }, | ||
]; | ||
|
||
const TagListTable = ({ tags }) => ( | ||
Check failure on line 17 in src/taxonomy/taxonomy-detail/TagListTable.jsx GitHub Actions / tests
|
||
<DataTable | ||
isFilterable | ||
isSortable | ||
defaultColumnValues={{ Filter: TextFilter }} | ||
itemCount={tagsSample.length} | ||
data={tagsSample} | ||
columns={[ | ||
{ | ||
Header: 'Name', | ||
accessor: 'name', | ||
}, | ||
]} | ||
> | ||
<DataTable.TableControlBar /> | ||
<DataTable.Table /> | ||
<DataTable.EmptyTable content="No results found" /> | ||
<DataTable.TableFooter /> | ||
</DataTable> | ||
); | ||
|
||
TagListTable.propTypes = { | ||
tags: Proptypes.array.isRequired, | ||
Check failure on line 39 in src/taxonomy/taxonomy-detail/TagListTable.jsx GitHub Actions / tests
|
||
}; | ||
|
||
export default TagListTable; |
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,97 @@ | ||
import React from 'react'; | ||
import { | ||
Container, | ||
Layout, | ||
} from '@edx/paragon'; | ||
import Proptypes from 'prop-types'; | ||
|
||
import PermissionDeniedAlert from '../../generic/PermissionDeniedAlert'; | ||
import Loading from '../../generic/Loading'; | ||
import Header from '../../header'; | ||
import SubHeader from '../../generic/sub-header/SubHeader'; | ||
import TaxonomyDetailSideCard from './TaxonomyDetailSideCard'; | ||
import TagListTable from './TagListTable'; | ||
import { useTaxonomyDetailDataResponse, useTaxonomyDetailDataStatus } from '../api/hooks/selectors'; | ||
|
||
const TaxonomyDetailContent = ({ taxonomyId }) => { | ||
const useTaxonomyDetailData = () => { | ||
const { isError, isFetched } = useTaxonomyDetailDataStatus(taxonomyId); | ||
const taxonomy = useTaxonomyDetailDataResponse(taxonomyId); | ||
return { isError, isFetched, taxonomy }; | ||
}; | ||
|
||
const { isError, isFetched, taxonomy } = useTaxonomyDetailData(taxonomyId); | ||
|
||
if (isError) { | ||
return ( | ||
<PermissionDeniedAlert /> | ||
); | ||
} | ||
|
||
if (!isFetched) { | ||
return ( | ||
<Loading /> | ||
); | ||
} | ||
|
||
if (taxonomy) { | ||
return ( | ||
<> | ||
<div className="pt-4.5 pr-4.5 pl-4.5 pb-2 bg-light-100 box-shadow-down-2"> | ||
<Container size="xl"> | ||
<SubHeader | ||
title={taxonomy.name} | ||
hideBorder | ||
/> | ||
</Container> | ||
</div> | ||
<div className="bg-light-400 m-4"> | ||
<Layout | ||
lg={[{ span: 9 }, { span: 3 }]} | ||
md={[{ span: 9 }, { span: 3 }]} | ||
sm={[{ span: 9 }, { span: 3 }]} | ||
xs={[{ span: 9 }, { span: 3 }]} | ||
xl={[{ span: 9 }, { span: 3 }]} | ||
> | ||
<Layout.Element> | ||
<TagListTable /> | ||
</Layout.Element> | ||
<Layout.Element> | ||
<TaxonomyDetailSideCard taxonomy={taxonomy} /> | ||
</Layout.Element> | ||
|
||
</Layout> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
return undefined; | ||
}; | ||
|
||
const TaxonomyDetailPage = ({ taxonomyId }) => ( | ||
<> | ||
<style> | ||
{` | ||
body { | ||
background-color: #E9E6E4; /* light-400 */ | ||
} | ||
`} | ||
</style> | ||
<Header isHiddenMainMenu /> | ||
<TaxonomyDetailContent taxonomyId={taxonomyId} /> | ||
</> | ||
); | ||
|
||
TaxonomyDetailPage.propTypes = { | ||
taxonomyId: Proptypes.number, | ||
}; | ||
|
||
TaxonomyDetailPage.defaultProps = { | ||
taxonomyId: undefined, | ||
}; | ||
|
||
TaxonomyDetailContent.propTypes = TaxonomyDetailPage.propTypes; | ||
TaxonomyDetailContent.defaultProps = TaxonomyDetailPage.defaultProps; | ||
|
||
export default TaxonomyDetailPage; |
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,27 @@ | ||
import { | ||
Card, | ||
} from '@edx/paragon'; | ||
import Proptypes from 'prop-types'; | ||
|
||
const TaxonomyDetailSideCard = ({ taxonomy }) => ( | ||
<Card> | ||
<Card.Header title="Taxonomy details" /> | ||
<Card.Section title="Title"> | ||
{taxonomy.name} | ||
</Card.Section> | ||
<Card.Divider className="ml-3 mr-3" /> | ||
<Card.Section title="Description"> | ||
{taxonomy.description} | ||
</Card.Section> | ||
<Card.Divider className="ml-3 mr-3" /> | ||
<Card.Section title="Copyright"> | ||
No copyright added | ||
</Card.Section> | ||
</Card> | ||
); | ||
|
||
TaxonomyDetailSideCard.propTypes = { | ||
taxonomy: Proptypes.object.isRequired, | ||
Check failure on line 24 in src/taxonomy/taxonomy-detail/TaxonomyDetailSideCard.jsx GitHub Actions / tests
|
||
}; | ||
|
||
export default TaxonomyDetailSideCard; |
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,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as TaxonomyDetailPage } from './TaxonomyDetailPage'; |