-
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 branch 'main' into task/WP-32--onboarding-page-filter-incomplet…
…e-users
- Loading branch information
Showing
28 changed files
with
518 additions
and
286 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -21,12 +21,6 @@ const dummyState = { | |
}, | ||
data: { | ||
demographics: { | ||
ethnicity: 'Asian', | ||
gender: 'Male', | ||
bio: '', | ||
website: 'http://owais.io', | ||
orcid_id: 'test', | ||
professional_level: 'Staff (support, administration, etc)', | ||
username: 'ojamil', | ||
email: '[email protected]', | ||
firstName: 'Owais', | ||
|
@@ -77,8 +71,6 @@ describe('Profile Information Component', () => { | |
'Institution', | ||
'Country of Residence', | ||
'Country of Citizenship', | ||
'Ethnicity', | ||
'Gender', | ||
]; | ||
headings.forEach((heading) => { | ||
expect(getByText(heading)).toBeInTheDocument(); | ||
|
39 changes: 39 additions & 0 deletions
39
client/src/components/_common/HighlightSearchTerm/HighlightSearchTerm.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,39 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from './HighlightSearchTerm.module.scss'; | ||
|
||
const HighlightSearchTerm = ({ searchTerm, content }) => { | ||
if (!searchTerm) { | ||
return <>{content}</>; | ||
} | ||
|
||
const searchTermRegex = new RegExp(`(${searchTerm})`, 'gi'); | ||
|
||
const highlightParts = () => { | ||
const parts = content.split(searchTermRegex); | ||
return parts.map((part, i) => { | ||
const isSearchTerm = part.match(searchTermRegex); | ||
return isSearchTerm ? ( | ||
<b className={styles['highlight']} key={i}> | ||
{part} | ||
</b> | ||
) : ( | ||
part | ||
); | ||
}); | ||
}; | ||
|
||
return <>{highlightParts()}</>; | ||
}; | ||
|
||
HighlightSearchTerm.propTypes = { | ||
searchTerm: PropTypes.string, | ||
content: PropTypes.string, | ||
}; | ||
|
||
HighlightSearchTerm.defaultProps = { | ||
searchTerm: '', | ||
content: '', | ||
}; | ||
|
||
export default HighlightSearchTerm; |
3 changes: 3 additions & 0 deletions
3
client/src/components/_common/HighlightSearchTerm/HighlightSearchTerm.module.scss
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,3 @@ | ||
.highlight { | ||
font-weight: bold; | ||
} |
57 changes: 57 additions & 0 deletions
57
client/src/components/_common/HighlightSearchTerm/HighlightSearchTerm.test.js
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,57 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { | ||
toBeInTheDocument, | ||
toHaveClass, | ||
toBeNull, | ||
} from '@testing-library/jest-dom'; | ||
|
||
import HighlightSearchTerm from './HighlightSearchTerm'; | ||
|
||
describe('HighlightSearchTerm Component', () => { | ||
it('renders content when searchTerm is not provided', () => { | ||
const { getByText } = render(<HighlightSearchTerm content="Lorem ipsum" />); | ||
expect(getByText('Lorem ipsum')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders without highlighting when searchTerm in content do not match', () => { | ||
const { getByText } = render( | ||
<HighlightSearchTerm | ||
searchTerm="minim" | ||
content="Lorem ipsum dolor sit amet" | ||
/> | ||
); | ||
expect(getByText('Lorem ipsum dolor sit amet')).toBeInTheDocument(); | ||
expect(document.querySelector('.highlight')).toBeNull(); | ||
}); | ||
|
||
it('renders content when searchTerm is not provided', () => { | ||
const { getByText } = render(<HighlightSearchTerm content="Lorem ipsum" />); | ||
expect(getByText('Lorem ipsum')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders content with searchTerm highlighted', () => { | ||
const { getByText } = render( | ||
<HighlightSearchTerm | ||
searchTerm="ipsum" | ||
content="Lorem ipsum dolor sit amet" | ||
/> | ||
); | ||
const highlightedText = getByText('ipsum'); | ||
expect(highlightedText).toHaveClass('highlight'); | ||
}); | ||
|
||
it('renders content with multiple searchTerm occurrences highlighted', () => { | ||
const { getAllByText } = render( | ||
<HighlightSearchTerm | ||
searchTerm="ipsum" | ||
content="Lorem ipsum ipsum Loremipsum ipsumipsum dolor sit amet" | ||
/> | ||
); | ||
const highlightedText = getAllByText('ipsum'); | ||
expect(highlightedText.length).toBe(5); | ||
highlightedText.forEach((element) => { | ||
expect(element).toHaveClass('highlight'); | ||
}); | ||
}); | ||
}); |
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,3 @@ | ||
import HighlightSearchTerm from './HighlightSearchTerm'; | ||
|
||
export default HighlightSearchTerm; |
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
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.