123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import {mountWithTheme} from 'sentry-test/enzyme';
- import {ExportQueryType} from 'sentry/components/dataExport';
- import DataDownload, {DownloadStatus} from 'sentry/views/dataExport/dataDownload';
- describe('DataDownload', function () {
- beforeEach(MockApiClient.clearMockResponses);
- const dateExpired = new Date();
- const organization = TestStubs.Organization();
- const mockRouteParams = {
- orgId: organization.slug,
- dataExportId: 721,
- };
- const getDataExportDetails = (body, statusCode = 200) =>
- MockApiClient.addMockResponse({
- url: `/organizations/${mockRouteParams.orgId}/data-export/${mockRouteParams.dataExportId}/`,
- body,
- statusCode,
- });
- it('should send a request to the data export endpoint', function () {
- const getValid = getDataExportDetails(DownloadStatus.Valid);
- mountWithTheme(<DataDownload params={mockRouteParams} />);
- expect(getValid).toHaveBeenCalled();
- });
- it("should render the 'Error' view when appropriate", function () {
- const errors = {
- download: {
- status: 403,
- statusText: 'Forbidden',
- responseJSON: {
- detail: 'You are not allowed',
- },
- },
- };
- getDataExportDetails({errors}, 403);
- const wrapper = mountWithTheme(<DataDownload params={mockRouteParams} />);
- expect(wrapper.state('errors')).toBeDefined();
- expect(wrapper.state('errors').download.status).toBe(403);
- });
- it("should render the 'Early' view when appropriate", function () {
- const status = DownloadStatus.Early;
- getDataExportDetails({status});
- const wrapper = mountWithTheme(<DataDownload params={mockRouteParams} />);
- expect(wrapper.state('download')).toEqual({status});
- expect(wrapper.state('download').dateExpired).toBeUndefined();
- expect(wrapper.find('Header').text()).toBe('What are you doing here?');
- });
- it("should render the 'Expired' view when appropriate", function () {
- const status = DownloadStatus.Expired;
- const response = {status, query: {type: ExportQueryType.IssuesByTag}};
- getDataExportDetails(response);
- const wrapper = mountWithTheme(<DataDownload params={mockRouteParams} />);
- expect(wrapper.state('download')).toEqual(response);
- expect(wrapper.state('download').dateExpired).toBeUndefined();
- expect(wrapper.find('Header').text()).toBe('This is awkward.');
- const buttonWrapper = wrapper.find('a[aria-label="Start a New Download"]');
- expect(buttonWrapper.prop('href')).toBe(
- `/organizations/${mockRouteParams.orgId}/issues/`
- );
- });
- it("should render the 'Valid' view when appropriate", function () {
- const status = DownloadStatus.Valid;
- getDataExportDetails({dateExpired, status});
- const wrapper = mountWithTheme(<DataDownload params={mockRouteParams} />);
- expect(wrapper.state('download')).toEqual({dateExpired, status});
- expect(wrapper.find('Header').text()).toBe('All done.');
- const buttonWrapper = wrapper.find('a[aria-label="Download CSV"]');
- expect(buttonWrapper.text()).toBe('Download CSV');
- expect(buttonWrapper.prop('href')).toBe(
- `/api/0/organizations/${mockRouteParams.orgId}/data-export/${mockRouteParams.dataExportId}/?download=true`
- );
- expect(wrapper.find('DateTime').prop('date')).toEqual(new Date(dateExpired));
- });
- it('should render the Open in Discover button when needed', function () {
- const status = DownloadStatus.Valid;
- getDataExportDetails({
- dateExpired,
- status,
- query: {
- type: ExportQueryType.Discover,
- info: {},
- },
- });
- const wrapper = mountWithTheme(<DataDownload params={mockRouteParams} />);
- const buttonWrapper = wrapper.find('button[aria-label="Open in Discover"]');
- expect(buttonWrapper.exists()).toBeTruthy();
- });
- it('should not render the Open in Discover button when not needed', function () {
- const status = DownloadStatus.Valid;
- getDataExportDetails({
- dateExpired,
- status,
- query: {
- type: ExportQueryType.IssuesByTag,
- info: {},
- },
- });
- const wrapper = mountWithTheme(<DataDownload params={mockRouteParams} />);
- const buttonWrapper = wrapper.find('button[aria-label="Open in Discover"]');
- expect(buttonWrapper.exists()).toBeFalsy();
- });
- });
|