12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import {ProjectFixture} from 'sentry-fixture/project';
- import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
- import {browserHistory} from 'sentry/utils/browserHistory';
- import OrganizationProjectsContainer from 'sentry/views/settings/organizationProjects';
- describe('OrganizationProjects', function () {
- let projectsGetMock: jest.Mock;
- let statsGetMock: jest.Mock;
- let projectsPutMock: jest.Mock;
- const project = ProjectFixture();
- beforeEach(function () {
- projectsGetMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [project],
- });
- statsGetMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/stats/',
- body: [[[], 1]],
- });
- projectsPutMock = MockApiClient.addMockResponse({
- method: 'PUT',
- url: '/projects/org-slug/project-slug/',
- });
- });
- afterEach(function () {
- MockApiClient.clearMockResponses();
- });
- it('should render the projects in the store', async function () {
- render(<OrganizationProjectsContainer />);
- expect(await screen.findByText('project-slug')).toBeInTheDocument();
- expect(projectsGetMock).toHaveBeenCalledTimes(1);
- expect(statsGetMock).toHaveBeenCalledTimes(1);
- expect(statsGetMock).toHaveBeenCalledWith(
- '/organizations/org-slug/stats/',
- expect.objectContaining({
- query: {
- group: 'project',
- projectID: [project.id],
- // Time is frozen in tests
- since: 1508121680,
- stat: 'generated',
- },
- })
- );
- expect(projectsPutMock).toHaveBeenCalledTimes(0);
- await userEvent.click(await screen.findByRole('button', {name: 'Bookmark Project'}));
- expect(
- await screen.findByRole('button', {name: 'Bookmark Project', pressed: true})
- ).toBeInTheDocument();
- expect(projectsPutMock).toHaveBeenCalledTimes(1);
- });
- it('should search organization projects', async function () {
- render(<OrganizationProjectsContainer />);
- expect(await screen.findByText('project-slug')).toBeInTheDocument();
- const searchBox = await screen.findByRole('textbox');
- await userEvent.type(searchBox, 'random');
- await waitFor(() => {
- expect(browserHistory.replace).toHaveBeenLastCalledWith({
- pathname: '/mock-pathname/',
- query: {query: 'random'},
- });
- });
- });
- });
|