apiNewToken.spec.tsx 2.2 KB

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