repositoryRow.spec.jsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {Client} from 'app/api';
  4. import RepositoryRow from 'app/components/repositoryRow';
  5. describe('RepositoryRow', function() {
  6. beforeEach(function() {
  7. Client.clearMockResponses();
  8. });
  9. const repository = TestStubs.Repository();
  10. const pendingRepo = TestStubs.Repository({
  11. status: 'pending_deletion',
  12. });
  13. const api = new Client();
  14. describe('rendering with access', function() {
  15. const organization = TestStubs.Organization({
  16. access: ['org:integrations'],
  17. });
  18. const routerContext = TestStubs.routerContext([{organization}]);
  19. it('displays provider information', function() {
  20. const wrapper = mountWithTheme(
  21. <RepositoryRow repository={repository} api={api} orgId={organization.slug} />,
  22. routerContext
  23. );
  24. expect(wrapper.find('strong').text()).toEqual(repository.name);
  25. expect(wrapper.find('small a').text()).toEqual('github.com/example/repo-name');
  26. // Trash button should display enabled
  27. expect(wrapper.find('Confirm').props().disabled).toEqual(false);
  28. // No cancel button
  29. expect(wrapper.find('Button[data-test-id="repo-cancel"]')).toHaveLength(0);
  30. });
  31. it('displays cancel pending button', function() {
  32. const wrapper = mountWithTheme(
  33. <RepositoryRow repository={pendingRepo} api={api} orgId={organization.slug} />,
  34. routerContext
  35. );
  36. // Trash button should be disabled
  37. expect(wrapper.find('Confirm').props().disabled).toEqual(true);
  38. expect(wrapper.find('Button[label="delete"]').props().disabled).toEqual(true);
  39. // Cancel button active
  40. const cancel = wrapper.find('Button[data-test-id="repo-cancel"]');
  41. expect(cancel).toHaveLength(1);
  42. expect(cancel.props().disabled).toEqual(false);
  43. });
  44. });
  45. describe('rendering without access', function() {
  46. const organization = TestStubs.Organization({
  47. access: ['org:write'],
  48. });
  49. const routerContext = TestStubs.routerContext([{organization}]);
  50. it('displays disabled trash', function() {
  51. const wrapper = mountWithTheme(
  52. <RepositoryRow repository={repository} api={api} orgId={organization.slug} />,
  53. routerContext
  54. );
  55. // Trash button should be disabled
  56. expect(wrapper.find('Confirm').props().disabled).toEqual(true);
  57. expect(wrapper.find('Button[label="delete"]').props().disabled).toEqual(true);
  58. });
  59. it('displays disabled cancel', function() {
  60. const wrapper = mountWithTheme(
  61. <RepositoryRow repository={pendingRepo} api={api} orgId={organization.slug} />,
  62. routerContext
  63. );
  64. // Cancel should be disabled
  65. expect(wrapper.find('Button[data-test-id="repo-cancel"]').props().disabled).toEqual(
  66. true
  67. );
  68. });
  69. });
  70. describe('deletion', function() {
  71. const organization = TestStubs.Organization({
  72. access: ['org:integrations'],
  73. });
  74. const routerContext = TestStubs.routerContext([{organization}]);
  75. it('sends api request on delete', async function() {
  76. const deleteRepo = Client.addMockResponse({
  77. url: `/organizations/${organization.slug}/repos/${repository.id}/`,
  78. method: 'DELETE',
  79. statusCode: 204,
  80. body: {},
  81. });
  82. const wrapper = mountWithTheme(
  83. <RepositoryRow repository={repository} api={api} orgId={organization.slug} />,
  84. routerContext
  85. );
  86. wrapper.find('Button[label="delete"]').simulate('click');
  87. await tick();
  88. // Confirm modal
  89. wrapper.find('ModalDialog Button[priority="primary"]').simulate('click');
  90. await wrapper.update();
  91. expect(deleteRepo).toHaveBeenCalled();
  92. });
  93. });
  94. describe('cancel deletion', function() {
  95. const organization = TestStubs.Organization({
  96. access: ['org:integrations'],
  97. });
  98. const routerContext = TestStubs.routerContext([{organization}]);
  99. it('sends api request to cancel', async function() {
  100. const cancel = Client.addMockResponse({
  101. url: `/organizations/${organization.slug}/repos/${pendingRepo.id}/`,
  102. method: 'PUT',
  103. statusCode: 204,
  104. body: {},
  105. });
  106. const wrapper = mountWithTheme(
  107. <RepositoryRow repository={pendingRepo} api={api} orgId={organization.slug} />,
  108. routerContext
  109. );
  110. wrapper.find('Button[data-test-id="repo-cancel"]').simulate('click');
  111. await wrapper.update();
  112. expect(cancel).toHaveBeenCalled();
  113. });
  114. });
  115. });