index.spec.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {ProjectFixture} from 'sentry-fixture/project';
  2. import {RouterFixture} from 'sentry-fixture/routerFixture';
  3. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  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. const router = RouterFixture();
  11. beforeEach(function () {
  12. projectsGetMock = MockApiClient.addMockResponse({
  13. url: '/organizations/org-slug/projects/',
  14. body: [project],
  15. });
  16. statsGetMock = MockApiClient.addMockResponse({
  17. url: '/organizations/org-slug/stats/',
  18. body: [[[], 1]],
  19. });
  20. projectsPutMock = MockApiClient.addMockResponse({
  21. method: 'PUT',
  22. url: '/projects/org-slug/project-slug/',
  23. });
  24. });
  25. afterEach(function () {
  26. MockApiClient.clearMockResponses();
  27. });
  28. it('should render the projects in the store', async function () {
  29. render(<OrganizationProjectsContainer />, {router});
  30. expect(await screen.findByText('project-slug')).toBeInTheDocument();
  31. expect(projectsGetMock).toHaveBeenCalledTimes(1);
  32. expect(statsGetMock).toHaveBeenCalledTimes(1);
  33. expect(statsGetMock).toHaveBeenCalledWith(
  34. '/organizations/org-slug/stats/',
  35. expect.objectContaining({
  36. query: {
  37. group: 'project',
  38. projectID: [project.id],
  39. // Time is frozen in tests
  40. since: 1508121680,
  41. stat: 'generated',
  42. },
  43. })
  44. );
  45. expect(projectsPutMock).toHaveBeenCalledTimes(0);
  46. await userEvent.click(await screen.findByRole('button', {name: 'Bookmark'}));
  47. expect(
  48. await screen.findByRole('button', {name: 'Remove Bookmark', pressed: true})
  49. ).toBeInTheDocument();
  50. expect(projectsPutMock).toHaveBeenCalledTimes(1);
  51. });
  52. it('should search organization projects', async function () {
  53. render(<OrganizationProjectsContainer />, {router});
  54. expect(await screen.findByText('project-slug')).toBeInTheDocument();
  55. const searchBox = await screen.findByRole('textbox');
  56. await userEvent.type(searchBox, 'random');
  57. await waitFor(() => {
  58. expect(router.replace).toHaveBeenLastCalledWith({
  59. pathname: '/mock-pathname/',
  60. query: {query: 'random'},
  61. });
  62. });
  63. });
  64. });