index.spec.jsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {Client} from 'sentry/api';
  3. import OrganizationProjectsContainer from 'sentry/views/settings/organizationProjects';
  4. describe('OrganizationProjects', function () {
  5. let org;
  6. let project;
  7. let projectsGetMock;
  8. let statsGetMock;
  9. let projectsPutMock;
  10. const routerContext = TestStubs.routerContext();
  11. beforeEach(function () {
  12. project = TestStubs.Project();
  13. org = TestStubs.Organization();
  14. projectsGetMock = Client.addMockResponse({
  15. url: '/organizations/org-slug/projects/',
  16. body: [project],
  17. });
  18. statsGetMock = Client.addMockResponse({
  19. url: '/organizations/org-slug/stats/',
  20. body: [[[], 1]],
  21. });
  22. projectsPutMock = Client.addMockResponse({
  23. method: 'PUT',
  24. url: '/projects/org-slug/project-slug/',
  25. });
  26. });
  27. afterEach(function () {
  28. Client.clearMockResponses();
  29. });
  30. it('should render the projects in the store', function () {
  31. const {container} = render(
  32. <OrganizationProjectsContainer params={{orgId: org.slug}} location={{query: {}}} />
  33. );
  34. expect(container).toSnapshot();
  35. expect(screen.getByText('project-slug')).toBeInTheDocument();
  36. expect(projectsGetMock).toHaveBeenCalledTimes(1);
  37. expect(statsGetMock).toHaveBeenCalledTimes(1);
  38. expect(projectsPutMock).toHaveBeenCalledTimes(0);
  39. userEvent.click(screen.getByRole('button', {name: 'Bookmark Project'}));
  40. expect(
  41. screen.getByRole('button', {name: 'Bookmark Project', pressed: true})
  42. ).toBeInTheDocument();
  43. expect(projectsPutMock).toHaveBeenCalledTimes(1);
  44. });
  45. it('should search organization projects', function () {
  46. const searchMock = MockApiClient.addMockResponse({
  47. url: `/organizations/${org.slug}/projects/`,
  48. body: [],
  49. });
  50. render(
  51. <OrganizationProjectsContainer location={{query: {}}} params={{orgId: org.slug}} />,
  52. {context: routerContext}
  53. );
  54. const searchBox = screen.getByRole('textbox');
  55. userEvent.type(searchBox, project.slug);
  56. expect(searchMock).toHaveBeenLastCalledWith(
  57. `/organizations/${org.slug}/projects/`,
  58. expect.objectContaining({
  59. method: 'GET',
  60. query: {
  61. query: project.slug,
  62. },
  63. })
  64. );
  65. userEvent.type(searchBox, '{enter}');
  66. expect(routerContext.context.router.push).toHaveBeenCalledTimes(1);
  67. });
  68. });