-
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.
Multiples of the same file type (#138)
* Add a test for a unique format helper function. * Add unique format function to code and reference from test. * Adding count display to file formats.
- Loading branch information
1 parent
e764f65
commit d02c5d7
Showing
2 changed files
with
116 additions
and
32 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,18 +1,99 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import SearchListItem from './index'; | ||
import SearchListItem, {getUniqueFormats} from './index'; | ||
|
||
describe('<SearchListItem />', () => { | ||
|
||
test('renders an item', () => { | ||
|
||
render(<SearchListItem | ||
item={ | ||
{ | ||
title: 'dkan', | ||
ref: '/dkan-item', | ||
} | ||
} | ||
/>); | ||
item={ | ||
{ | ||
title: 'dkan', | ||
ref: '/dkan-item', | ||
} | ||
} | ||
/>); | ||
expect(screen.getByRole('heading', 'Welcome to DKAN')).toBeInTheDocument(); | ||
}); | ||
|
||
test('Return uniquely formatted items', () => { | ||
|
||
const formats = [ | ||
[0, | ||
{ | ||
"identifier": 1, | ||
"format": "csv" | ||
}], | ||
[1, | ||
{ "identifier":2, | ||
"format": "csv" | ||
}], | ||
[2, | ||
{ "identifier":3, | ||
"format": "csv" | ||
}], | ||
[3, | ||
{ "identifier":4, | ||
"format": "rdf" | ||
}], | ||
[4, | ||
{ "identifier":5, | ||
"format": "xml" | ||
}] | ||
]; | ||
|
||
expect( | ||
getUniqueFormats(formats)) | ||
.toEqual([ | ||
{"format": "csv", | ||
"identifier": 1 | ||
}, | ||
{"format": "rdf", | ||
"identifier": 4 | ||
}, | ||
{"format": "xml", | ||
"identifier": 5 | ||
} | ||
]); | ||
}); | ||
|
||
test('Return formats with count.',() => { | ||
render( | ||
<SearchListItem | ||
item={ | ||
{ | ||
title: 'dkan', | ||
ref: '/dkan-item', | ||
format: [ | ||
{"format": "csv", | ||
"identifier": 1 | ||
}, | ||
{"format": "csv", | ||
"identifier": 2 | ||
}, | ||
{"format": "csv", | ||
"identifier": 3 | ||
}, | ||
{"format": "rdf", | ||
"identifier": 4 | ||
}, | ||
{"format": "xml", | ||
"identifier": 5 | ||
} | ||
], | ||
theme: ['category'], | ||
identifier: '123', | ||
ref: '/', | ||
description: 'This is the description.', | ||
publisher: 'Data Provider Name', | ||
} | ||
} | ||
/>); | ||
|
||
expect(screen.getByText('1x rdf')).toBeInTheDocument(); | ||
expect(screen.getByText('1x xml')).toBeInTheDocument(); | ||
expect(screen.getByText('3x csv')).toBeInTheDocument(); | ||
}); | ||
}); |