index.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import OrganizationProjectsContainer from 'sentry/views/settings/organizationProjects';
  3. describe('OrganizationProjects', function () {
  4. let org;
  5. let project;
  6. let projectsGetMock;
  7. let statsGetMock;
  8. let projectsPutMock;
  9. const routerContext = TestStubs.routerContext();
  10. const router = TestStubs.router();
  11. beforeEach(function () {
  12. project = TestStubs.Project();
  13. org = TestStubs.Organization();
  14. projectsGetMock = MockApiClient.addMockResponse({
  15. url: '/organizations/org-slug/projects/',
  16. body: [project],
  17. });
  18. statsGetMock = MockApiClient.addMockResponse({
  19. url: '/organizations/org-slug/stats/',
  20. body: [[[], 1]],
  21. });
  22. projectsPutMock = MockApiClient.addMockResponse({
  23. method: 'PUT',
  24. url: '/projects/org-slug/project-slug/',
  25. });
  26. });
  27. afterEach(function () {
  28. MockApiClient.clearMockResponses();
  29. });
  30. it('should render the projects in the store', async function () {
  31. const {container} = render(
  32. <OrganizationProjectsContainer
  33. router={router}
  34. routes={router.routes}
  35. params={router.params}
  36. routeParams={router.params}
  37. route={router.routes[0]}
  38. location={{...router.location, query: {}}}
  39. />
  40. );
  41. expect(container).toSnapshot();
  42. expect(screen.getByText('project-slug')).toBeInTheDocument();
  43. expect(projectsGetMock).toHaveBeenCalledTimes(1);
  44. expect(statsGetMock).toHaveBeenCalledTimes(1);
  45. expect(projectsPutMock).toHaveBeenCalledTimes(0);
  46. await userEvent.click(screen.getByRole('button', {name: 'Bookmark Project'}));
  47. expect(
  48. screen.getByRole('button', {name: 'Bookmark Project', pressed: true})
  49. ).toBeInTheDocument();
  50. expect(projectsPutMock).toHaveBeenCalledTimes(1);
  51. });
  52. it('should search organization projects', async function () {
  53. const searchMock = MockApiClient.addMockResponse({
  54. url: `/organizations/${org.slug}/projects/`,
  55. body: [],
  56. });
  57. render(
  58. <OrganizationProjectsContainer
  59. router={router}
  60. routes={router.routes}
  61. params={router.params}
  62. routeParams={router.params}
  63. route={router.routes[0]}
  64. location={{...router.location, query: {}}}
  65. />,
  66. {
  67. context: routerContext,
  68. }
  69. );
  70. const searchBox = screen.getByRole('textbox');
  71. await userEvent.type(searchBox, project.slug);
  72. expect(searchMock).toHaveBeenLastCalledWith(
  73. `/organizations/${org.slug}/projects/`,
  74. expect.objectContaining({
  75. method: 'GET',
  76. query: {
  77. query: project.slug,
  78. },
  79. })
  80. );
  81. await userEvent.type(searchBox, '{enter}');
  82. expect(routerContext.context.router.push).toHaveBeenCalledTimes(1);
  83. });
  84. });