index.spec.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {ProjectFixture} from 'sentry-fixture/project';
  2. import {render, screen, userEvent, waitFor} 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(statsGetMock).toHaveBeenCalledWith(
  33. '/organizations/org-slug/stats/',
  34. expect.objectContaining({
  35. query: {
  36. group: 'project',
  37. projectID: [project.id],
  38. // Time is frozen in tests
  39. since: 1508121680,
  40. stat: 'generated',
  41. },
  42. })
  43. );
  44. expect(projectsPutMock).toHaveBeenCalledTimes(0);
  45. await userEvent.click(await screen.findByRole('button', {name: 'Bookmark'}));
  46. expect(
  47. await screen.findByRole('button', {name: 'Remove Bookmark', pressed: true})
  48. ).toBeInTheDocument();
  49. expect(projectsPutMock).toHaveBeenCalledTimes(1);
  50. });
  51. it('should search organization projects', async function () {
  52. render(<OrganizationProjectsContainer />);
  53. expect(await screen.findByText('project-slug')).toBeInTheDocument();
  54. const searchBox = await screen.findByRole('textbox');
  55. await userEvent.type(searchBox, 'random');
  56. await waitFor(() => {
  57. expect(browserHistory.replace).toHaveBeenLastCalledWith({
  58. pathname: '/mock-pathname/',
  59. query: {query: 'random'},
  60. });
  61. });
  62. });
  63. });