-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display a popover when hovering over highlighted mentions
- Loading branch information
Showing
7 changed files
with
343 additions
and
30 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
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,35 @@ | ||
import type { Mention } from '../../../types/api'; | ||
import type { InvalidUsername } from '../../helpers/mentions'; | ||
|
||
export type MentionPopoverContent = { | ||
content: Mention | InvalidUsername; | ||
}; | ||
|
||
/** | ||
* Information to display in a Popover when hovering over a processed mention. | ||
*/ | ||
export default function MentionPopoverContent({ | ||
content, | ||
}: MentionPopoverContent) { | ||
if (typeof content === 'string') { | ||
return ( | ||
<> | ||
No user with username <span className="font-bold">{content}</span>{' '} | ||
exists | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col gap-y-1.5"> | ||
<div data-testid="username" className="text-md font-bold"> | ||
@{content.username} | ||
</div> | ||
{content.display_name && ( | ||
<div data-testid="display-name" className="text-color-text-light"> | ||
{content.display_name} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/sidebar/components/mentions/test/MentionPopoverContent-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,37 @@ | ||
import { mount } from '@hypothesis/frontend-testing'; | ||
|
||
import MentionPopoverContent from '../MentionPopoverContent'; | ||
|
||
describe('MentionPopoverContent', () => { | ||
function createComponent(content) { | ||
return mount(<MentionPopoverContent content={content} />); | ||
} | ||
|
||
it('renders user-not-found message when InvalidUser is provided', () => { | ||
const wrapper = createComponent('@invalid'); | ||
|
||
assert.equal('No user with username @invalid exists', wrapper.text()); | ||
assert.isFalse(wrapper.exists('[data-testid="username"]')); | ||
assert.isFalse(wrapper.exists('[data-testid="display-name"]')); | ||
}); | ||
|
||
it('renders username when valid mention without display name is provided', () => { | ||
const wrapper = createComponent({ username: 'janedoe' }); | ||
|
||
assert.equal(wrapper.find('[data-testid="username"]').text(), '@janedoe'); | ||
assert.isFalse(wrapper.exists('[data-testid="display-name"]')); | ||
}); | ||
|
||
it('renders username and display name when valid mention with display name is provided', () => { | ||
const wrapper = createComponent({ | ||
username: 'janedoe', | ||
display_name: 'Jane Doe', | ||
}); | ||
|
||
assert.equal(wrapper.find('[data-testid="username"]').text(), '@janedoe'); | ||
assert.equal( | ||
wrapper.find('[data-testid="display-name"]').text(), | ||
'Jane Doe', | ||
); | ||
}); | ||
}); |
Oops, something went wrong.