123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- import React from 'react';
- import {mountWithTheme} from 'sentry-test/enzyme';
- import TeamStore from 'app/stores/teamStore';
- import TeamSettings from 'app/views/settings/organizationTeams/teamSettings';
- describe('TeamSettings', function() {
- beforeEach(function() {
- MockApiClient.clearMockResponses();
- jest.spyOn(window.location, 'assign');
- });
- afterEach(function() {
- window.location.assign.mockRestore();
- });
- it('can change name and slug', async function() {
- const team = TestStubs.Team();
- const putMock = MockApiClient.addMockResponse({
- url: `/teams/org/${team.slug}/`,
- method: 'PUT',
- });
- const mountOptions = TestStubs.routerContext();
- const {router} = mountOptions.context;
- const wrapper = mountWithTheme(
- <TeamSettings
- routes={[]}
- router={router}
- params={{orgId: 'org', teamId: team.slug}}
- team={team}
- onTeamChange={() => {}}
- />,
- mountOptions
- );
- wrapper
- .find('input[name="name"]')
- .simulate('change', {target: {value: 'New Name'}})
- .simulate('blur');
- expect(putMock).toHaveBeenCalledWith(
- `/teams/org/${team.slug}/`,
- expect.objectContaining({
- data: {
- name: 'New Name',
- },
- })
- );
- wrapper
- .find('input[name="slug"]')
- .simulate('change', {target: {value: 'NEW SLUG'}})
- .simulate('blur');
- wrapper.find('SaveButton').simulate('click');
- expect(putMock).toHaveBeenCalledWith(
- `/teams/org/${team.slug}/`,
- expect.objectContaining({
- data: {
- slug: 'new-slug',
- },
- })
- );
- await tick();
- expect(router.replace).toHaveBeenCalledWith('/settings/org/teams/new-slug/settings/');
- });
- it('needs team:admin in order to see an enabled Remove Team button', function() {
- const team = TestStubs.Team();
- const wrapper = mountWithTheme(
- <TeamSettings
- routes={[]}
- params={{orgId: 'org', teamId: team.slug}}
- team={team}
- onTeamChange={() => {}}
- />,
- TestStubs.routerContext([{organization: TestStubs.Organization({access: []})}])
- );
- expect(
- wrapper
- .find('Panel')
- .last()
- .find('Button')
- .prop('disabled')
- ).toBe(true);
- });
- it('can remove team', async function() {
- const team = TestStubs.Team({hasAccess: true});
- const deleteMock = MockApiClient.addMockResponse({
- url: `/teams/org/${team.slug}/`,
- method: 'DELETE',
- });
- const routerPushMock = jest.fn();
- jest.spyOn(TeamStore, 'trigger');
- TeamStore.loadInitialData([
- {
- slug: 'team-slug',
- hasAccess: true,
- },
- ]);
- const wrapper = mountWithTheme(
- <TeamSettings
- router={{replace: routerPushMock}}
- routes={[]}
- params={{orgId: 'org', teamId: team.slug}}
- team={team}
- onTeamChange={() => {}}
- />,
- TestStubs.routerContext()
- );
- // Click "Remove Team button
- wrapper.find('Button[priority="danger"] button').simulate('click');
- TeamStore.trigger.mockReset();
- // Wait for modal
- wrapper.find('ModalDialog Button[priority="danger"] button').simulate('click');
- expect(deleteMock).toHaveBeenCalledWith(
- `/teams/org/${team.slug}/`,
- expect.objectContaining({
- method: 'DELETE',
- })
- );
- await tick();
- await tick();
- expect(routerPushMock).toHaveBeenCalledWith('/settings/org/teams/');
- expect(TeamStore.items).toEqual([]);
- TeamStore.trigger.mockRestore();
- });
- });
|