accountAuthorizations.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {ApiApplicationFixture} from 'sentry-fixture/apiApplication';
  2. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import AccountAuthorizations from 'sentry/views/settings/account/accountAuthorizations';
  4. describe('AccountAuthorizations', function () {
  5. beforeEach(function () {
  6. MockApiClient.clearMockResponses();
  7. });
  8. it('renders empty', async function () {
  9. MockApiClient.addMockResponse({
  10. url: '/api-authorizations/',
  11. method: 'GET',
  12. body: [],
  13. });
  14. render(<AccountAuthorizations />);
  15. expect(
  16. await screen.findByText("You haven't approved any third party applications.")
  17. ).toBeInTheDocument();
  18. });
  19. it('revokes authorizations correctly', async function () {
  20. MockApiClient.addMockResponse({
  21. url: '/api-authorizations/',
  22. method: 'GET',
  23. body: [
  24. {
  25. application: ApiApplicationFixture({name: 'Delete Shrimp'}),
  26. homepageUrl: 'test.com',
  27. id: 'delete_shrimp',
  28. scopes: [],
  29. },
  30. {
  31. application: ApiApplicationFixture({name: 'Keep Shrimp'}),
  32. homepageUrl: 'test2.com',
  33. id: 'keep_shrimp',
  34. scopes: [],
  35. },
  36. ],
  37. });
  38. const deleteMock = MockApiClient.addMockResponse({
  39. url: '/api-authorizations/',
  40. method: 'DELETE',
  41. });
  42. render(<AccountAuthorizations />);
  43. expect(await screen.findByText('Delete Shrimp')).toBeInTheDocument();
  44. expect(await screen.findByText('Keep Shrimp')).toBeInTheDocument();
  45. // delete the 'Detete Shrimp' authorization
  46. await userEvent.click(screen.getByTestId('delete_shrimp'));
  47. expect(deleteMock).toHaveBeenCalledWith(
  48. '/api-authorizations/',
  49. expect.objectContaining({
  50. method: 'DELETE',
  51. data: {authorization: 'delete_shrimp'},
  52. })
  53. );
  54. await waitFor(() =>
  55. expect(screen.queryByText('Delete Shrimp')).not.toBeInTheDocument()
  56. );
  57. await waitFor(() => expect(screen.queryByText('Keep Shrimp')).toBeInTheDocument());
  58. });
  59. });