releaseContext.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {render, screen, within} from 'sentry-test/reactTestingLibrary';
  2. import ConfigStore from 'sentry/stores/configStore';
  3. import {QueryClient, QueryClientProvider} from 'sentry/utils/queryClient';
  4. import ReleaseContext from './releaseContext';
  5. import {defaultRow, mockedCommit, mockedUser1, mockedUser2} from './testUtils';
  6. const queryClient = new QueryClient({
  7. defaultOptions: {
  8. queries: {
  9. retry: false,
  10. },
  11. },
  12. });
  13. export const mockedReleaseWithHealth = TestStubs.Release({
  14. id: '1',
  15. shortVersion: 'sentry-android-shop@1.2.0',
  16. version: 'sentry-android-shop@1.2.0',
  17. dateCreated: '2010-05-17T02:41:20Z',
  18. lastEvent: '2011-10-17T02:41:20Z',
  19. firstEvent: '2010-05-17T02:41:20Z',
  20. status: 'open',
  21. commitCount: 4,
  22. lastCommit: mockedCommit,
  23. newGroups: 21,
  24. authors: [mockedUser1, mockedUser2],
  25. });
  26. const renderReleaseContext = () => {
  27. const organization = TestStubs.Organization();
  28. render(
  29. <QueryClientProvider client={queryClient}>
  30. <ReleaseContext dataRow={defaultRow} organization={organization} />
  31. </QueryClientProvider>,
  32. {organization}
  33. );
  34. };
  35. describe('Quick Context Content Release Column', function () {
  36. beforeEach(() => {
  37. MockApiClient.addMockResponse({
  38. url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
  39. body: mockedReleaseWithHealth,
  40. });
  41. });
  42. afterEach(() => {
  43. queryClient.clear();
  44. MockApiClient.clearMockResponses();
  45. });
  46. it('Renders Release details for release', async () => {
  47. renderReleaseContext();
  48. expect(await screen.findByText(/Created/i)).toBeInTheDocument();
  49. expect(screen.getByText(/7 years ago/i)).toBeInTheDocument();
  50. expect(screen.getByText(/Last Event/i)).toBeInTheDocument();
  51. expect(screen.getByText(/6 years ago/i)).toBeInTheDocument();
  52. expect(screen.getByText(/New Issues/i)).toBeInTheDocument();
  53. expect(screen.getByText(/21/i)).toBeInTheDocument();
  54. });
  55. it('Renders Last Commit', async () => {
  56. renderReleaseContext();
  57. expect(await screen.findByText(/Last Commit/i)).toBeInTheDocument();
  58. expect(screen.getByTestId('quick-context-commit-row')).toBeInTheDocument();
  59. });
  60. it('Renders Commit Count and Author when user is NOT in list of authors', async () => {
  61. renderReleaseContext();
  62. const authorsSectionHeader = within(
  63. await screen.findByTestId('quick-context-release-author-header')
  64. );
  65. expect(authorsSectionHeader.getByText(/4/i)).toBeInTheDocument();
  66. expect(authorsSectionHeader.getByText(/commits by/i)).toBeInTheDocument();
  67. expect(authorsSectionHeader.getByText(/2/i)).toBeInTheDocument();
  68. expect(authorsSectionHeader.getByText(/authors/i)).toBeInTheDocument();
  69. expect(screen.getByText(/KN/i)).toBeInTheDocument();
  70. expect(screen.getByText(/VN/i)).toBeInTheDocument();
  71. });
  72. it('Renders Commit Count and Author when user is in list of authors', async () => {
  73. jest.spyOn(ConfigStore, 'get').mockImplementation(() => mockedUser1);
  74. renderReleaseContext();
  75. expect(await screen.findByText(/4/i)).toBeInTheDocument();
  76. expect(screen.getByText(/commits by you and 1 other/i)).toBeInTheDocument();
  77. expect(screen.getByText(/KN/i)).toBeInTheDocument();
  78. expect(screen.getByText(/VN/i)).toBeInTheDocument();
  79. });
  80. });