details.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. } from 'sentry-test/reactTestingLibrary';
  7. import ApiApplicationDetails from 'sentry/views/settings/account/apiApplications/details';
  8. describe('ApiApplications', function () {
  9. it('renders basic details for newly created App', async function () {
  10. MockApiClient.addMockResponse({
  11. url: '/api-applications/abcd/',
  12. body: {
  13. allowedOrigins: ['http://example.com'],
  14. clientID: 'abcd',
  15. clientSecret: '1234',
  16. homepageUrl: 'http://example.com/homepage',
  17. id: 'abcd',
  18. name: 'Example App Name',
  19. privacyUrl: 'http://example.com/privacy',
  20. redirectUris: ['http://example.com/redirect'],
  21. termsUrl: ['http://example.com/terms'],
  22. },
  23. });
  24. render(<ApiApplicationDetails />, {
  25. router: {
  26. params: {
  27. appId: 'abcd',
  28. },
  29. },
  30. });
  31. expect(
  32. await screen.findByRole('heading', {name: 'Application Details'})
  33. ).toBeInTheDocument();
  34. expect(screen.getByDisplayValue('http://example.com')).toBeInTheDocument();
  35. expect(screen.getByDisplayValue('http://example.com/redirect')).toBeInTheDocument();
  36. expect(screen.getByDisplayValue('http://example.com/privacy')).toBeInTheDocument();
  37. expect(screen.getByDisplayValue('http://example.com/terms')).toBeInTheDocument();
  38. expect(screen.getByDisplayValue('abcd')).toBeInTheDocument();
  39. expect(screen.getByDisplayValue('1234')).toBeInTheDocument();
  40. expect(screen.getByDisplayValue('Example App Name')).toBeInTheDocument();
  41. expect(screen.getByLabelText('Name')).toBeInTheDocument();
  42. expect(screen.getByLabelText('Homepage')).toBeInTheDocument();
  43. expect(screen.getByLabelText('Privacy Policy')).toBeInTheDocument();
  44. expect(screen.getByLabelText('Terms of Service')).toBeInTheDocument();
  45. expect(screen.getByLabelText('Authorized Redirect URIs')).toBeInTheDocument();
  46. expect(screen.getByLabelText('Authorized JavaScript Origins')).toBeInTheDocument();
  47. expect(screen.getByLabelText('Client ID')).toBeInTheDocument();
  48. expect(screen.getByLabelText('Client Secret')).toBeInTheDocument();
  49. expect(screen.getByLabelText('Authorization URL')).toBeInTheDocument();
  50. expect(screen.getByLabelText('Token URL')).toBeInTheDocument();
  51. });
  52. it('handles client secret rotation', async function () {
  53. MockApiClient.addMockResponse({
  54. url: '/api-applications/abcd/',
  55. body: {
  56. allowedOrigins: ['http://example.com'],
  57. clientID: 'abcd',
  58. clientSecret: null,
  59. homepageUrl: 'http://example.com/homepage',
  60. id: 'abcd',
  61. name: 'Example App Name',
  62. privacyUrl: 'http://example.com/privacy',
  63. redirectUris: ['http://example.com/redirect'],
  64. termsUrl: ['http://example.com/terms'],
  65. },
  66. });
  67. const rotateSecretApiCall = MockApiClient.addMockResponse({
  68. method: 'POST',
  69. url: '/api-applications/abcd/rotate-secret/',
  70. body: {
  71. clientSecret: 'newSecret!',
  72. },
  73. });
  74. render(<ApiApplicationDetails />, {
  75. router: {
  76. params: {
  77. appId: 'abcd',
  78. },
  79. },
  80. });
  81. renderGlobalModal();
  82. expect(await screen.findByText('hidden')).toBeInTheDocument();
  83. expect(
  84. screen.getByRole('button', {name: 'Rotate client secret'})
  85. ).toBeInTheDocument();
  86. await userEvent.click(screen.getByRole('button', {name: 'Rotate client secret'}));
  87. // Confirm modal
  88. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  89. expect(
  90. screen.getByText('This will be the only time your client secret is visible!')
  91. ).toBeInTheDocument();
  92. expect(screen.getByText('Your new Client Secret')).toBeInTheDocument();
  93. expect(screen.getByLabelText<HTMLInputElement>('new-client-secret')).toHaveValue(
  94. 'newSecret!'
  95. );
  96. expect(rotateSecretApiCall).toHaveBeenCalledTimes(1);
  97. });
  98. });