index.spec.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React from 'react';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {
  4. render,
  5. screen,
  6. userEvent,
  7. waitForElementToBeRemoved,
  8. } from 'sentry-test/reactTestingLibrary';
  9. import {FeatureFeedback} from 'sentry/components/featureFeedback';
  10. import GlobalModal from 'sentry/components/globalModal';
  11. import {RouteContext} from 'sentry/views/routeContext';
  12. function ComponentProviders({children}: {children: React.ReactNode}) {
  13. const {router} = initializeOrg();
  14. return (
  15. <RouteContext.Provider
  16. value={{
  17. router,
  18. location: router.location,
  19. params: {},
  20. routes: [],
  21. }}
  22. >
  23. {children}
  24. <GlobalModal />
  25. </RouteContext.Provider>
  26. );
  27. }
  28. describe('FeatureFeedback', function () {
  29. it('shows the modal on click', async function () {
  30. render(
  31. <ComponentProviders>
  32. <FeatureFeedback featureName="test" />
  33. </ComponentProviders>
  34. );
  35. userEvent.click(screen.getByText('Give Feedback'));
  36. expect(await screen.findByText('Select type of feedback')).toBeInTheDocument();
  37. expect(screen.getByRole('button', {name: 'Submit Feedback'})).toBeInTheDocument();
  38. });
  39. it('shows the modal on click with custom "onClick" handler', async function () {
  40. const mockOnClick = jest.fn();
  41. render(
  42. <ComponentProviders>
  43. <FeatureFeedback
  44. featureName="test"
  45. buttonProps={{
  46. onClick: mockOnClick,
  47. }}
  48. />
  49. </ComponentProviders>
  50. );
  51. userEvent.click(screen.getByText('Give Feedback'));
  52. expect(await screen.findByText('Select type of feedback')).toBeInTheDocument();
  53. expect(mockOnClick).toHaveBeenCalled();
  54. });
  55. it('Close modal on click', async function () {
  56. render(
  57. <ComponentProviders>
  58. <FeatureFeedback featureName="test" />
  59. </ComponentProviders>
  60. );
  61. userEvent.click(screen.getByText('Give Feedback'));
  62. userEvent.click(await screen.findByRole('button', {name: 'Cancel'}));
  63. await waitForElementToBeRemoved(() =>
  64. screen.queryByRole('heading', {name: 'Submit Feedback'})
  65. );
  66. });
  67. });