repositoryRow.spec.jsx 4.4 KB

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