integration-widget.test.tsx 3.2 KB

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