organizationProjects.spec.jsx 2.3 KB

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