index.spec.tsx 2.2 KB

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