organizationProjects.spec.jsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {Client} from 'sentry/api';
  3. import OrganizationProjectsContainer from 'sentry/views/settings/organizationProjects';
  4. describe('OrganizationProjects', function () {
  5. let org;
  6. let project;
  7. let projectsGetMock;
  8. let statsGetMock;
  9. let projectsPutMock;
  10. const routerContext = TestStubs.routerContext();
  11. beforeEach(function () {
  12. project = TestStubs.Project();
  13. org = TestStubs.Organization();
  14. projectsGetMock = Client.addMockResponse({
  15. url: '/organizations/org-slug/projects/',
  16. body: [project],
  17. });
  18. statsGetMock = Client.addMockResponse({
  19. url: '/organizations/org-slug/stats/',
  20. body: [[[], 1]],
  21. });
  22. projectsPutMock = Client.addMockResponse({
  23. method: 'PUT',
  24. url: '/projects/org-slug/project-slug/',
  25. });
  26. });
  27. afterEach(function () {
  28. Client.clearMockResponses();
  29. });
  30. it('should render the projects in the store', function () {
  31. const wrapper = mountWithTheme(
  32. <OrganizationProjectsContainer params={{orgId: org.slug}} location={{query: {}}} />
  33. );
  34. expect(wrapper).toSnapshot();
  35. expect(wrapper.find('ProjectBadge').text()).toBe('project-slug');
  36. expect(projectsGetMock).toHaveBeenCalledTimes(1);
  37. expect(statsGetMock).toHaveBeenCalledTimes(1);
  38. expect(projectsPutMock).toHaveBeenCalledTimes(0);
  39. wrapper.find('BookmarkStar').simulate('click');
  40. expect(wrapper.find('BookmarkStar').prop('isBookmarked')).toBeTruthy();
  41. expect(projectsPutMock).toHaveBeenCalledTimes(1);
  42. });
  43. it('should search organization projects', function () {
  44. const searchMock = MockApiClient.addMockResponse({
  45. url: `/organizations/${org.slug}/projects/`,
  46. body: [],
  47. });
  48. const wrapper = mountWithTheme(
  49. <OrganizationProjectsContainer location={{query: {}}} params={{orgId: org.slug}} />,
  50. routerContext
  51. );
  52. wrapper
  53. .find('AsyncComponentSearchInput Input')
  54. .simulate('change', {target: {value: `${project.slug}`}});
  55. expect(searchMock).toHaveBeenLastCalledWith(
  56. `/organizations/${org.slug}/projects/`,
  57. expect.objectContaining({
  58. method: 'GET',
  59. query: {
  60. query: project.slug,
  61. },
  62. })
  63. );
  64. wrapper.find('SearchWrapper form').simulate('submit');
  65. expect(routerContext.context.router.push).toHaveBeenCalledTimes(1);
  66. });
  67. });