aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorJeremy Davis <jeremy.davis@sonarsource.com>2019-11-13 16:01:34 +0900
committerSonarTech <sonartech@sonarsource.com>2019-12-04 20:46:09 +0100
commit668947a3d283074ea36006b9932ae91855f8ca73 (patch)
tree6817a8041a124f133051ff90749fc6c63c03cc4a /server/sonar-web
parent4a2af7bf6dd8f9b43686539de7c28767907a6719 (diff)
downloadsonarqube-668947a3d283074ea36006b9932ae91855f8ca73.tar.gz
sonarqube-668947a3d283074ea36006b9932ae91855f8ca73.zip
SONAR-12646 Fix inconsistent date filtering
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/apps/projectsManagement/App.tsx4
-rw-r--r--server/sonar-web/src/main/js/apps/projectsManagement/__tests__/App-test.tsx31
2 files changed, 24 insertions, 11 deletions
diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/App.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/App.tsx
index f8c96116762..1d31a5bc7a9 100644
--- a/server/sonar-web/src/main/js/apps/projectsManagement/App.tsx
+++ b/server/sonar-web/src/main/js/apps/projectsManagement/App.tsx
@@ -21,7 +21,7 @@ import { debounce, uniq, without } from 'lodash';
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';
@@ -86,7 +86,7 @@ export default class App extends React.PureComponent<Props, State> {
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,
diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/App-test.tsx
index 4ac8adae2bc..6941a34fbdc 100644
--- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/App-test.tsx
+++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/App-test.tsx
@@ -20,7 +20,9 @@
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');
@@ -28,9 +30,9 @@ jest.mock('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' };
@@ -42,9 +44,7 @@ const defaultSearchParameters = {
};
beforeEach(() => {
- getComponents
- .mockImplementation(() => Promise.resolve({ paging: { total: 0 }, components: [] }))
- .mockClear();
+ jest.clearAllMocks();
});
it('fetches all projects on mount', () => {
@@ -75,6 +75,19 @@ it('searches', () => {
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')();
@@ -82,7 +95,7 @@ it('loads more', () => {
});
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();
@@ -118,7 +131,7 @@ it('creates project', () => {
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();
@@ -133,7 +146,7 @@ it('changes default project visibility', () => {
});
function shallowRender(props?: { [P in keyof Props]?: Props[P] }) {
- return shallow(
+ return shallow<App>(
<App
currentUser={{ login: 'foo' }}
hasProvisionPermission={true}