From 668947a3d283074ea36006b9932ae91855f8ca73 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Wed, 13 Nov 2019 16:01:34 +0900 Subject: [PATCH] SONAR-12646 Fix inconsistent date filtering --- .../main/js/apps/projectsManagement/App.tsx | 4 +-- .../projectsManagement/__tests__/App-test.tsx | 31 +++++++++++++------ 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 { 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; +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('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('onProjectCreated')(); wrapper.update(); - expect(getComponents.mock.calls).toHaveLength(2); + expect((getComponents as jest.Mock).mock.calls).toHaveLength(2); wrapper.find('CreateProjectForm').prop('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(