-
Notifications
You must be signed in to change notification settings - Fork 17
Mspyx 578 Add VC IDR Link to Toast Message #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
e3ffbe4
948e5c5
843cec0
aea6404
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -10,21 +10,29 @@ | |||
}; | ||||
|
||||
// The function for displaying toast messages | ||||
export function toastMessage({ status, message }: { | ||||
export function toastMessage({ status, message, linkURL }: { | ||||
status: Status; | ||||
message: string; | ||||
linkURL?: string; | ||||
}): void { | ||||
toast[status](message, { | ||||
toast[status]( | ||||
<div style={{display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between'}}> | ||||
<div> | ||||
{message} | ||||
</div> | ||||
{linkURL && <a style={{fontSize: '12px'}} href={linkURL} target="_blank">Open VC</a> } | ||||
Check warning on line 23 in packages/components/src/components/ToastMessage/ToastMessage.tsx
|
||||
</div>, | ||||
{ | ||||
position: 'top-right', | ||||
hideProgressBar: true, | ||||
closeOnClick: true, | ||||
// closeOnClick: true, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
pauseOnHover: true, | ||||
draggable: true, | ||||
autoClose: 3000, | ||||
autoClose: 4000, | ||||
}); | ||||
} | ||||
|
||||
// ToastMessage component for displaying a ToastContainer | ||||
export const ToastMessage = () => { | ||||
return <ToastContainer />; | ||||
}; | ||||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add e2e tests? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,78 @@ | ||
import React from 'react'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import { render, waitFor, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { ToastMessage, toastMessage, Status } from '../../../components/ToastMessage/ToastMessage'; | ||
|
||
describe('Toast Message', () => { | ||
test('renders ToastMessage component and triggers toast', async () => { | ||
const status = Status.success; | ||
const message = 'Test message'; | ||
const linkURL = ''; | ||
|
||
// Render the component | ||
render(<ToastMessage />); | ||
|
||
// Call the toastMessage function | ||
toastMessage({ status, message }); | ||
toastMessage({ status, message, linkURL }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add unit tests to verify the functionality (i.e., does the link appear when a URL is provided, and does it not appear when no URL is provided)? |
||
|
||
// Check that the toast message is correctly. | ||
await waitFor(() => { | ||
expect(document.body).toHaveTextContent(message); | ||
}); | ||
}); | ||
|
||
test('renders ToastMessage with a link when linkURL is provided', async () => { | ||
const status = Status.info; | ||
const message = 'Linked toast'; | ||
const linkURL = 'https://example.com/vc/456'; | ||
|
||
render(<ToastMessage />); | ||
|
||
toastMessage({ status, message, linkURL }); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText(message)).toBeInTheDocument(); | ||
}); | ||
|
||
const link = screen.getByText('Open VC'); | ||
expect(link).toBeInTheDocument(); | ||
expect(link).toHaveAttribute('href', linkURL); | ||
expect(link).toHaveAttribute('target', '_blank'); | ||
}); | ||
|
||
test('does not render link when linkURL is not provided', async () => { | ||
const status = Status.info; | ||
const message = 'No link toast'; | ||
|
||
render(<ToastMessage />); | ||
toastMessage({ status, message }); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText(message)).toBeInTheDocument(); | ||
}); | ||
|
||
// Ensure "Open VC" link is not present | ||
expect(screen.queryByText('Open VC')).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('toast disappears after autoClose duration', async () => { | ||
jest.useFakeTimers(); | ||
const message = 'Temporary toast'; | ||
|
||
render(<ToastMessage />); | ||
toastMessage({ status: Status.warning, message }); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText(message)).toBeInTheDocument(); | ||
}); | ||
|
||
jest.advanceTimersByTime(4000); | ||
|
||
await waitFor(() => { | ||
expect(screen.queryByText(message)).not.toBeInTheDocument(); | ||
}); | ||
|
||
jest.useRealTimers(); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.