From a2c9177fd9e0f72b38cacdba32ab5cf1a9c22fcb Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Mon, 23 Dec 2019 13:04:09 +0100 Subject: [PATCH] SONAR-12215 Make projects list accessible --- .../dist/commonjs/AutoSizer.ts | 38 +++++++++++ .../dist/commonjs/WindowScroller.ts | 40 ++++++++++++ .../__snapshots__/GraphHistory-test.tsx.snap | 7 +- .../apps/projects/components/ProjectsList.tsx | 24 ++++--- .../__tests__/ProjectsList-test.tsx | 23 ++++++- .../__snapshots__/ProjectsList-test.tsx.snap | 65 +++++++++++++++---- 6 files changed, 167 insertions(+), 30 deletions(-) create mode 100644 server/sonar-web/__mocks__/react-virtualized/dist/commonjs/AutoSizer.ts create mode 100644 server/sonar-web/__mocks__/react-virtualized/dist/commonjs/WindowScroller.ts diff --git a/server/sonar-web/__mocks__/react-virtualized/dist/commonjs/AutoSizer.ts b/server/sonar-web/__mocks__/react-virtualized/dist/commonjs/AutoSizer.ts new file mode 100644 index 00000000000..a494f2f12e3 --- /dev/null +++ b/server/sonar-web/__mocks__/react-virtualized/dist/commonjs/AutoSizer.ts @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +type AutoSizerProps = { + children: (props: AutoSizerChildProps) => React.ReactNode; + disableHeight?: boolean; + disableWidth?: boolean; +}; +type AutoSizerChildProps = { height?: number; width?: number }; + +function AutoSizer({ children, disableHeight, disableWidth }: AutoSizerProps) { + const props: AutoSizerChildProps = {}; + if (!disableHeight) { + props.height = 200; + } + if (!disableWidth) { + props.width = 200; + } + return children(props); +} + +module.exports = { AutoSizer }; diff --git a/server/sonar-web/__mocks__/react-virtualized/dist/commonjs/WindowScroller.ts b/server/sonar-web/__mocks__/react-virtualized/dist/commonjs/WindowScroller.ts new file mode 100644 index 00000000000..641a7d883d9 --- /dev/null +++ b/server/sonar-web/__mocks__/react-virtualized/dist/commonjs/WindowScroller.ts @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +type WindowScrollerProps = { + children: (params: WindowScrollerChildProps) => React.ReactNode; +}; +type WindowScrollerChildProps = { + height: number; + isScrolling: boolean; + scrollTop: number; + onChildScroll: (params: { scrollTop: number }) => void; +}; + +function WindowScroller({ children }: WindowScrollerProps) { + const props: WindowScrollerChildProps = { + height: 200, + isScrolling: false, + scrollTop: 0, + onChildScroll: () => {} + }; + return children(props); +} + +module.exports = { WindowScroller }; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/GraphHistory-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/GraphHistory-test.tsx.snap index 0c35555fe88..afee3742c9e 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/GraphHistory-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/GraphHistory-test.tsx.snap @@ -32,12 +32,7 @@ exports[`should correctly render a graph 1`] = `
- +
diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx b/server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx index a7967ec2bcf..d2347e98c46 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx @@ -21,6 +21,7 @@ import * as React from 'react'; import { AutoSizer } from 'react-virtualized/dist/commonjs/AutoSizer'; import { List, ListRowProps } from 'react-virtualized/dist/commonjs/List'; import { WindowScroller } from 'react-virtualized/dist/commonjs/WindowScroller'; +import { translate } from 'sonar-ui-common/helpers/l10n'; import { OnboardingContext } from '../../../app/components/OnboardingContext'; import EmptySearch from '../../../components/common/EmptySearch'; import { Query } from '../query'; @@ -74,16 +75,18 @@ export default class ProjectsList extends React.PureComponent { const project = this.props.projects[index]; const height = this.getCardHeight(); return ( -
- +
+
+ +
); }; @@ -97,6 +100,7 @@ export default class ProjectsList extends React.PureComponent { {({ width }) => (
{ - expect(shallowRender()).toMatchSnapshot(); +jest.mock('react-virtualized/dist/commonjs/AutoSizer'); +jest.mock('react-virtualized/dist/commonjs/WindowScroller'); + +it('renders correctly', () => { + const wrapper = shallowRender(); + expect( + wrapper + .find(WindowScroller) + .dive() + .find(AutoSizer) + .dive() + ).toMatchSnapshot('list element'); + + expect( + wrapper.instance().renderRow({ index: 0, key: 'foo-key', style: {} } as ListRowProps) + ).toMatchSnapshot('row element'); }); it('renders different types of "no projects"', () => { @@ -32,7 +49,7 @@ it('renders different types of "no projects"', () => { }); function shallowRender(props?: any) { - return shallow( + return shallow( + +
+`; + +exports[`renders correctly: row element 1`] = `
- - - + +
`; -- 2.39.5