aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2017-09-21 10:37:47 +0200
committerEric Hartmann <hartmann.eric@gmail.Com>2017-10-02 13:03:35 +0200
commit929c3d426c51982272dabf5b3e6472b4a155eb60 (patch)
tree2f8c01ac01c6f6fc13455ef3c33549d5caec97df /server/sonar-web/src/main/js/apps
parent71030c3e284c9ae264cd5e3b697c2e29060e9731 (diff)
downloadsonarqube-929c3d426c51982272dabf5b3e6472b4a155eb60.tar.gz
sonarqube-929c3d426c51982272dabf5b3e6472b4a155eb60.zip
SONAR-7024 show project specific dispatcher labels
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
-rw-r--r--server/sonar-web/src/main/js/apps/account/notifications/NotificationsList.js14
-rw-r--r--server/sonar-web/src/main/js/apps/account/notifications/ProjectNotifications.js1
-rw-r--r--server/sonar-web/src/main/js/apps/account/notifications/__tests__/NotificationsList-test.js31
-rw-r--r--server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/NotificationsList-test.js.snap55
-rw-r--r--server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/ProjectNotifications-test.js.snap1
5 files changed, 100 insertions, 2 deletions
diff --git a/server/sonar-web/src/main/js/apps/account/notifications/NotificationsList.js b/server/sonar-web/src/main/js/apps/account/notifications/NotificationsList.js
index 2c90aee9251..af7a219e350 100644
--- a/server/sonar-web/src/main/js/apps/account/notifications/NotificationsList.js
+++ b/server/sonar-web/src/main/js/apps/account/notifications/NotificationsList.js
@@ -19,7 +19,7 @@
*/
import React from 'react';
import Checkbox from '../../../components/controls/Checkbox';
-import { translate } from '../../../helpers/l10n';
+import { translate, hasMessage } from '../../../helpers/l10n';
/*:: import type {
Notification,
NotificationsState,
@@ -33,6 +33,7 @@ export default class NotificationsList extends React.PureComponent {
onRemove: (n: Notification) => void,
channels: ChannelsState,
checkboxId: (string, string) => string,
+ project?: boolean,
types: TypesState,
notifications: NotificationsState
};
@@ -52,6 +53,15 @@ export default class NotificationsList extends React.PureComponent {
}
}
+ getDispatcherLabel(dispatcher /*: string */) {
+ const globalMessageKey = ['notification.dispatcher', dispatcher];
+ const projectMessageKey = [...globalMessageKey, 'project'];
+ const shouldUseProjectMessage = this.props.project && hasMessage(...projectMessageKey);
+ return shouldUseProjectMessage
+ ? translate(...projectMessageKey)
+ : translate(...globalMessageKey);
+ }
+
render() {
const { channels, checkboxId, types } = this.props;
@@ -59,7 +69,7 @@ export default class NotificationsList extends React.PureComponent {
<tbody>
{types.map(type => (
<tr key={type}>
- <td>{translate('notification.dispatcher', type)}</td>
+ <td>{this.getDispatcherLabel(type)}</td>
{channels.map(channel => (
<td key={channel} className="text-center">
<Checkbox
diff --git a/server/sonar-web/src/main/js/apps/account/notifications/ProjectNotifications.js b/server/sonar-web/src/main/js/apps/account/notifications/ProjectNotifications.js
index 750440be1f1..481f754b10b 100644
--- a/server/sonar-web/src/main/js/apps/account/notifications/ProjectNotifications.js
+++ b/server/sonar-web/src/main/js/apps/account/notifications/ProjectNotifications.js
@@ -99,6 +99,7 @@ class ProjectNotifications extends React.PureComponent {
checkboxId={(d, c) => `project-notification-${project.key}-${d}-${c}`}
onAdd={n => this.handleAddNotification(n)}
onRemove={n => this.handleRemoveNotification(n)}
+ project={true}
/>
</table>
);
diff --git a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/NotificationsList-test.js b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/NotificationsList-test.js
index 6ad339b88eb..19ad4fa3f53 100644
--- a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/NotificationsList-test.js
+++ b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/NotificationsList-test.js
@@ -17,10 +17,18 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+/* eslint-disable import/first */
+jest.mock('../../../../helpers/l10n', () => {
+ const l10n = require.requireActual('../../../../helpers/l10n');
+ l10n.hasMessage = jest.fn();
+ return l10n;
+});
+
import React from 'react';
import { shallow } from 'enzyme';
import NotificationsList from '../NotificationsList';
import Checkbox from '../../../../components/controls/Checkbox';
+import { hasMessage } from '../../../../helpers/l10n';
const channels = ['channel1', 'channel2'];
const types = ['type1', 'type2'];
@@ -31,6 +39,10 @@ const notifications = [
];
const checkboxId = (t, c) => `checkbox-io-${t}-${c}`;
+beforeEach(() => {
+ hasMessage.mockImplementation(() => false).mockClear();
+});
+
it('should match snapshot', () => {
expect(
shallow(
@@ -46,6 +58,25 @@ it('should match snapshot', () => {
).toMatchSnapshot();
});
+it('renders project-specific labels', () => {
+ hasMessage.mockImplementation(() => true);
+ expect(
+ shallow(
+ <NotificationsList
+ onAdd={jest.fn()}
+ onRemove={jest.fn()}
+ channels={channels}
+ checkboxId={checkboxId}
+ project={true}
+ types={types}
+ notifications={notifications}
+ />
+ )
+ ).toMatchSnapshot();
+ expect(hasMessage).toBeCalledWith('notification.dispatcher', 'type1', 'project');
+ expect(hasMessage).toBeCalledWith('notification.dispatcher', 'type2', 'project');
+});
+
it('should call `onAdd` and `onRemove`', () => {
const onAdd = jest.fn();
const onRemove = jest.fn();
diff --git a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/NotificationsList-test.js.snap b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/NotificationsList-test.js.snap
index 8035cb42916..3ca417ef0a0 100644
--- a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/NotificationsList-test.js.snap
+++ b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/NotificationsList-test.js.snap
@@ -1,5 +1,60 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`renders project-specific labels 1`] = `
+<tbody>
+ <tr>
+ <td>
+ notification.dispatcher.type1.project
+ </td>
+ <td
+ className="text-center"
+ >
+ <Checkbox
+ checked={true}
+ id="checkbox-io-type1-channel1"
+ onCheck={[Function]}
+ thirdState={false}
+ />
+ </td>
+ <td
+ className="text-center"
+ >
+ <Checkbox
+ checked={false}
+ id="checkbox-io-type1-channel2"
+ onCheck={[Function]}
+ thirdState={false}
+ />
+ </td>
+ </tr>
+ <tr>
+ <td>
+ notification.dispatcher.type2.project
+ </td>
+ <td
+ className="text-center"
+ >
+ <Checkbox
+ checked={true}
+ id="checkbox-io-type2-channel1"
+ onCheck={[Function]}
+ thirdState={false}
+ />
+ </td>
+ <td
+ className="text-center"
+ >
+ <Checkbox
+ checked={true}
+ id="checkbox-io-type2-channel2"
+ onCheck={[Function]}
+ thirdState={false}
+ />
+ </td>
+ </tr>
+</tbody>
+`;
+
exports[`should match snapshot 1`] = `
<tbody>
<tr>
diff --git a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/ProjectNotifications-test.js.snap b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/ProjectNotifications-test.js.snap
index d7a5a2f3e76..3a5f1bb6f42 100644
--- a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/ProjectNotifications-test.js.snap
+++ b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/ProjectNotifications-test.js.snap
@@ -74,6 +74,7 @@ exports[`should match snapshot 1`] = `
}
onAdd={[Function]}
onRemove={[Function]}
+ project={true}
types={
Array [
"type1",