-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publisher dataset count by name (#140)
* Publisher dataset count by name tests. * Adding Docx for Publisher Dataset Count (by name) component. * Tests for counting datasets within and Organization. * Update an Organization so that it will accept a component with a dataset count, and query and endpoint for count data. * Adding organizationEndpoint as a property for organizations.
- Loading branch information
1 parent
1e25373
commit 7af50b2
Showing
6 changed files
with
163 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import Organization from './index'; | ||
import Organization, {countDatasetsByName} from './index'; | ||
import PublisherDatasetCountByName from '../PublisherDatasetCountByName'; | ||
|
||
const data = | ||
[{"publisher": { | ||
"@type": "org:Organization", | ||
"name": "State Economic Council" | ||
}}, | ||
{"publisher": { | ||
"@type": "org:Organization", | ||
"name": "State Economic Council" | ||
}}]; | ||
|
||
|
||
describe('<Organization />', () => { | ||
test('renders a heading', () => { | ||
render(<Organization name="DKAN" />); | ||
expect(screen.getByRole('heading', 'DKAN')).toBeInTheDocument(); | ||
}); | ||
|
||
test('Has a publisher name.', () => { | ||
expect(data[0]['publisher']['name']).toEqual("State Economic Council"); | ||
}); | ||
|
||
test('renders with a dataset link with no count', () => { | ||
render(<Organization name="DKAN" />); | ||
expect(screen.getByText('datasets')).toBeInTheDocument(); | ||
}); | ||
|
||
test('Calculates a count from data',() => { | ||
expect(countDatasetsByName("State Economic Council", data)).toEqual(2); | ||
}); | ||
|
||
}); |
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,38 @@ | ||
--- | ||
name: Publisher Dataset Count (by name). | ||
menu: Components | ||
route: /components/publisher-dataset-count-by-name | ||
--- | ||
|
||
import { Playground, Props } from 'docz' | ||
import PublisherDatasetCountByName from './index' | ||
|
||
# Publisher dataset count (by name). | ||
|
||
## Properties | ||
|
||
<Props of={PublisherDatasetCountByName} /> | ||
|
||
### With no datasetCount. | ||
<Playground> | ||
<PublisherDatasetCountByName | ||
name="State Economic Council" | ||
/> | ||
</Playground> | ||
|
||
## Basic usage | ||
### With a count of 1. | ||
<Playground> | ||
<PublisherDatasetCountByName | ||
datasetCount="1" | ||
name="State Economic Council" | ||
/> | ||
</Playground> | ||
|
||
With a count of more than 1. | ||
<Playground> | ||
<PublisherDatasetCountByName | ||
datasetCount="3" | ||
name="State Economic Council" | ||
/> | ||
</Playground> |
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 React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link } from "@reach/router"; | ||
|
||
const PublisherDatasetCountByName = (props) => { | ||
const { name, searchUrl, datasetCount} = props; | ||
const link = searchUrl ? searchUrl : `search/?publisher__name=${name}`; | ||
let str; | ||
if (datasetCount) { | ||
str = (datasetCount === 1) ? '1 dataset' : `${datasetCount}x datasets`; | ||
} else { | ||
str = 'datasets'; | ||
} | ||
return ( | ||
<Link to={link} className="publisher-datasets-link" alt="Publisher datasets"> | ||
{str} | ||
</Link> | ||
); | ||
}; | ||
|
||
export default PublisherDatasetCountByName; | ||
|
||
PublisherDatasetCountByName.propTypes = { | ||
name: PropTypes.string, | ||
searchUrl: PropTypes.string, | ||
datasetCount: PropTypes.string | ||
}; |
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,22 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import PublisherDatasetCountByName from './index'; | ||
|
||
describe('<PublisherDatasetCountByName />', () => { | ||
|
||
test('If no dataset renders, just a link to the page.', () => { | ||
render(<PublisherDatasetCountByName name="Non matching organization." />); | ||
expect(screen.getByText('datasets')).toBeInTheDocument(); | ||
}); | ||
|
||
test('If there is a publisher with datasets render the dataset count.',() => { | ||
render(<PublisherDatasetCountByName name="State Economic Council" datasetCount="3" />); | ||
expect(screen.getByText('3x datasets')).toBeInTheDocument(); | ||
}); | ||
|
||
test('Dataset count with just one item.',() => { | ||
render(<PublisherDatasetCountByName name="State Economic Council" datasetCount="1" />); | ||
}); | ||
|
||
}); |
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