organizationTeamProjects.spec.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import {Client} from 'app/api';
  4. import TeamStore from 'app/stores/teamStore';
  5. import ProjectsStore from 'app/stores/projectsStore';
  6. import OrganizationTeamProjects from 'app/views/settings/team/teamProjects';
  7. describe('OrganizationTeamProjects', function() {
  8. let project;
  9. let project2;
  10. let team;
  11. let putMock;
  12. let postMock;
  13. let deleteMock;
  14. beforeEach(function() {
  15. team = TestStubs.Team({slug: 'team-slug'});
  16. project = TestStubs.Project({teams: [team]});
  17. project2 = TestStubs.Project({
  18. id: '3',
  19. slug: 'project-slug-2',
  20. name: 'Project Name 2',
  21. });
  22. TeamStore.loadInitialData([team]);
  23. ProjectsStore.loadInitialData([project, project2]);
  24. putMock = Client.addMockResponse({
  25. method: 'PUT',
  26. url: '/projects/org-slug/project-slug/',
  27. body: project,
  28. });
  29. postMock = Client.addMockResponse({
  30. method: 'POST',
  31. url: `/projects/org-slug/${project2.slug}/teams/${team.slug}/`,
  32. body: {...project2, teams: [team]},
  33. status: 201,
  34. });
  35. deleteMock = Client.addMockResponse({
  36. method: 'DELETE',
  37. url: `/projects/org-slug/${project2.slug}/teams/${team.slug}/`,
  38. body: {...project2, teams: []},
  39. status: 204,
  40. });
  41. });
  42. afterEach(function() {
  43. Client.clearMockResponses();
  44. });
  45. it('Should render', function() {
  46. let wrapper = mount(
  47. <OrganizationTeamProjects params={{orgId: 'org-slug', teamId: team.slug}} />,
  48. TestStubs.routerOrganizationContext()
  49. );
  50. expect(wrapper).toMatchSnapshot();
  51. expect(wrapper.find('.project-name').text()).toBe('Project Name');
  52. });
  53. it('Should allow bookmarking', function() {
  54. let wrapper = mount(
  55. <OrganizationTeamProjects params={{orgId: 'org-slug', teamId: team.slug}} />,
  56. TestStubs.routerOrganizationContext()
  57. );
  58. let star = wrapper.find('.icon-star-outline');
  59. expect(star.length).toBe(1);
  60. star.simulate('click');
  61. star = wrapper.find('.icon-star-outline');
  62. expect(star.length).toBe(0);
  63. star = wrapper.find('.icon-star-solid');
  64. expect(star.length).toBe(1);
  65. expect(putMock).toHaveBeenCalledTimes(1);
  66. });
  67. it('Should allow adding and removing projects', function(done) {
  68. let wrapper = mount(
  69. <OrganizationTeamProjects params={{orgId: 'org-slug', teamId: team.slug}} />,
  70. TestStubs.routerOrganizationContext()
  71. );
  72. let add = wrapper.find('DropdownButton').first();
  73. add.simulate('click');
  74. let el = wrapper.find('AutoCompleteItem').first();
  75. el.simulate('click');
  76. wrapper.update();
  77. expect(postMock).toHaveBeenCalledTimes(1);
  78. setTimeout(() => {
  79. wrapper.update();
  80. // find first project's remove button
  81. let remove = wrapper.find('Button').at(1);
  82. remove.simulate('click');
  83. expect(deleteMock).toHaveBeenCalledTimes(1);
  84. done();
  85. }, 1);
  86. });
  87. });