aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2019-03-19 11:50:07 +0100
committerSonarTech <sonartech@sonarsource.com>2019-04-08 20:21:06 +0200
commit5cd8d9390415373044bf4e69edc56a14bd014110 (patch)
treee7705bdc1a0b7574913be7f65130e99a6a07e153 /server/sonar-web/src
parent1f58a70b3b2b6531acf1e3e98443a5122e85fba6 (diff)
downloadsonarqube-5cd8d9390415373044bf4e69edc56a14bd014110.tar.gz
sonarqube-5cd8d9390415373044bf4e69edc56a14bd014110.zip
Add missing tests for components
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx96
-rw-r--r--server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityAnalysis-test.tsx.snap540
2 files changed, 636 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx
new file mode 100644
index 00000000000..89125bfe728
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx
@@ -0,0 +1,96 @@
+/*
+ * 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.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import ProjectActivityAnalysis from '../ProjectActivityAnalysis';
+import { mockParsedAnalysis, mockAnalysisEvent } from '../../../../helpers/testMocks';
+import { waitAndUpdate } from '../../../../helpers/testUtils';
+
+jest.mock('../../../../helpers/dates', () => ({
+ parseDate: () => ({
+ valueOf: () => 1546333200000,
+ toISOString: () => '2019-01-01T09:00:00.000Z'
+ })
+}));
+
+it('should render correctly', () => {
+ expect(shallowRender()).toMatchSnapshot();
+ expect(
+ shallowRender({ analysis: mockParsedAnalysis({ events: [mockAnalysisEvent()] }) })
+ ).toMatchSnapshot();
+ expect(
+ shallowRender({ analysis: mockParsedAnalysis({ buildString: '1.0.234' }) })
+ ).toMatchSnapshot();
+});
+
+it('should show the correct admin options', () => {
+ const wrapper = shallowRender({
+ canAdmin: true,
+ canCreateVersion: true,
+ canDeleteAnalyses: true
+ });
+ const instance = wrapper.instance();
+
+ expect(wrapper).toMatchSnapshot();
+
+ instance.setState({ addEventForm: true });
+ waitAndUpdate(wrapper);
+ expect(wrapper).toMatchSnapshot();
+ instance.setState({ addEventForm: false });
+
+ instance.setState({ removeAnalysisForm: true });
+ waitAndUpdate(wrapper);
+ expect(wrapper).toMatchSnapshot();
+ instance.setState({ removeAnalysisForm: false });
+
+ instance.setState({ addVersionForm: true });
+ waitAndUpdate(wrapper);
+ expect(wrapper).toMatchSnapshot();
+ instance.setState({ addVersionForm: false });
+});
+
+it('should not allow the first item to be deleted', () => {
+ expect(
+ shallowRender({
+ canAdmin: true,
+ canCreateVersion: true,
+ canDeleteAnalyses: true,
+ isFirst: true
+ })
+ ).toMatchSnapshot();
+});
+
+function shallowRender(props: Partial<ProjectActivityAnalysis['props']> = {}) {
+ return shallow(
+ <ProjectActivityAnalysis
+ addCustomEvent={jest.fn()}
+ addVersion={jest.fn()}
+ analysis={mockParsedAnalysis()}
+ canCreateVersion={false}
+ changeEvent={jest.fn()}
+ deleteAnalysis={jest.fn()}
+ deleteEvent={jest.fn()}
+ isFirst={false}
+ selected={false}
+ updateSelectedDate={jest.fn()}
+ {...props}
+ />
+ );
+}
diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityAnalysis-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityAnalysis-test.tsx.snap
new file mode 100644
index 00000000000..60706a012c2
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityAnalysis-test.tsx.snap
@@ -0,0 +1,540 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should not allow the first item to be deleted 1`] = `
+<Tooltip
+ mouseEnterDelay={0.5}
+ overlay={
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={true}
+ />
+ }
+ placement="left"
+>
+ <li
+ className="project-activity-analysis"
+ data-date={1546333200000}
+ onClick={[Function]}
+ tabIndex={0}
+ >
+ <div
+ className="project-activity-time spacer-right"
+ >
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={false}
+ >
+ <Component />
+ </TimeFormatter>
+ </div>
+ <div
+ className="project-activity-analysis-actions big-spacer-right"
+ >
+ <ActionsDropdown
+ small={true}
+ toggleClassName="js-analysis-actions"
+ >
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_version
+ </ActionsDropdownItem>
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_custom_event
+ </ActionsDropdownItem>
+ </ActionsDropdown>
+ </div>
+ </li>
+</Tooltip>
+`;
+
+exports[`should render correctly 1`] = `
+<Tooltip
+ mouseEnterDelay={0.5}
+ overlay={
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={true}
+ />
+ }
+ placement="left"
+>
+ <li
+ className="project-activity-analysis"
+ data-date={1546333200000}
+ onClick={[Function]}
+ tabIndex={0}
+ >
+ <div
+ className="project-activity-time spacer-right"
+ >
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={false}
+ >
+ <Component />
+ </TimeFormatter>
+ </div>
+ </li>
+</Tooltip>
+`;
+
+exports[`should render correctly 2`] = `
+<Tooltip
+ mouseEnterDelay={0.5}
+ overlay={
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={true}
+ />
+ }
+ placement="left"
+>
+ <li
+ className="project-activity-analysis"
+ data-date={1546333200000}
+ onClick={[Function]}
+ tabIndex={0}
+ >
+ <div
+ className="project-activity-time spacer-right"
+ >
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={false}
+ >
+ <Component />
+ </TimeFormatter>
+ </div>
+ <Events
+ analysis="foo"
+ changeEvent={[MockFunction]}
+ deleteEvent={[MockFunction]}
+ events={
+ Array [
+ Object {
+ "category": "QUALITY_GATE",
+ "description": "Lorem ipsum dolor sit amet",
+ "key": "E11",
+ "name": "Lorem ipsum",
+ "qualityGate": Object {
+ "failing": Array [
+ Object {
+ "branch": "master",
+ "key": "foo",
+ "name": "Foo",
+ },
+ Object {
+ "branch": "feature/bar",
+ "key": "bar",
+ "name": "Bar",
+ },
+ ],
+ "status": "ERROR",
+ "stillFailing": true,
+ },
+ },
+ ]
+ }
+ isFirst={false}
+ />
+ </li>
+</Tooltip>
+`;
+
+exports[`should render correctly 3`] = `
+<Tooltip
+ mouseEnterDelay={0.5}
+ overlay={
+ <React.Fragment>
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={true}
+ />
+ <br />
+ project_activity.analysis_build_string_X.1.0.234
+ </React.Fragment>
+ }
+ placement="left"
+>
+ <li
+ className="project-activity-analysis"
+ data-date={1546333200000}
+ onClick={[Function]}
+ tabIndex={0}
+ >
+ <div
+ className="project-activity-time spacer-right"
+ >
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={false}
+ >
+ <Component />
+ </TimeFormatter>
+ </div>
+ </li>
+</Tooltip>
+`;
+
+exports[`should show the correct admin options 1`] = `
+<Tooltip
+ mouseEnterDelay={0.5}
+ overlay={
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={true}
+ />
+ }
+ placement="left"
+>
+ <li
+ className="project-activity-analysis"
+ data-date={1546333200000}
+ onClick={[Function]}
+ tabIndex={0}
+ >
+ <div
+ className="project-activity-time spacer-right"
+ >
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={false}
+ >
+ <Component />
+ </TimeFormatter>
+ </div>
+ <div
+ className="project-activity-analysis-actions big-spacer-right"
+ >
+ <ActionsDropdown
+ small={true}
+ toggleClassName="js-analysis-actions"
+ >
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_version
+ </ActionsDropdownItem>
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_custom_event
+ </ActionsDropdownItem>
+ <ActionsDropdownDivider />
+ <ActionsDropdownItem
+ className="js-delete-analysis"
+ destructive={true}
+ onClick={[Function]}
+ >
+ project_activity.delete_analysis
+ </ActionsDropdownItem>
+ </ActionsDropdown>
+ </div>
+ </li>
+</Tooltip>
+`;
+
+exports[`should show the correct admin options 2`] = `
+<Tooltip
+ mouseEnterDelay={0.5}
+ overlay={
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={true}
+ />
+ }
+ placement="left"
+>
+ <li
+ className="project-activity-analysis"
+ data-date={1546333200000}
+ onClick={[Function]}
+ tabIndex={0}
+ >
+ <div
+ className="project-activity-time spacer-right"
+ >
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={false}
+ >
+ <Component />
+ </TimeFormatter>
+ </div>
+ <div
+ className="project-activity-analysis-actions big-spacer-right"
+ >
+ <ActionsDropdown
+ small={true}
+ toggleClassName="js-analysis-actions"
+ >
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_version
+ </ActionsDropdownItem>
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_custom_event
+ </ActionsDropdownItem>
+ <ActionsDropdownDivider />
+ <ActionsDropdownItem
+ className="js-delete-analysis"
+ destructive={true}
+ onClick={[Function]}
+ >
+ project_activity.delete_analysis
+ </ActionsDropdownItem>
+ </ActionsDropdown>
+ <AddEventForm
+ addEvent={[MockFunction]}
+ addEventButtonText="project_activity.add_custom_event"
+ analysis={
+ Object {
+ "date": 2017-03-01T08:36:01.000Z,
+ "events": Array [],
+ "key": "foo",
+ "projectVersion": "1.0",
+ }
+ }
+ onClose={[Function]}
+ />
+ </div>
+ </li>
+</Tooltip>
+`;
+
+exports[`should show the correct admin options 3`] = `
+<Tooltip
+ mouseEnterDelay={0.5}
+ overlay={
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={true}
+ />
+ }
+ placement="left"
+>
+ <li
+ className="project-activity-analysis"
+ data-date={1546333200000}
+ onClick={[Function]}
+ tabIndex={0}
+ >
+ <div
+ className="project-activity-time spacer-right"
+ >
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={false}
+ >
+ <Component />
+ </TimeFormatter>
+ </div>
+ <div
+ className="project-activity-analysis-actions big-spacer-right"
+ >
+ <ActionsDropdown
+ small={true}
+ toggleClassName="js-analysis-actions"
+ >
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_version
+ </ActionsDropdownItem>
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_custom_event
+ </ActionsDropdownItem>
+ <ActionsDropdownDivider />
+ <ActionsDropdownItem
+ className="js-delete-analysis"
+ destructive={true}
+ onClick={[Function]}
+ >
+ project_activity.delete_analysis
+ </ActionsDropdownItem>
+ </ActionsDropdown>
+ <RemoveAnalysisForm
+ analysis={
+ Object {
+ "date": 2017-03-01T08:36:01.000Z,
+ "events": Array [],
+ "key": "foo",
+ "projectVersion": "1.0",
+ }
+ }
+ deleteAnalysis={[MockFunction]}
+ onClose={[Function]}
+ />
+ </div>
+ </li>
+</Tooltip>
+`;
+
+exports[`should show the correct admin options 4`] = `
+<Tooltip
+ mouseEnterDelay={0.5}
+ overlay={
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={true}
+ />
+ }
+ placement="left"
+>
+ <li
+ className="project-activity-analysis"
+ data-date={1546333200000}
+ onClick={[Function]}
+ tabIndex={0}
+ >
+ <div
+ className="project-activity-time spacer-right"
+ >
+ <TimeFormatter
+ date={
+ Object {
+ "toISOString": [Function],
+ "valueOf": [Function],
+ }
+ }
+ long={false}
+ >
+ <Component />
+ </TimeFormatter>
+ </div>
+ <div
+ className="project-activity-analysis-actions big-spacer-right"
+ >
+ <ActionsDropdown
+ small={true}
+ toggleClassName="js-analysis-actions"
+ >
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_version
+ </ActionsDropdownItem>
+ <ActionsDropdownItem
+ className="js-add-event"
+ onClick={[Function]}
+ >
+ project_activity.add_custom_event
+ </ActionsDropdownItem>
+ <ActionsDropdownDivider />
+ <ActionsDropdownItem
+ className="js-delete-analysis"
+ destructive={true}
+ onClick={[Function]}
+ >
+ project_activity.delete_analysis
+ </ActionsDropdownItem>
+ </ActionsDropdown>
+ <AddEventForm
+ addEvent={[MockFunction]}
+ addEventButtonText="project_activity.add_version"
+ analysis={
+ Object {
+ "date": 2017-03-01T08:36:01.000Z,
+ "events": Array [],
+ "key": "foo",
+ "projectVersion": "1.0",
+ }
+ }
+ onClose={[Function]}
+ />
+ </div>
+ </li>
+</Tooltip>
+`;