IntegrationOverviewTab.test.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { screen } from '@testing-library/dom'
  2. import { mockAnimationsApi } from 'jsdom-testing-mocks'
  3. import { beforeEach, describe, expect, it, vi } from 'vitest'
  4. import { IntegrationOverviewTab } from './IntegrationOverviewTab'
  5. import { customRender } from '@/tests/lib/custom-render'
  6. import { routerMock } from '@/tests/lib/route-mock'
  7. mockAnimationsApi()
  8. vi.mock('../Landing/Integrations.constants', () => ({
  9. INTEGRATIONS: [
  10. {
  11. id: 'test-integration',
  12. name: 'Test Integration',
  13. requiredExtensions: ['pg_net'],
  14. },
  15. ],
  16. }))
  17. vi.mock('framer-motion', async (importOriginal) => {
  18. const actual = (await importOriginal()) as any
  19. return {
  20. ...actual,
  21. motion: {
  22. ...actual.motion,
  23. div: ({ children, ...props }: any) => <div {...props}>{children}</div>,
  24. },
  25. }
  26. })
  27. const mockExtensions = vi.fn()
  28. vi.mock('@/data/database-extensions/database-extensions-query', () => ({
  29. useDatabaseExtensionsQuery: () => ({ data: mockExtensions() }),
  30. }))
  31. vi.mock('@/hooks/misc/useSelectedProject', () => ({
  32. useSelectedProjectQuery: () => ({
  33. data: { ref: 'default', connectionString: 'postgres://localhost' },
  34. }),
  35. useIsOrioleDb: () => false,
  36. }))
  37. vi.mock('common', async (importOriginal) => {
  38. const actual = (await importOriginal()) as any
  39. return {
  40. ...actual,
  41. useParams: () => ({ id: 'test-integration', ref: 'default' }),
  42. }
  43. })
  44. vi.mock('./MarkdownContent', () => ({
  45. MarkdownContent: () => null,
  46. }))
  47. describe('IntegrationOverviewTab', () => {
  48. beforeEach(() => {
  49. routerMock.setCurrentUrl('/project/default/integrations/test-integration/overview')
  50. mockExtensions.mockReturnValue([
  51. { name: 'pg_net', installed_version: null, default_version: '0.6.0' },
  52. ])
  53. })
  54. it('does not disable actions when hideRequiredExtensionsSection is true and extensions are uninstalled', () => {
  55. customRender(
  56. <IntegrationOverviewTab
  57. hideRequiredExtensionsSection
  58. actions={<button>Enable webhooks</button>}
  59. />
  60. )
  61. const actionsArea = screen.getByText('Enable webhooks').closest('[aria-disabled]')
  62. expect(actionsArea).toHaveAttribute('aria-disabled', 'false')
  63. expect(actionsArea).not.toHaveClass('opacity-25')
  64. })
  65. it('disables actions when extensions are uninstalled and hideRequiredExtensionsSection is false', () => {
  66. customRender(<IntegrationOverviewTab actions={<button>Enable integration</button>} />)
  67. const actionsArea = screen.getByText('Enable integration').closest('[aria-disabled]')
  68. expect(actionsArea).toHaveAttribute('aria-disabled', 'true')
  69. expect(actionsArea).toHaveClass('opacity-25')
  70. })
  71. })