index.spec.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*global global*/
  2. import React from 'react';
  3. import {Client} from 'app/api';
  4. import {mount} from 'enzyme';
  5. import OrganizationDeveloperSettings from 'app/views/settings/organizationDeveloperSettings/index';
  6. describe('Organization Developer Settings', function() {
  7. let org = TestStubs.Organization();
  8. let sentryApp = TestStubs.SentryApp();
  9. let routerContext = TestStubs.routerContext();
  10. beforeEach(() => {
  11. Client.clearMockResponses();
  12. });
  13. describe('when no Apps exist', () => {
  14. Client.addMockResponse({
  15. url: `/organizations/${org.slug}/sentry-apps/`,
  16. body: [],
  17. });
  18. const wrapper = mount(
  19. <OrganizationDeveloperSettings params={{orgId: org.slug}} />,
  20. routerContext
  21. );
  22. it('displays empty state', () => {
  23. expect(wrapper).toMatchSnapshot();
  24. expect(wrapper.exists('EmptyMessage')).toBe(true);
  25. });
  26. });
  27. describe('with unpublished apps', () => {
  28. Client.addMockResponse({
  29. url: `/organizations/${org.slug}/sentry-apps/`,
  30. body: [sentryApp],
  31. });
  32. let wrapper = mount(
  33. <OrganizationDeveloperSettings params={{orgId: org.slug}} />,
  34. routerContext
  35. );
  36. it('displays all Apps owned by the Org', () => {
  37. expect(wrapper).toMatchSnapshot();
  38. expect(wrapper.find('SentryApplicationRow').prop('app').name).toBe('Sample App');
  39. // shows correct published status
  40. });
  41. it('allows for deletion', async () => {
  42. Client.addMockResponse({
  43. url: `/sentry-apps/${sentryApp.slug}/`,
  44. method: 'DELETE',
  45. body: [],
  46. });
  47. expect(wrapper.find('[icon="icon-trash"]').prop('disabled')).toEqual(false);
  48. wrapper.find('[icon="icon-trash"]').simulate('click');
  49. // confirm deletion by entering in app slug
  50. wrapper.find('input').simulate('change', {target: {value: 'sample-app'}});
  51. wrapper
  52. .find('ConfirmDelete Button')
  53. .last()
  54. .simulate('click');
  55. await tick();
  56. wrapper.update();
  57. expect(wrapper.state('applications')).toEqual([]);
  58. });
  59. });
  60. describe('with published apps', () => {
  61. const publishedSentryApp = TestStubs.SentryApp({status: 'published'});
  62. Client.addMockResponse({
  63. url: `/organizations/${org.slug}/sentry-apps/`,
  64. body: [publishedSentryApp],
  65. });
  66. let wrapper = mount(
  67. <OrganizationDeveloperSettings params={{orgId: org.slug}} />,
  68. routerContext
  69. );
  70. it('trash button is disabled', () => {
  71. expect(wrapper).toMatchSnapshot();
  72. expect(wrapper.find('[icon="icon-trash"]').prop('disabled')).toEqual(true);
  73. });
  74. });
  75. });