projectToolbar.spec.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import ProjectToolbarSettings from 'sentry/views/settings/project/projectToolbar';
  4. describe('ProjectToolbarSettings', function () {
  5. const {routerProps, organization, project, router} = initializeOrg({
  6. organization: {
  7. features: ['dev-toolbar-ui'],
  8. },
  9. });
  10. const url = `/projects/${organization.slug}/${project.slug}/`;
  11. beforeEach(function () {
  12. MockApiClient.clearMockResponses();
  13. });
  14. it('displays previously saved setting', function () {
  15. const initialOptionValue = 'sentry.io';
  16. project.options = {'sentry:toolbar_allowed_origins': initialOptionValue};
  17. render(
  18. <ProjectToolbarSettings
  19. {...routerProps}
  20. organization={organization}
  21. project={project}
  22. />,
  23. {
  24. router,
  25. }
  26. );
  27. expect(screen.getByRole('textbox')).toHaveValue(initialOptionValue);
  28. });
  29. it('can submit new allowed origins', async function () {
  30. render(
  31. <ProjectToolbarSettings
  32. {...routerProps}
  33. organization={organization}
  34. project={project}
  35. />,
  36. {
  37. router,
  38. }
  39. );
  40. const mockPut = MockApiClient.addMockResponse({
  41. url,
  42. method: 'PUT',
  43. });
  44. const textarea = screen.getByRole('textbox');
  45. expect(textarea).toBeEnabled();
  46. const mockInput = 'test.io\n*.example.com';
  47. await userEvent.clear(textarea);
  48. await userEvent.type(textarea, mockInput);
  49. await userEvent.tab(); // unfocus ("blur") the input
  50. expect(mockPut).toHaveBeenCalledWith(
  51. url,
  52. expect.objectContaining({
  53. method: 'PUT',
  54. data: {
  55. options: {'sentry:toolbar_allowed_origins': mockInput},
  56. },
  57. })
  58. );
  59. });
  60. it('displays nothing when project options are undefined', function () {
  61. project.options = undefined;
  62. render(
  63. <ProjectToolbarSettings
  64. {...routerProps}
  65. organization={organization}
  66. project={project}
  67. />,
  68. {
  69. router,
  70. }
  71. );
  72. expect(screen.getByRole('textbox')).toHaveValue('');
  73. });
  74. it('displays nothing when project options are empty', function () {
  75. project.options = {};
  76. render(
  77. <ProjectToolbarSettings
  78. {...routerProps}
  79. organization={organization}
  80. project={project}
  81. />,
  82. {
  83. router,
  84. }
  85. );
  86. expect(screen.getByRole('textbox')).toHaveValue('');
  87. });
  88. });