import * as React from 'react';
import Helmet from 'react-helmet';
import ListFooter from 'sonar-ui-common/components/controls/ListFooter';
-import { toNotSoISOString } from 'sonar-ui-common/helpers/dates';
+import { toShortNotSoISOString } from 'sonar-ui-common/helpers/dates';
import { translate } from 'sonar-ui-common/helpers/l10n';
import { getComponents, Project } from '../../api/components';
import Suggestions from '../../app/components/embed-docs-modal/Suggestions';
requestProjects = () => {
const { analyzedBefore } = this.state;
const parameters = {
- analyzedBefore: analyzedBefore && toNotSoISOString(analyzedBefore),
+ analyzedBefore: analyzedBefore && toShortNotSoISOString(analyzedBefore),
onProvisionedOnly: this.state.provisioned || undefined,
organization: this.props.organization.key,
p: this.state.page !== 1 ? this.state.page : undefined,
import { shallow } from 'enzyme';
import * as React from 'react';
+import { getComponents } from '../../../api/components';
import App, { Props } from '../App';
+import Search from '../Search';
jest.mock('lodash', () => {
const lodash = require.requireActual('lodash');
return lodash;
});
-jest.mock('../../../api/components', () => ({ getComponents: jest.fn() }));
-
-const getComponents = require('../../../api/components').getComponents as jest.Mock<any>;
+jest.mock('../../../api/components', () => ({
+ getComponents: jest.fn().mockResolvedValue({ paging: { total: 0 }, components: [] })
+}));
const organization: T.Organization = { key: 'org', name: 'org', projectVisibility: 'public' };
};
beforeEach(() => {
- getComponents
- .mockImplementation(() => Promise.resolve({ paging: { total: 0 }, components: [] }))
- .mockClear();
+ jest.clearAllMocks();
});
it('fetches all projects on mount', () => {
expect(getComponents).lastCalledWith({ ...defaultSearchParameters, q: 'foo', qualifiers: 'TRK' });
});
+it('should handle date filtering', () => {
+ const wrapper = shallowRender();
+ wrapper
+ .find(Search)
+ .props()
+ .onDateChanged(new Date('2019-11-14T06:55:02.663Z'));
+ expect(getComponents).toHaveBeenCalledWith({
+ ...defaultSearchParameters,
+ qualifiers: 'TRK',
+ analyzedBefore: '2019-11-14'
+ });
+});
+
it('loads more', () => {
const wrapper = shallowRender();
wrapper.find('ListFooter').prop<Function>('loadMore')();
});
it('selects and deselects projects', async () => {
- getComponents.mockImplementation(() =>
+ (getComponents as jest.Mock).mockImplementation(() =>
Promise.resolve({ paging: { total: 2 }, components: [{ key: 'foo' }, { key: 'bar' }] })
);
const wrapper = shallowRender();
wrapper.find('CreateProjectForm').prop<Function>('onProjectCreated')();
wrapper.update();
- expect(getComponents.mock.calls).toHaveLength(2);
+ expect((getComponents as jest.Mock).mock.calls).toHaveLength(2);
wrapper.find('CreateProjectForm').prop<Function>('onClose')();
wrapper.update();
});
function shallowRender(props?: { [P in keyof Props]?: Props[P] }) {
- return shallow(
+ return shallow<App>(
<App
currentUser={{ login: 'foo' }}
hasProvisionPermission={true}