apiNewToken.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import selectEvent from 'react-select-event';
  2. import {RouterContextFixture} from 'sentry-fixture/routerContextFixture';
  3. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import ApiNewToken from 'sentry/views/settings/account/apiNewToken';
  5. describe('ApiNewToken', function () {
  6. it('renders', function () {
  7. render(<ApiNewToken />, {
  8. context: RouterContextFixture(),
  9. });
  10. });
  11. it('renders with disabled "Create Token" button', async function () {
  12. render(<ApiNewToken />, {
  13. context: RouterContextFixture(),
  14. });
  15. expect(await screen.getByRole('button', {name: 'Create Token'})).toBeDisabled();
  16. });
  17. it('submits with correct hierarchical scopes', async function () {
  18. MockApiClient.clearMockResponses();
  19. const assignMock = MockApiClient.addMockResponse({
  20. method: 'POST',
  21. url: `/api-tokens/`,
  22. });
  23. render(<ApiNewToken />, {
  24. context: RouterContextFixture(),
  25. });
  26. const createButton = await screen.getByRole('button', {name: 'Create Token'});
  27. const selectByValue = (name, value) =>
  28. selectEvent.select(screen.getByRole('textbox', {name}), value);
  29. // Assigning Admin here will also grant read + write access to the resource
  30. await selectByValue('Project', 'Admin');
  31. await selectByValue('Release', 'Admin');
  32. await selectByValue('Team', 'Admin');
  33. await selectByValue('Issue & Event', 'Admin');
  34. await selectByValue('Organization', 'Admin');
  35. await selectByValue('Member', 'Admin');
  36. await userEvent.click(createButton);
  37. await waitFor(() =>
  38. expect(assignMock).toHaveBeenCalledWith(
  39. '/api-tokens/',
  40. expect.objectContaining({
  41. data: expect.objectContaining({
  42. scopes: expect.arrayContaining([
  43. 'project:read',
  44. 'project:write',
  45. 'project:admin',
  46. 'project:releases',
  47. 'team:read',
  48. 'team:write',
  49. 'team:admin',
  50. 'event:read',
  51. 'event:write',
  52. 'event:admin',
  53. 'org:read',
  54. 'org:write',
  55. 'org:admin',
  56. 'org:integrations',
  57. 'member:read',
  58. 'member:write',
  59. 'member:admin',
  60. ]),
  61. }),
  62. })
  63. )
  64. );
  65. });
  66. });