projectToolbar.spec.tsx 2.4 KB

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