index.spec.tsx 2.6 KB

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