integration-widget.test.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { expect } from 'chai'
  2. import { screen, fireEvent, render, waitFor } from '@testing-library/react'
  3. import { IntegrationLinkingWidget } from '../../../../../../frontend/js/features/settings/components/linking/integration-widget'
  4. describe('<IntegrationLinkingWidgetTest/>', function () {
  5. const defaultProps = {
  6. logoSrc: '/logo',
  7. title: 'Integration',
  8. description: ['paragraph1', 'paragraph2'],
  9. linkPath: '/link',
  10. unlinkPath: '/unlink',
  11. unlinkConfirmationTitle: 'confirm unlink',
  12. unlinkConfirmationText: 'you will be unlinked',
  13. }
  14. describe('when the feature is not available', function () {
  15. beforeEach(function () {
  16. render(<IntegrationLinkingWidget {...defaultProps} hasFeature={false} />)
  17. })
  18. it("should render 'Premium feature' label", function () {
  19. screen.getByText('Premium feature')
  20. })
  21. it('should render a link to upgrade the account', function () {
  22. expect(
  23. screen.getByRole('link', { name: 'Upgrade' }).getAttribute('href')
  24. ).to.equal('/user/subscription/plans')
  25. })
  26. })
  27. describe('when the integration is not linked', function () {
  28. beforeEach(function () {
  29. render(
  30. <IntegrationLinkingWidget {...defaultProps} hasFeature linked={false} />
  31. )
  32. })
  33. it('should render a link to initiate integration linking', function () {
  34. expect(
  35. screen.getByRole('link', { name: 'Link' }).getAttribute('href')
  36. ).to.equal('/link')
  37. })
  38. it("should not render 'premium feature' labels", function () {
  39. expect(screen.queryByText('premium_feature')).to.not.exist
  40. expect(screen.queryByText('integration_is_a_premium_feature')).to.not
  41. .exist
  42. })
  43. })
  44. describe('when the integration is linked', function () {
  45. beforeEach(function () {
  46. render(
  47. <IntegrationLinkingWidget
  48. {...defaultProps}
  49. hasFeature
  50. linked
  51. statusIndicator={<div>status indicator</div>}
  52. />
  53. )
  54. })
  55. it('should render a status indicator', function () {
  56. screen.getByText('status indicator')
  57. })
  58. it("should not render 'premium feature' labels", function () {
  59. expect(screen.queryByText('premium_feature')).to.not.exist
  60. expect(screen.queryByText('integration_is_a_premium_feature')).to.not
  61. .exist
  62. })
  63. it('should display an `unlink` button', function () {
  64. screen.getByRole('button', { name: 'Unlink' })
  65. })
  66. it('should open a modal with a link to confirm integration unlinking', function () {
  67. fireEvent.click(screen.getByRole('button', { name: 'Unlink' }))
  68. screen.getByText('confirm unlink')
  69. screen.getByText('you will be unlinked')
  70. screen.getByRole('button', { name: 'Cancel' })
  71. screen.getByRole('button', { name: 'Unlink' })
  72. })
  73. it('should cancel unlinking when clicking "cancel" in the confirmation modal', async function () {
  74. fireEvent.click(screen.getByRole('button', { name: 'Unlink' }))
  75. screen.getByText('confirm unlink')
  76. const cancelBtn = screen.getByRole('button', {
  77. name: 'Cancel',
  78. hidden: false,
  79. })
  80. fireEvent.click(cancelBtn)
  81. await waitFor(() =>
  82. screen.getByRole('button', { name: 'Cancel', hidden: true })
  83. )
  84. })
  85. })
  86. })