From: Stas Vilchik Date: Fri, 1 Sep 2017 09:18:10 +0000 (+0200) Subject: SONAR-9702 rewrite some background tasks components X-Git-Tag: 6.6-RC1~380^2~23 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c01264d91bd4d05e405d4e93e2accd5fefb81136;p=sonarqube.git SONAR-9702 rewrite some background tasks components --- diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.js b/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.js deleted file mode 100644 index f5286bccfd8..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.js +++ /dev/null @@ -1,106 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -// @flow -import React from 'react'; -import Modal from 'react-modal'; -import { getTask } from '../../../api/ce'; -import { translate } from '../../../helpers/l10n'; - -/*:: -type Props = { - onClose: () => void, - task: { componentName: string, id: string, type: string } -}; -*/ - -/*:: -type State = { - scannerContext: ?string -}; -*/ - -export default class ScannerContext extends React.PureComponent { - /*:: mounted: boolean; */ - /*:: props: Props; */ - state /*: State */ = { - scannerContext: null - }; - - componentDidMount() { - this.mounted = true; - this.loadScannerContext(); - } - - componentWillUnmount() { - this.mounted = false; - } - - loadScannerContext() { - getTask(this.props.task.id, ['scannerContext']).then(task => { - if (this.mounted) { - this.setState({ scannerContext: task.scannerContext }); - } - }); - } - - handleCloseClick = (event /*: Event */) => { - event.preventDefault(); - this.props.onClose(); - }; - - render() { - const { task } = this.props; - const { scannerContext } = this.state; - - return ( - -
-

- {translate('background_tasks.scanner_context')} - {': '} - {task.componentName} - {' ['} - {translate('background_task.type', task.type)} - {']'} -

-
- -
- {scannerContext != null - ?
-                {scannerContext}
-              
- : } -
- -
- - {translate('close')} - -
-
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx new file mode 100644 index 00000000000..c15d38eda16 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx @@ -0,0 +1,99 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 Modal from 'react-modal'; +import { getTask } from '../../../api/ce'; +import { translate } from '../../../helpers/l10n'; +import { Task } from '../types'; + +interface Props { + onClose: () => void; + task: Task; +} + +interface State { + scannerContext?: string; +} + +export default class ScannerContext extends React.PureComponent { + mounted: boolean; + state: State = {}; + + componentDidMount() { + this.mounted = true; + this.loadScannerContext(); + } + + componentWillUnmount() { + this.mounted = false; + } + + loadScannerContext() { + getTask(this.props.task.id, ['scannerContext']).then(task => { + if (this.mounted) { + this.setState({ scannerContext: task.scannerContext }); + } + }); + } + + handleCloseClick = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.props.onClose(); + }; + + render() { + const { task } = this.props; + const { scannerContext } = this.state; + + return ( + +
+

+ {translate('background_tasks.scanner_context')} + {': '} + {task.componentName} + {' ['} + {translate('background_task.type', task.type)} + {']'} +

+
+ +
+ {scannerContext != null + ?
+                {scannerContext}
+              
+ : } +
+ + +
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.js deleted file mode 100644 index 9f00597e2b7..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.js +++ /dev/null @@ -1,122 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -// @flow -import React from 'react'; -import Modal from 'react-modal'; -import { getTask } from '../../../api/ce'; -import { translate } from '../../../helpers/l10n'; - -/*:: -type Props = { - onClose: () => void, - task: { componentName: string, errorMessage: string, id: string, type: string } -}; -*/ - -/*:: -type State = { - loading: boolean, - stacktrace: ?string -}; -*/ - -export default class Stacktrace extends React.PureComponent { - /*:: mounted: boolean; */ - /*:: props: Props; */ - state /*: State */ = { - loading: true, - stacktrace: null - }; - - componentDidMount() { - this.mounted = true; - this.loadStacktrace(); - } - - componentWillUnmount() { - this.mounted = false; - } - - loadStacktrace() { - getTask(this.props.task.id, ['stacktrace']).then(task => { - if (this.mounted) { - this.setState({ loading: false, stacktrace: task.errorStacktrace }); - } - }); - } - - handleCloseClick = (event /*: Event */) => { - event.preventDefault(); - this.props.onClose(); - }; - - render() { - const { task } = this.props; - const { loading, stacktrace } = this.state; - - return ( - -
-

- {translate('background_tasks.error_stacktrace')} - {': '} - {task.componentName} - {' ['} - {translate('background_task.type', task.type)} - {']'} -

-
- -
- {loading - ? - : stacktrace - ?
-

- {translate('background_tasks.error_stacktrace')} -

-
-                    {stacktrace}
-                  
-
- :
-

- {translate('background_tasks.error_message')} -

-
-                    {task.errorMessage}
-                  
-
} -
- - -
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx new file mode 100644 index 00000000000..1397e58ac6a --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx @@ -0,0 +1,114 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 Modal from 'react-modal'; +import { getTask } from '../../../api/ce'; +import { translate } from '../../../helpers/l10n'; +import { Task } from '../types'; + +interface Props { + onClose: () => void; + task: Task; +} + +interface State { + loading: boolean; + stacktrace?: string; +} + +export default class Stacktrace extends React.PureComponent { + mounted: boolean; + state: State = { loading: true }; + + componentDidMount() { + this.mounted = true; + this.loadStacktrace(); + } + + componentWillUnmount() { + this.mounted = false; + } + + loadStacktrace() { + getTask(this.props.task.id, ['stacktrace']).then(task => { + if (this.mounted) { + this.setState({ loading: false, stacktrace: task.errorStacktrace }); + } + }); + } + + handleCloseClick = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.props.onClose(); + }; + + render() { + const { task } = this.props; + const { loading, stacktrace } = this.state; + + return ( + +
+

+ {translate('background_tasks.error_stacktrace')} + {': '} + {task.componentName} + {' ['} + {translate('background_task.type', task.type)} + {']'} +

+
+ +
+ {loading + ? + : stacktrace + ?
+

+ {translate('background_tasks.error_stacktrace')} +

+
+                    {stacktrace}
+                  
+
+ :
+

+ {translate('background_tasks.error_message')} +

+
+                    {task.errorMessage}
+                  
+
} +
+ + +
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Task.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Task.js deleted file mode 100644 index 3c93857dadb..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Task.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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 React from 'react'; -import PropTypes from 'prop-types'; -import TaskStatus from './TaskStatus'; -import TaskComponent from './TaskComponent'; -import TaskId from './TaskId'; -import TaskDay from './TaskDay'; -import TaskDate from './TaskDate'; -import TaskExecutionTime from './TaskExecutionTime'; -import TaskActions from './TaskActions'; - -export default class Task extends React.PureComponent { - static propTypes = { - task: PropTypes.object.isRequired, - index: PropTypes.number.isRequired, - tasks: PropTypes.array.isRequired, - component: PropTypes.object, - onCancelTask: PropTypes.func.isRequired, - onFilterTask: PropTypes.func.isRequired - }; - - render() { - const { task, index, tasks, component, onCancelTask, onFilterTask } = this.props; - - const prevTask = index > 0 ? tasks[index - 1] : null; - - return ( - - - - - - - - - - - - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx new file mode 100644 index 00000000000..701fffd7ced --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx @@ -0,0 +1,62 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 TaskStatus from './TaskStatus'; +import TaskComponent from './TaskComponent'; +import TaskId from './TaskId'; +import TaskDay from './TaskDay'; +import TaskDate from './TaskDate'; +import TaskExecutionTime from './TaskExecutionTime'; +import TaskActions from './TaskActions'; +import { Task as ITask } from '../types'; + +interface Props { + component?: {}; + onCancelTask: (task: ITask) => void; + onFilterTask: (task: ITask) => void; + task: ITask; + previousTask?: ITask; +} + +export default function Task(props: Props) { + const { task, component, onCancelTask, onFilterTask, previousTask } = props; + + return ( + + + + + + + + + + + + ); +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js deleted file mode 100644 index 03b8be8455d..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js +++ /dev/null @@ -1,122 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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 React from 'react'; -import ScannerContext from './ScannerContext'; -import Stacktrace from './Stacktrace'; -import { STATUSES } from './../constants'; -import { translate, translateWithParameters } from '../../../helpers/l10n'; - -export default class TaskActions extends React.PureComponent { - state = { - scannerContextOpen: false, - stacktraceOpen: false - }; - - handleFilterClick(e) { - e.preventDefault(); - this.props.onFilterTask(this.props.task); - } - - handleCancelClick(e) { - e.preventDefault(); - this.props.onCancelTask(this.props.task); - } - - handleShowScannerContextClick(e) { - e.preventDefault(); - this.setState({ scannerContextOpen: true }); - } - - closeScannerContext = () => this.setState({ scannerContextOpen: false }); - - handleShowStacktraceClick(e) { - e.preventDefault(); - this.setState({ stacktraceOpen: true }); - } - - closeStacktrace = () => this.setState({ stacktraceOpen: false }); - - render() { - const { component, task } = this.props; - - const canFilter = component == null; - const canCancel = task.status === STATUSES.PENDING; - const canShowStacktrace = task.errorMessage != null; - const hasActions = canFilter || canCancel || task.hasScannerContext || canShowStacktrace; - - if (!hasActions) { - return  ; - } - - return ( - - - - {this.state.scannerContextOpen && - } - - {this.state.stacktraceOpen && } - - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx new file mode 100644 index 00000000000..e75801aa4f8 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx @@ -0,0 +1,136 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 ScannerContext from './ScannerContext'; +import Stacktrace from './Stacktrace'; +import { STATUSES } from './../constants'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; +import { Task } from '../types'; + +interface Props { + component?: {}; + onCancelTask: (task: Task) => void; + onFilterTask: (task: Task) => void; + task: Task; +} + +interface State { + scannerContextOpen: boolean; + stacktraceOpen: boolean; +} + +export default class TaskActions extends React.PureComponent { + state: State = { + scannerContextOpen: false, + stacktraceOpen: false + }; + + handleFilterClick = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.props.onFilterTask(this.props.task); + }; + + handleCancelClick = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.props.onCancelTask(this.props.task); + }; + + handleShowScannerContextClick = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.setState({ scannerContextOpen: true }); + }; + + closeScannerContext = () => this.setState({ scannerContextOpen: false }); + + handleShowStacktraceClick = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.setState({ stacktraceOpen: true }); + }; + + closeStacktrace = () => this.setState({ stacktraceOpen: false }); + + render() { + const { component, task } = this.props; + + const canFilter = component == undefined; + const canCancel = task.status === STATUSES.PENDING; + const canShowStacktrace = task.errorMessage != undefined; + const hasActions = canFilter || canCancel || task.hasScannerContext || canShowStacktrace; + + if (!hasActions) { + return  ; + } + + return ( + + + + {this.state.scannerContextOpen && + } + + {this.state.stacktraceOpen && } + + ); + } +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.js deleted file mode 100644 index 1123a8de956..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.js +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -/* @flow */ -import React from 'react'; -import { Link } from 'react-router'; -import TaskType from './TaskType'; -import QualifierIcon from '../../../components/shared/QualifierIcon'; -import Organization from '../../../components/shared/Organization'; -/*:: import type { Task } from '../types'; */ - -/*:: -type Props = { - task: Task -}; -*/ - -export default function TaskComponent(props /*: Props */) { - const { task } = props; - - if (!task.componentKey) { - return ( - - - {task.id} - - - - ); - } - - return ( - - - - - - {task.organization != null && } - - - {task.componentName} - - - - - ); -} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx new file mode 100644 index 00000000000..07bb92df540 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 { Link } from 'react-router'; +import TaskType from './TaskType'; +import QualifierIcon from '../../../components/shared/QualifierIcon'; +import Organization from '../../../components/shared/Organization'; +import { Task } from '../types'; + +interface Props { + task: Task; +} + +export default function TaskComponent({ task }: Props) { + if (!task.componentKey) { + return ( + + + {task.id} + + + + ); + } + + return ( + + {task.componentQualifier && + + + } + + {task.organization && } + + {task.componentName && + + {task.componentName} + } + + + + ); +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDate.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDate.tsx index 525d8bbc420..6cebb2f9af6 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDate.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDate.tsx @@ -22,15 +22,15 @@ import TimeFormatter from '../../../components/intl/TimeFormatter'; import { differenceInDays, isValidDate, parseDate } from '../../../helpers/dates'; interface Props { - date: string; - baseDate: string; + date?: string; + baseDate?: string; } export default function TaskDate({ date, baseDate }: Props) { - const parsedDate = parseDate(date); - const parsedBaseDate = parseDate(baseDate); + const parsedDate = date && parseDate(date); + const parsedBaseDate = baseDate && parseDate(baseDate); const diff = - date && baseDate && isValidDate(parsedDate) && isValidDate(parsedBaseDate) + parsedDate && parsedBaseDate && isValidDate(parsedDate) && isValidDate(parsedBaseDate) ? differenceInDays(parsedDate, parsedBaseDate) : 0; @@ -38,7 +38,7 @@ export default function TaskDate({ date, baseDate }: Props) { {diff > 0 && {`(+${diff}d)`}} - {date && isValidDate(parsedDate) ? : ''} + {parsedDate && isValidDate(parsedDate) ? : ''} ); } diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDay.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDay.tsx index c2d8911358b..46bb3879a6a 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDay.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDay.tsx @@ -20,20 +20,19 @@ import * as React from 'react'; import DateFormatter from '../../../components/intl/DateFormatter'; import { isSameDay, parseDate } from '../../../helpers/dates'; -import { ITask } from '../types'; interface Props { - task: ITask; - prevTask?: ITask; + submittedAt: string; + prevSubmittedAt?: string; } -export default function TaskDay({ task, prevTask }: Props) { +export default function TaskDay({ submittedAt, prevSubmittedAt }: Props) { const shouldDisplay = - !prevTask || !isSameDay(parseDate(task.submittedAt), parseDate(prevTask.submittedAt)); + !prevSubmittedAt || !isSameDay(parseDate(submittedAt), parseDate(prevSubmittedAt)); return ( - {shouldDisplay ? : ''} + {shouldDisplay ? : ''} ); } diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.js deleted file mode 100644 index ee2eedb43e5..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -/* @flow */ -import React from 'react'; -import { formatDuration } from '../utils'; -/*:: import type { Task } from '../types'; */ - -const TaskExecutionTime = ({ task } /*: { task: Task } */) => { - return ( - - {formatDuration(task.executionTimeMs)} - - ); -}; - -export default TaskExecutionTime; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.tsx new file mode 100644 index 00000000000..55baca3f360 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.tsx @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 { formatDuration } from '../utils'; + +interface Props { + ms?: number; +} + +export default function TaskExecutionTime({ ms }: Props) { + return ( + + {ms && formatDuration(ms)} + + ); +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskId.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskId.js deleted file mode 100644 index b4e705d4f54..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskId.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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 React from 'react'; - -const TaskId = ({ task }) => { - return ( - -
- {task.id} -
- - ); -}; - -export default TaskId; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskId.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskId.tsx new file mode 100644 index 00000000000..cd2215d40e6 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskId.tsx @@ -0,0 +1,34 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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'; + +interface Props { + id: string; +} + +export default function TaskId({ id }: Props) { + return ( + +
+ {id} +
+ + ); +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.js deleted file mode 100644 index b2ef518c558..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.js +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -/* @flow */ -import React from 'react'; -import { STATUSES } from './../constants'; -import PendingIcon from '../../../components/icons-components/PendingIcon'; -import { translate } from '../../../helpers/l10n'; -/*:: import type { Task } from '../types'; */ - -const TaskStatus = ({ task } /*: { task: Task } */) => { - let inner; - - switch (task.status) { - case STATUSES.PENDING: - inner = ; - break; - case STATUSES.IN_PROGRESS: - inner = ; - break; - case STATUSES.SUCCESS: - inner = ( - - {translate('background_task.status.SUCCESS')} - - ); - break; - case STATUSES.FAILED: - inner = ( - - {translate('background_task.status.FAILED')} - - ); - break; - case STATUSES.CANCELED: - inner = ( - - {translate('background_task.status.CANCELED')} - - ); - break; - default: - inner = ''; - } - - return ( - - {inner} - - ); -}; - -export default TaskStatus; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.tsx new file mode 100644 index 00000000000..87b2a7d7338 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.tsx @@ -0,0 +1,69 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 { STATUSES } from './../constants'; +import PendingIcon from '../../../components/icons-components/PendingIcon'; +import { translate } from '../../../helpers/l10n'; + +interface Props { + status: string; +} + +export default function TaskStatus({ status }: Props) { + let inner; + + switch (status) { + case STATUSES.PENDING: + inner = ; + break; + case STATUSES.IN_PROGRESS: + inner = ; + break; + case STATUSES.SUCCESS: + inner = ( + + {translate('background_task.status.SUCCESS')} + + ); + break; + case STATUSES.FAILED: + inner = ( + + {translate('background_task.status.FAILED')} + + ); + break; + case STATUSES.CANCELED: + inner = ( + + {translate('background_task.status.CANCELED')} + + ); + break; + default: + inner = ''; + } + + return ( + + {inner} + + ); +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.js deleted file mode 100644 index da9f6c36f41..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -/* @flow */ -import React from 'react'; -/*:: import type { Task } from '../types'; */ -import { translate } from '../../../helpers/l10n'; - -const TaskType = ({ task } /*: { task: Task } */) => { - return ( - - {'['} - {translate('background_task.type', task.type)} - {task.incremental && ` - ${translate('incremental')}`} - {']'} - - ); -}; - -export default TaskType; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.tsx new file mode 100644 index 00000000000..5769bdb868a --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.tsx @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 { translate } from '../../../helpers/l10n'; + +interface Props { + incremental?: boolean; + type: string; +} + +export default function TaskType({ incremental, type }: Props) { + return ( + + {'['} + {translate('background_task.type', type)} + {incremental && ` - ${translate('incremental')}`} + {']'} + + ); +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.js index fef3f83eea7..ebbfb3f253e 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.js @@ -82,11 +82,11 @@ export default class Tasks extends React.PureComponent { 0 ? tasks[index - 1] : undefined} /> )} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx new file mode 100644 index 00000000000..af7194151d6 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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. + */ +jest.mock('../../../../api/ce', () => ({ + getTask: jest.fn() +})); + +import * as React from 'react'; +import { mount, shallow } from 'enzyme'; +import ScannerContext from '../ScannerContext'; +import { click, doAsync } from '../../../../helpers/testUtils'; + +const getTask = require('../../../../api/ce').getTask as jest.Mock; + +const task = { + componentName: 'foo', + status: 'PENDING', + id: '123', + submittedAt: '2017-01-01', + type: 'REPORT' +}; + +it('renders', () => { + const wrapper = shallow(); + wrapper.setState({ scannerContext: 'context' }); + expect(wrapper).toMatchSnapshot(); +}); + +it('closes', () => { + const onClose = jest.fn(); + const wrapper = shallow(); + click(wrapper.find('.js-modal-close')); + expect(onClose).toBeCalled(); +}); + +it('fetches scanner context on mount', () => { + getTask.mockImplementation(() => Promise.resolve({ scannerContext: 'context' })); + const wrapper = mount(); + expect(wrapper.state()).toEqual({}); + expect(getTask).toBeCalledWith('123', ['scannerContext']); + return doAsync().then(() => { + expect(wrapper.state()).toEqual({ scannerContext: 'context' }); + }); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx new file mode 100644 index 00000000000..979af8df09e --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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. + */ +jest.mock('../../../../api/ce', () => ({ + getTask: jest.fn() +})); + +import * as React from 'react'; +import { mount, shallow } from 'enzyme'; +import Stacktrace from '../Stacktrace'; +import { click, doAsync } from '../../../../helpers/testUtils'; + +const getTask = require('../../../../api/ce').getTask as jest.Mock; + +const task = { + componentName: 'foo', + status: 'PENDING', + id: '123', + submittedAt: '2017-01-01', + type: 'REPORT' +}; + +it('renders', () => { + const wrapper = shallow(); + wrapper.setState({ loading: false, stacktrace: 'stacktrace' }); + expect(wrapper).toMatchSnapshot(); +}); + +it('closes', () => { + const onClose = jest.fn(); + const wrapper = shallow(); + click(wrapper.find('.js-modal-close')); + expect(onClose).toBeCalled(); +}); + +it('fetches scanner context on mount', () => { + getTask.mockImplementation(() => Promise.resolve({ errorStacktrace: 'stacktrace' })); + const wrapper = mount(); + expect(wrapper.state()).toEqual({ loading: true }); + expect(getTask).toBeCalledWith('123', ['stacktrace']); + return doAsync().then(() => { + expect(wrapper.state()).toEqual({ loading: false, stacktrace: 'stacktrace' }); + }); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx new file mode 100644 index 00000000000..a928e53ae78 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 Task from '../Task'; + +it('renders', () => { + expect( + shallow( + + ) + ).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx new file mode 100644 index 00000000000..940fe3341da --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx @@ -0,0 +1,65 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 TaskActions from '../TaskActions'; +import { click } from '../../../../helpers/testUtils'; + +it('renders', () => { + expect(shallowRender()).toMatchSnapshot(); + expect(shallowRender({ status: 'SUCCESS' })).toMatchSnapshot(); + expect(shallowRender({ hasScannerContext: true })).toMatchSnapshot(); + expect(shallowRender({ errorMessage: 'error!' })).toMatchSnapshot(); + expect(shallowRender({}, { component: { key: 'foo' } })).toMatchSnapshot(); +}); + +it('shows stack trace', () => { + const wrapper = shallowRender({ errorMessage: 'error!' }); + click(wrapper.find('.js-task-show-stacktrace')); + expect(wrapper.find('Stacktrace')).toMatchSnapshot(); + wrapper.find('Stacktrace').prop('onClose')(); + expect(wrapper.find('Stacktrace')).toMatchSnapshot(); +}); + +it('shows scanner context', () => { + const wrapper = shallowRender({ hasScannerContext: true }); + click(wrapper.find('.js-task-show-scanner-context')); + expect(wrapper.find('ScannerContext')).toMatchSnapshot(); + wrapper.find('ScannerContext').prop('onClose')(); + expect(wrapper.find('ScannerContext')).toMatchSnapshot(); +}); + +function shallowRender(fields?: any, props?: any) { + return shallow( + + ); +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.js b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.js deleted file mode 100644 index b1c54c7f158..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -/* @flow */ -import React from 'react'; -import { shallow } from 'enzyme'; -import TaskComponent from '../TaskComponent'; - -it('renders', () => { - const task = { - componentKey: 'foo', - componentName: 'foo', - componentQualifier: 'TRK', - id: 'bar', - organization: 'org', - type: 'REPORT' - }; - expect(shallow()).toMatchSnapshot(); - expect(shallow()).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx new file mode 100644 index 00000000000..5f12acf8f48 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 TaskComponent from '../TaskComponent'; + +it('renders', () => { + const task = { + componentKey: 'foo', + componentName: 'foo', + componentQualifier: 'TRK', + id: 'bar', + organization: 'org', + status: 'PENDING', + submittedAt: '2017-01-01', + type: 'REPORT' + }; + expect(shallow()).toMatchSnapshot(); + expect(shallow()).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDate-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDate-test.tsx new file mode 100644 index 00000000000..7e37c8dbfa6 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDate-test.tsx @@ -0,0 +1,29 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 TaskDate from '../TaskDate'; + +it('renders', () => { + expect(shallow()).toMatchSnapshot(); + expect(shallow()).toMatchSnapshot(); + expect(shallow()).toMatchSnapshot(); + expect(shallow()).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDay-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDay-test.tsx new file mode 100644 index 00000000000..2413a5689a0 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDay-test.tsx @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 TaskDay from '../TaskDay'; + +it('renders', () => { + expect( + shallow() + ).toMatchSnapshot(); + + expect( + shallow() + ).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskExecutionTime-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskExecutionTime-test.tsx new file mode 100644 index 00000000000..77bd3e73e70 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskExecutionTime-test.tsx @@ -0,0 +1,27 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 TaskExecutionTime from '../TaskExecutionTime'; + +it('renders', () => { + expect(shallow()).toMatchSnapshot(); + expect(shallow()).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskId-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskId-test.tsx new file mode 100644 index 00000000000..63cca20adb9 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskId-test.tsx @@ -0,0 +1,26 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 TaskId from '../TaskId'; + +it('renders', () => { + expect(shallow()).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskStatus-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskStatus-test.tsx new file mode 100644 index 00000000000..e404108db57 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskStatus-test.tsx @@ -0,0 +1,30 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 TaskStatus from '../TaskStatus'; + +it('renders', () => { + expect.assertions(5); + const statuses = ['PENDING', 'IN_PROGRESS', 'SUCCESS', 'FAILED', 'CANCELED']; + statuses.forEach(status => { + expect(shallow()).toMatchSnapshot(); + }); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskType-test.js b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskType-test.js deleted file mode 100644 index ed32df32523..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskType-test.js +++ /dev/null @@ -1,28 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -/* @flow */ -import React from 'react'; -import { shallow } from 'enzyme'; -import TaskType from '../TaskType'; - -it('renders', () => { - expect(shallow()).toMatchSnapshot(); - expect(shallow()).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskType-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskType-test.tsx new file mode 100644 index 00000000000..1c0e961622f --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskType-test.tsx @@ -0,0 +1,27 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 TaskType from '../TaskType'; + +it('renders', () => { + expect(shallow()).toMatchSnapshot(); + expect(shallow()).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/ScannerContext-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/ScannerContext-test.tsx.snap new file mode 100644 index 00000000000..8b3ce1ea4b6 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/ScannerContext-test.tsx.snap @@ -0,0 +1,50 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + +
+

+ background_tasks.scanner_context + : + foo + [ + background_task.type.REPORT + ] +

+
+
+
+      context
+    
+
+ +
+`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Stacktrace-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Stacktrace-test.tsx.snap new file mode 100644 index 00000000000..d1fad07e61d --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Stacktrace-test.tsx.snap @@ -0,0 +1,57 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + +
+

+ background_tasks.error_stacktrace + : + foo + [ + background_task.type.REPORT + ] +

+
+
+
+

+ background_tasks.error_stacktrace +

+
+        stacktrace
+      
+
+
+ +
+`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Task-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Task-test.tsx.snap new file mode 100644 index 00000000000..0fab9afcace --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Task-test.tsx.snap @@ -0,0 +1,49 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + + + + + + + + + + + +`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap new file mode 100644 index 00000000000..9de3ec891a0 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap @@ -0,0 +1,272 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + + + +`; + +exports[`renders 2`] = ` + + + +`; + +exports[`renders 3`] = ` + + + +`; + +exports[`renders 4`] = ` + + + +`; + +exports[`renders 5`] = ` + + + +`; + +exports[`shows scanner context 1`] = ` + +`; + +exports[`shows scanner context 2`] = `undefined`; + +exports[`shows stack trace 1`] = ` + +`; + +exports[`shows stack trace 2`] = `undefined`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.js.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.js.snap deleted file mode 100644 index 703c9f27eea..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.js.snap +++ /dev/null @@ -1,64 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders 1`] = ` - - - - - - - foo - - - -`; - -exports[`renders 2`] = ` - - - bar - - - -`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap new file mode 100644 index 00000000000..b8fec515315 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + + + + + + + foo + + + +`; + +exports[`renders 2`] = ` + + + bar + + + +`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDate-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDate-test.tsx.snap new file mode 100644 index 00000000000..2222e541e98 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDate-test.tsx.snap @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + +`; + +exports[`renders 2`] = ` + + + +`; + +exports[`renders 3`] = ` + + + +`; + +exports[`renders 4`] = ` + + + (+4d) + + + +`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDay-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDay-test.tsx.snap new file mode 100644 index 00000000000..7fccb036da2 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDay-test.tsx.snap @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + + + +`; + +exports[`renders 2`] = ` + +`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskExecutionTime-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskExecutionTime-test.tsx.snap new file mode 100644 index 00000000000..536d0bff76b --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskExecutionTime-test.tsx.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + +`; + +exports[`renders 2`] = ` + + 12s + +`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskId-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskId-test.tsx.snap new file mode 100644 index 00000000000..0fe227570dc --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskId-test.tsx.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + +
+ 173 +
+ +`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskStatus-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskStatus-test.tsx.snap new file mode 100644 index 00000000000..02e803cd510 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskStatus-test.tsx.snap @@ -0,0 +1,55 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + + + +`; + +exports[`renders 2`] = ` + + + +`; + +exports[`renders 3`] = ` + + + background_task.status.SUCCESS + + +`; + +exports[`renders 4`] = ` + + + background_task.status.FAILED + + +`; + +exports[`renders 5`] = ` + + + background_task.status.CANCELED + + +`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskType-test.js.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskType-test.js.snap deleted file mode 100644 index 92b09f70f85..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskType-test.js.snap +++ /dev/null @@ -1,22 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders 1`] = ` - - [ - background_task.type. - ] - -`; - -exports[`renders 2`] = ` - - [ - background_task.type. - - incremental - ] - -`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskType-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskType-test.tsx.snap new file mode 100644 index 00000000000..649856a4680 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskType-test.tsx.snap @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` + + [ + background_task.type.REPORT + ] + +`; + +exports[`renders 2`] = ` + + [ + background_task.type.REPORT + - incremental + ] + +`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/types.ts b/server/sonar-web/src/main/js/apps/background-tasks/types.ts index c517f201399..b0e1003be03 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/types.ts +++ b/server/sonar-web/src/main/js/apps/background-tasks/types.ts @@ -18,8 +18,19 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export interface ITask { - incremental: boolean; +export interface Task { + componentKey?: string; + componentName?: string; + componentQualifier?: string; + errorMessage?: string; + executedAt?: string; + executionTimeMs?: number; + hasScannerContext?: boolean; + incremental?: boolean; id: string; + organization?: string; + startedAt?: string; + status: string; submittedAt: string; + type: string; }