teamSettings.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import PropTypes from 'prop-types';
  2. import React from 'react';
  3. import {mount, shallow} from 'enzyme';
  4. import TeamSettings from 'app/views/settings/team/teamSettings.old';
  5. import NewTeamSettings from 'app/views/settings/team/teamSettings';
  6. const childContextTypes = {
  7. organization: PropTypes.object,
  8. router: PropTypes.object,
  9. location: PropTypes.object,
  10. };
  11. // #NEW-SETTINGS
  12. describe('TeamSettings', function() {
  13. describe('render()', function() {
  14. let wrapper;
  15. beforeEach(function() {
  16. let team = TestStubs.Team();
  17. wrapper = shallow(
  18. <TeamSettings
  19. routes={[]}
  20. params={{orgId: 'org', teamId: team.slug}}
  21. team={team}
  22. onTeamChange={() => {}}
  23. />,
  24. {
  25. context: {
  26. router: TestStubs.router(),
  27. organization: {
  28. id: '1337',
  29. access: [],
  30. },
  31. },
  32. childContextTypes,
  33. }
  34. );
  35. });
  36. it('renders', function() {
  37. wrapper.update();
  38. expect(wrapper).toMatchSnapshot();
  39. });
  40. it('renders with remove team', function() {
  41. wrapper.setContext({
  42. organization: {
  43. id: '1337',
  44. access: ['team:admin'],
  45. },
  46. });
  47. wrapper.update();
  48. expect(wrapper).toMatchSnapshot();
  49. });
  50. });
  51. });
  52. describe('NewTeamSettings', function() {
  53. beforeEach(function() {
  54. MockApiClient.clearMockResponses();
  55. sinon.stub(window.location, 'assign');
  56. });
  57. afterEach(function() {
  58. window.location.assign.restore();
  59. });
  60. it('can change name and slug', function(done) {
  61. let team = TestStubs.Team();
  62. let putMock = MockApiClient.addMockResponse({
  63. url: `/teams/org/${team.slug}/`,
  64. method: 'PUT',
  65. });
  66. let wrapper = mount(
  67. <NewTeamSettings
  68. routes={[]}
  69. params={{orgId: 'org', teamId: team.slug}}
  70. team={team}
  71. onTeamChange={() => {}}
  72. />,
  73. TestStubs.routerContext()
  74. );
  75. wrapper
  76. .find('input[name="name"]')
  77. .simulate('change', {target: {value: 'New Name'}})
  78. .simulate('blur');
  79. expect(putMock).toHaveBeenCalledWith(
  80. `/teams/org/${team.slug}/`,
  81. expect.objectContaining({
  82. data: {
  83. name: 'New Name',
  84. },
  85. })
  86. );
  87. wrapper
  88. .find('input[name="slug"]')
  89. .simulate('change', {target: {value: 'new-slug'}})
  90. .simulate('blur');
  91. expect(putMock).toHaveBeenCalledWith(
  92. `/teams/org/${team.slug}/`,
  93. expect.objectContaining({
  94. data: {
  95. slug: 'new-slug',
  96. },
  97. })
  98. );
  99. setTimeout(() => {
  100. expect(
  101. window.location.assign.calledWith('/settings/org/teams/new-slug/settings/')
  102. ).toBe(true);
  103. done();
  104. }, 1);
  105. });
  106. });