index.spec.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import OrganizationProjectsContainer from 'sentry/views/settings/organizationProjects';
  3. describe('OrganizationProjects', function () {
  4. let projectsGetMock: jest.Mock;
  5. let statsGetMock: jest.Mock;
  6. let projectsPutMock: jest.Mock;
  7. const org = TestStubs.Organization();
  8. const project = TestStubs.Project();
  9. const routerProps = TestStubs.routeComponentProps();
  10. const routerContext = TestStubs.routerContext();
  11. const router = TestStubs.router();
  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(
  31. <OrganizationProjectsContainer
  32. {...routerProps}
  33. location={{...router.location, query: {}}}
  34. />
  35. );
  36. expect(screen.getByText('project-slug')).toBeInTheDocument();
  37. expect(projectsGetMock).toHaveBeenCalledTimes(1);
  38. expect(statsGetMock).toHaveBeenCalledTimes(1);
  39. expect(projectsPutMock).toHaveBeenCalledTimes(0);
  40. await userEvent.click(screen.getByRole('button', {name: 'Bookmark Project'}));
  41. expect(
  42. screen.getByRole('button', {name: 'Bookmark Project', pressed: true})
  43. ).toBeInTheDocument();
  44. expect(projectsPutMock).toHaveBeenCalledTimes(1);
  45. });
  46. it('should search organization projects', async function () {
  47. const searchMock = MockApiClient.addMockResponse({
  48. url: `/organizations/${org.slug}/projects/`,
  49. body: [],
  50. });
  51. render(
  52. <OrganizationProjectsContainer
  53. {...routerProps}
  54. location={{...router.location, query: {}}}
  55. />,
  56. {
  57. context: routerContext,
  58. }
  59. );
  60. const searchBox = screen.getByRole('textbox');
  61. await userEvent.type(searchBox, project.slug);
  62. expect(searchMock).toHaveBeenLastCalledWith(
  63. `/organizations/${org.slug}/projects/`,
  64. expect.objectContaining({
  65. method: 'GET',
  66. query: {
  67. query: project.slug,
  68. },
  69. })
  70. );
  71. await userEvent.type(searchBox, '{enter}');
  72. expect(routerContext.context.router.push).toHaveBeenCalledTimes(1);
  73. });
  74. });