bookmarkStar.spec.jsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React from 'react';
  2. import {mount} from 'sentry-test/enzyme';
  3. import BookmarkStar from 'app/components/projects/bookmarkStar';
  4. describe('BookmarkStar', function () {
  5. let wrapper, projectMock;
  6. beforeEach(function () {
  7. wrapper = mount(
  8. <BookmarkStar
  9. organization={TestStubs.Organization()}
  10. project={TestStubs.Project()}
  11. />,
  12. TestStubs.routerContext()
  13. );
  14. projectMock = MockApiClient.addMockResponse({
  15. url: '/projects/org-slug/project-slug/',
  16. method: 'PUT',
  17. data: TestStubs.Project({isBookmarked: false, platform: 'javascript'}),
  18. });
  19. });
  20. afterEach(function () {
  21. MockApiClient.clearMockResponses();
  22. });
  23. it('renders', function () {
  24. expect(wrapper).toSnapshot();
  25. });
  26. it('can star', async function () {
  27. const star = wrapper.find('BookmarkStar');
  28. expect(star.find('Star').first().prop('isBookmarked')).toBe(false);
  29. star.simulate('click');
  30. expect(projectMock).toHaveBeenCalledWith(
  31. '/projects/org-slug/project-slug/',
  32. expect.objectContaining({
  33. data: {
  34. isBookmarked: true,
  35. },
  36. })
  37. );
  38. });
  39. it('can unstar', async function () {
  40. wrapper = mount(
  41. <BookmarkStar
  42. organization={TestStubs.Organization()}
  43. project={TestStubs.Project({
  44. isBookmarked: true,
  45. })}
  46. />,
  47. TestStubs.routerContext()
  48. );
  49. const star = wrapper.find('BookmarkStar');
  50. expect(star.find('Star').first().prop('isBookmarked')).toBe(true);
  51. star.simulate('click');
  52. expect(projectMock).toHaveBeenCalledWith(
  53. '/projects/org-slug/project-slug/',
  54. expect.objectContaining({
  55. data: {
  56. isBookmarked: false,
  57. },
  58. })
  59. );
  60. });
  61. it('takes a manual isBookmarked prop', function () {
  62. wrapper = mount(
  63. <BookmarkStar
  64. organization={TestStubs.Organization()}
  65. project={TestStubs.Project()}
  66. isBookmarked
  67. />,
  68. TestStubs.routerContext()
  69. );
  70. const star = wrapper.find('BookmarkStar');
  71. expect(star.find('Star').first().prop('isBookmarked')).toBe(true);
  72. star.simulate('click');
  73. expect(star.find('Star').first().prop('isBookmarked')).toBe(true);
  74. });
  75. });