index.spec.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {ProjectFixture} from 'sentry-fixture/project';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {browserHistory} from 'sentry/utils/browserHistory';
  4. import OrganizationProjectsContainer from 'sentry/views/settings/organizationProjects';
  5. describe('OrganizationProjects', function () {
  6. let projectsGetMock: jest.Mock;
  7. let statsGetMock: jest.Mock;
  8. let projectsPutMock: jest.Mock;
  9. const project = ProjectFixture();
  10. beforeEach(function () {
  11. projectsGetMock = MockApiClient.addMockResponse({
  12. url: '/organizations/org-slug/projects/',
  13. body: [project],
  14. });
  15. statsGetMock = MockApiClient.addMockResponse({
  16. url: '/organizations/org-slug/stats/',
  17. body: [[[], 1]],
  18. });
  19. projectsPutMock = MockApiClient.addMockResponse({
  20. method: 'PUT',
  21. url: '/projects/org-slug/project-slug/',
  22. });
  23. });
  24. afterEach(function () {
  25. MockApiClient.clearMockResponses();
  26. });
  27. it('should render the projects in the store', async function () {
  28. render(<OrganizationProjectsContainer />);
  29. expect(await screen.findByText('project-slug')).toBeInTheDocument();
  30. expect(projectsGetMock).toHaveBeenCalledTimes(1);
  31. expect(statsGetMock).toHaveBeenCalledTimes(1);
  32. expect(projectsPutMock).toHaveBeenCalledTimes(0);
  33. await userEvent.click(await screen.findByRole('button', {name: 'Bookmark Project'}));
  34. expect(
  35. await screen.findByRole('button', {name: 'Bookmark Project', pressed: true})
  36. ).toBeInTheDocument();
  37. expect(projectsPutMock).toHaveBeenCalledTimes(1);
  38. });
  39. it('should search organization projects', async function () {
  40. jest.useFakeTimers();
  41. render(<OrganizationProjectsContainer />);
  42. expect(await screen.findByText('project-slug')).toBeInTheDocument();
  43. const searchBox = await screen.findByRole('textbox');
  44. await userEvent.type(searchBox, 'random', {
  45. advanceTimers: jest.advanceTimersByTime,
  46. });
  47. jest.runAllTimers();
  48. expect(browserHistory.replace).toHaveBeenLastCalledWith({
  49. pathname: '/mock-pathname/',
  50. query: {query: 'random'},
  51. });
  52. });
  53. });