index.spec.jsx 2.3 KB

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