dataDownload.spec.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {textWithMarkupMatcher} from 'sentry-test/utils';
  5. import {ExportQueryType} from 'sentry/components/dataExport';
  6. import DataDownload, {DownloadStatus} from 'sentry/views/dataExport/dataDownload';
  7. describe('DataDownload', function () {
  8. beforeEach(MockApiClient.clearMockResponses);
  9. const dateExpired = new Date();
  10. const organization = OrganizationFixture();
  11. const mockRouteParams = {
  12. orgId: organization.slug,
  13. dataExportId: '721',
  14. };
  15. const getDataExportDetails = (body, statusCode = 200) =>
  16. MockApiClient.addMockResponse({
  17. url: `/organizations/${mockRouteParams.orgId}/data-export/${mockRouteParams.dataExportId}/`,
  18. body,
  19. statusCode,
  20. });
  21. it('should send a request to the data export endpoint', function () {
  22. const getValid = getDataExportDetails(DownloadStatus.VALID);
  23. render(<DataDownload {...RouteComponentPropsFixture()} params={mockRouteParams} />);
  24. expect(getValid).toHaveBeenCalledTimes(1);
  25. });
  26. it("should render the 'Error' view when appropriate", function () {
  27. const errors = {
  28. download: {
  29. status: 403,
  30. statusText: 'Forbidden',
  31. responseJSON: {
  32. detail: 'You are not allowed',
  33. },
  34. },
  35. };
  36. getDataExportDetails({errors}, 403);
  37. render(<DataDownload {...RouteComponentPropsFixture()} params={mockRouteParams} />);
  38. expect(screen.getByText('403 -')).toBeInTheDocument(); // Either the code or the mock is mistaken about the data return format
  39. });
  40. it("should render the 'Early' view when appropriate", function () {
  41. const status = DownloadStatus.EARLY;
  42. getDataExportDetails({status});
  43. render(<DataDownload {...RouteComponentPropsFixture()} params={mockRouteParams} />);
  44. expect(
  45. screen.getByText(textWithMarkupMatcher('What are you doing here?'))
  46. ).toBeInTheDocument();
  47. expect(screen.getByText(/were you invited/)).toBeInTheDocument();
  48. });
  49. it("should render the 'Expired' view when appropriate", function () {
  50. const status = DownloadStatus.EXPIRED;
  51. const response = {status, query: {type: ExportQueryType.ISSUES_BY_TAG}};
  52. getDataExportDetails(response);
  53. render(<DataDownload {...RouteComponentPropsFixture()} params={mockRouteParams} />);
  54. expect(screen.getByText('This is awkward.')).toBeInTheDocument();
  55. expect(screen.getByRole('button', {name: 'Start a New Download'})).toHaveAttribute(
  56. 'href',
  57. `/organizations/${mockRouteParams.orgId}/issues/`
  58. );
  59. });
  60. it("should render the 'Valid' view when appropriate", function () {
  61. const status = DownloadStatus.VALID;
  62. getDataExportDetails({dateExpired, status});
  63. render(<DataDownload {...RouteComponentPropsFixture()} params={mockRouteParams} />);
  64. expect(screen.getByText('All done.')).toBeInTheDocument();
  65. expect(screen.getByRole('button', {name: 'Download CSV'})).toHaveAttribute(
  66. 'href',
  67. `/api/0/organizations/${mockRouteParams.orgId}/data-export/${mockRouteParams.dataExportId}/?download=true`
  68. );
  69. expect(
  70. screen.getByText(
  71. textWithMarkupMatcher("That link won't last forever — it expires:Oct 17, 2:41 AM")
  72. )
  73. ).toBeInTheDocument();
  74. });
  75. it('should render the Open in Discover button when needed', function () {
  76. const status = DownloadStatus.VALID;
  77. getDataExportDetails({
  78. dateExpired,
  79. status,
  80. query: {
  81. type: ExportQueryType.DISCOVER,
  82. info: {},
  83. },
  84. });
  85. render(<DataDownload {...RouteComponentPropsFixture()} params={mockRouteParams} />);
  86. expect(screen.getByRole('button', {name: 'Open in Discover'})).toBeInTheDocument();
  87. });
  88. it('should not render the Open in Discover button when not needed', function () {
  89. const status = DownloadStatus.VALID;
  90. getDataExportDetails({
  91. dateExpired,
  92. status,
  93. query: {
  94. type: ExportQueryType.ISSUES_BY_TAG,
  95. info: {},
  96. },
  97. });
  98. render(<DataDownload {...RouteComponentPropsFixture()} params={mockRouteParams} />);
  99. expect(
  100. screen.queryByRole('button', {name: 'Open in Discover'})
  101. ).not.toBeInTheDocument();
  102. });
  103. });