notification.test.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { expect } from 'chai'
  2. import { screen, render } from '@testing-library/react'
  3. import Notification from '../../../../frontend/js/shared/components/notification'
  4. import * as eventTracking from '@/infrastructure/event-tracking'
  5. import sinon from 'sinon'
  6. describe('<Notification />', function () {
  7. let sendMBSpy: sinon.SinonSpy
  8. beforeEach(function () {
  9. sendMBSpy = sinon.spy(eventTracking, 'sendMB')
  10. })
  11. afterEach(function () {
  12. sendMBSpy.restore()
  13. })
  14. it('renders and is not dismissible by default', function () {
  15. render(<Notification type="info" content={<p>A notification</p>} />)
  16. screen.getByText('A notification')
  17. expect(screen.queryByRole('button', { name: 'Close' })).to.be.null
  18. })
  19. it('renders with action', function () {
  20. render(
  21. <Notification
  22. type="info"
  23. content={<p>A notification</p>}
  24. action={<a href="/">Action</a>}
  25. />
  26. )
  27. screen.getByText('A notification')
  28. screen.getByRole('link', { name: 'Action' })
  29. })
  30. it('renders with close button', function () {
  31. render(
  32. <Notification type="info" content={<p>A notification</p>} isDismissible />
  33. )
  34. screen.getByText('A notification')
  35. screen.getByRole('button', { name: 'Close' })
  36. })
  37. it('renders with title and content passed as HTML', function () {
  38. render(
  39. <Notification
  40. type="info"
  41. content={<p>A notification</p>}
  42. title="A title"
  43. />
  44. )
  45. screen.getByText('A title')
  46. screen.getByText('A notification')
  47. })
  48. it('renders with content when passed as a string', function () {
  49. render(
  50. <Notification type="info" content="A notification" title="A title" />
  51. )
  52. screen.getByText('A notification')
  53. })
  54. })