]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14430 Missing translation keys for background tasks
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Tue, 9 Feb 2021 10:17:42 +0000 (11:17 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 11 Feb 2021 20:07:07 +0000 (20:07 +0000)
server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 1f28a742198dce5d104c9aed89c6e153b0a7fd55..0cb0ebd7579d4649faa9c89c88e4bbde73369ecc 100644 (file)
  */
 import { shallow } from 'enzyme';
 import * as React from 'react';
+import { FormattedMessage } from 'react-intl';
+import { Alert } from 'sonar-ui-common/components/ui/Alert';
+import { hasMessage } from 'sonar-ui-common/helpers/l10n';
 import { mockTask } from '../../../../../helpers/mocks/tasks';
 import { mockComponent, mockLocation } from '../../../../../helpers/testMocks';
-import { TaskStatuses } from '../../../../../types/tasks';
+import { Task, TaskStatuses, TaskTypes } from '../../../../../types/tasks';
 import { ComponentNavBgTaskNotif } from '../ComponentNavBgTaskNotif';
 
 jest.mock('sonar-ui-common/helpers/l10n', () => ({
@@ -29,16 +32,10 @@ jest.mock('sonar-ui-common/helpers/l10n', () => ({
   hasMessage: jest.fn().mockReturnValue(true)
 }));
 
+const UNKNOWN_TASK_TYPE: TaskTypes = 'UNKOWN' as TaskTypes;
+
 it('renders correctly', () => {
   expect(shallowRender()).toMatchSnapshot('default');
-  expect(shallowRender({ isPending: true })).toMatchSnapshot('pending');
-  expect(
-    shallowRender({
-      component: mockComponent({ configuration: { showBackgroundTasks: true } }),
-      isPending: true
-    })
-  ).toMatchSnapshot('pending for admins');
-  expect(shallowRender({ isInProgress: true, isPending: true })).toMatchSnapshot('in progress');
   expect(
     shallowRender({
       currentTask: mockTask({
@@ -48,57 +45,275 @@ it('renders correctly', () => {
       })
     })
   ).toMatchSnapshot('license issue');
-  expect(
-    shallowRender({
-      currentTask: mockTask({ branch: 'my/branch', status: TaskStatuses.Failed }),
-      currentTaskOnSameBranch: false
-    })
-  ).toMatchSnapshot('branch');
-  expect(
-    shallowRender({
-      currentTask: mockTask({ branch: 'my/branch', status: TaskStatuses.Failed }),
-      currentTaskOnSameBranch: false
-    })
-  ).toMatchSnapshot('branch for admins');
-  expect(
-    shallowRender({
-      component: mockComponent({ configuration: { showBackgroundTasks: true } }),
-      currentTask: mockTask({
-        pullRequest: '650',
-        pullRequestTitle: 'feature/my_pr',
-        status: TaskStatuses.Failed
-      }),
-      currentTaskOnSameBranch: false
-    })
-  ).toMatchSnapshot('pull request');
-  expect(
-    shallowRender({
-      component: mockComponent({ configuration: { showBackgroundTasks: true } }),
-      currentTask: mockTask({
-        pullRequest: '650',
-        pullRequestTitle: 'feature/my_pr',
-        status: TaskStatuses.Failed
-      }),
-      currentTaskOnSameBranch: false
-    })
-  ).toMatchSnapshot('pull request for admins');
-  expect(
-    shallowRender({
-      component: mockComponent({ configuration: { showBackgroundTasks: true } }),
-      location: mockLocation({ pathname: '/project/background_tasks' })
-    })
-  ).toMatchSnapshot('on background task page');
-  expect(
-    shallowRender({
-      component: mockComponent({ configuration: { showBackgroundTasks: true } }),
-      currentTask: mockTask({ branch: 'my/branch', status: TaskStatuses.Failed }),
-      currentTaskOnSameBranch: false,
-      location: mockLocation({ pathname: '/project/background_tasks' })
-    })
-  ).toMatchSnapshot('on background task page for branch');
-  expect(shallowRender({ currentTask: undefined })).toMatchSnapshot('no current task');
+  expect(shallowRender({ currentTask: undefined }).type()).toBeNull(); // No task.
 });
 
+it.each([
+  // failed
+  [
+    'component_navigation.status.failed',
+    'error',
+    mockTask({ status: TaskStatuses.Failed, type: UNKNOWN_TASK_TYPE }),
+    false,
+    false,
+    false,
+    false
+  ],
+  [
+    'component_navigation.status.failed_X',
+    'error',
+    mockTask({ status: TaskStatuses.Failed }),
+    false,
+    false,
+    false,
+    false
+  ],
+  [
+    'component_navigation.status.failed.admin.link',
+    'error',
+    mockTask({ status: TaskStatuses.Failed, type: UNKNOWN_TASK_TYPE }),
+    false,
+    false,
+    true,
+    false
+  ],
+  [
+    'component_navigation.status.failed_X.admin.link',
+    'error',
+    mockTask({ status: TaskStatuses.Failed }),
+    false,
+    false,
+    true,
+    false
+  ],
+  [
+    'component_navigation.status.failed.admin.help',
+    'error',
+    mockTask({ status: TaskStatuses.Failed, type: UNKNOWN_TASK_TYPE }),
+    false,
+    false,
+    true,
+    true
+  ],
+  [
+    'component_navigation.status.failed_X.admin.help',
+    'error',
+    mockTask({ status: TaskStatuses.Failed }),
+    false,
+    false,
+    true,
+    true
+  ],
+  // failed_branch
+  [
+    'component_navigation.status.failed_branch',
+    'error',
+    mockTask({ status: TaskStatuses.Failed, branch: 'foo', type: UNKNOWN_TASK_TYPE }),
+    false,
+    false,
+    false,
+    false
+  ],
+  [
+    'component_navigation.status.failed_branch_X',
+    'error',
+    mockTask({ status: TaskStatuses.Failed, branch: 'foo' }),
+    false,
+    false,
+    false,
+    false
+  ],
+  [
+    'component_navigation.status.failed_branch.admin.link',
+    'error',
+    mockTask({ status: TaskStatuses.Failed, branch: 'foo', type: UNKNOWN_TASK_TYPE }),
+    false,
+    false,
+    true,
+    false
+  ],
+  [
+    'component_navigation.status.failed_branch_X.admin.link',
+    'error',
+    mockTask({ status: TaskStatuses.Failed, branch: 'foo' }),
+    false,
+    false,
+    true,
+    false
+  ],
+  [
+    'component_navigation.status.failed_branch.admin.help',
+    'error',
+    mockTask({ status: TaskStatuses.Failed, branch: 'foo', type: UNKNOWN_TASK_TYPE }),
+    false,
+    false,
+    true,
+    true
+  ],
+  [
+    'component_navigation.status.failed_branch_X.admin.help',
+    'error',
+    mockTask({ status: TaskStatuses.Failed, branch: 'foo' }),
+    false,
+    false,
+    true,
+    true
+  ],
+  // pending
+  [
+    'component_navigation.status.pending',
+    'info',
+    mockTask({ type: UNKNOWN_TASK_TYPE }),
+    true,
+    false,
+    false,
+    false
+  ],
+  ['component_navigation.status.pending_X', 'info', mockTask(), true, false, false, false],
+  [
+    'component_navigation.status.pending.admin.link',
+    'info',
+    mockTask({ type: UNKNOWN_TASK_TYPE }),
+    true,
+    false,
+    true,
+    false
+  ],
+  [
+    'component_navigation.status.pending_X.admin.link',
+    'info',
+    mockTask(),
+    true,
+    false,
+    true,
+    false
+  ],
+  [
+    'component_navigation.status.pending.admin.help',
+    'info',
+    mockTask({ type: UNKNOWN_TASK_TYPE }),
+    true,
+    false,
+    true,
+    true
+  ],
+  [
+    'component_navigation.status.pending_X.admin.help',
+    'info',
+    mockTask({ status: TaskStatuses.Failed }),
+    true,
+    false,
+    true,
+    true
+  ],
+  // in_progress
+  [
+    'component_navigation.status.in_progress',
+    'info',
+    mockTask({ type: UNKNOWN_TASK_TYPE }),
+    true,
+    true,
+    false,
+    false
+  ],
+  ['component_navigation.status.in_progress_X', 'info', mockTask(), true, true, false, false],
+  [
+    'component_navigation.status.in_progress.admin.link',
+    'info',
+    mockTask({ type: UNKNOWN_TASK_TYPE }),
+    true,
+    true,
+    true,
+    false
+  ],
+  [
+    'component_navigation.status.in_progress_X.admin.link',
+    'info',
+    mockTask(),
+    true,
+    true,
+    true,
+    false
+  ],
+  [
+    'component_navigation.status.in_progress.admin.help',
+    'info',
+    mockTask({ type: UNKNOWN_TASK_TYPE }),
+    true,
+    true,
+    true,
+    true
+  ],
+  [
+    'component_navigation.status.in_progress_X.admin.help',
+    'info',
+    mockTask({ status: TaskStatuses.Failed }),
+    true,
+    true,
+    true,
+    true
+  ]
+])(
+  'should render the expected message=%p',
+  (
+    expectedMessage: string,
+    alertVariant: string,
+    currentTask: Task,
+    isPending: boolean,
+    isInProgress: boolean,
+    showBackgroundTasks: boolean,
+    onBackgroudTaskPage: boolean
+  ) => {
+    if (currentTask.type === UNKNOWN_TASK_TYPE) {
+      (hasMessage as jest.Mock).mockReturnValueOnce(false);
+    }
+
+    const wrapper = shallowRender({
+      component: mockComponent({ configuration: { showBackgroundTasks } }),
+      currentTask,
+      currentTaskOnSameBranch: !currentTask.branch,
+      isPending,
+      isInProgress,
+      location: mockLocation({
+        pathname: onBackgroudTaskPage ? '/project/background_tasks' : '/foo/bar'
+      })
+    });
+    const messageProps = wrapper.find(FormattedMessage).props();
+
+    // Translation key.
+    expect(messageProps.defaultMessage).toBe(expectedMessage);
+
+    // Alert variant.
+    expect(wrapper.find(Alert).props().variant).toBe(alertVariant);
+
+    // Formatted message values prop.
+    if (/_X/.test(expectedMessage)) {
+      expect(messageProps.values?.type).toBe(`background_task.type.${currentTask.type}`);
+    } else {
+      expect(messageProps.values?.type).toBeUndefined();
+    }
+
+    if (currentTask.branch) {
+      expect(messageProps.values?.branch).toBe(currentTask.branch);
+    } else {
+      expect(messageProps.values?.branch).toBeUndefined();
+    }
+
+    if (showBackgroundTasks) {
+      if (onBackgroudTaskPage) {
+        expect(messageProps.values?.url).toBeUndefined();
+        expect(messageProps.values?.stacktrace).toBe('background_tasks.show_stacktrace');
+      } else {
+        expect(messageProps.values?.url).toBeDefined();
+        expect(messageProps.values?.stacktrace).toBeUndefined();
+      }
+    } else {
+      expect(messageProps.values?.url).toBeUndefined();
+      expect(messageProps.values?.stacktrace).toBeUndefined();
+    }
+  }
+);
+
 function shallowRender(props: Partial<ComponentNavBgTaskNotif['props']> = {}) {
   return shallow<ComponentNavBgTaskNotif>(
     <ComponentNavBgTaskNotif
index 695a64c9c4ec9b8ce06b20820c89885ead477a64..b5664b36ac51ada0a834e382f27ebc9f4dcaa069 100644 (file)
@@ -1,45 +1,5 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`renders correctly: branch 1`] = `
-<Alert
-  display="banner"
-  variant="error"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.failed_branch_X"
-    id="component_navigation.status.failed_branch_X"
-    values={
-      Object {
-        "branch": "my/branch",
-        "stacktrace": undefined,
-        "type": "background_task.type.REPORT",
-        "url": undefined,
-      }
-    }
-  />
-</Alert>
-`;
-
-exports[`renders correctly: branch for admins 1`] = `
-<Alert
-  display="banner"
-  variant="error"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.failed_branch_X"
-    id="component_navigation.status.failed_branch_X"
-    values={
-      Object {
-        "branch": "my/branch",
-        "stacktrace": undefined,
-        "type": "background_task.type.REPORT",
-        "url": undefined,
-      }
-    }
-  />
-</Alert>
-`;
-
 exports[`renders correctly: default 1`] = `
 <Alert
   display="banner"
@@ -60,26 +20,6 @@ exports[`renders correctly: default 1`] = `
 </Alert>
 `;
 
-exports[`renders correctly: in progress 1`] = `
-<Alert
-  display="banner"
-  variant="info"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.in_progress_X"
-    id="component_navigation.status.in_progress_X"
-    values={
-      Object {
-        "branch": undefined,
-        "stacktrace": undefined,
-        "type": "background_task.type.REPORT",
-        "url": undefined,
-      }
-    }
-  />
-</Alert>
-`;
-
 exports[`renders correctly: license issue 1`] = `
 <Connect(withAppState(ComponentNavLicenseNotif))
   currentTask={
@@ -98,167 +38,3 @@ exports[`renders correctly: license issue 1`] = `
   }
 />
 `;
-
-exports[`renders correctly: no current task 1`] = `""`;
-
-exports[`renders correctly: on background task page 1`] = `
-<Alert
-  display="banner"
-  variant="error"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.failed_X.admin.help"
-    id="component_navigation.status.failed_X.admin.help"
-    values={
-      Object {
-        "branch": undefined,
-        "stacktrace": "background_tasks.show_stacktrace",
-        "type": "background_task.type.REPORT",
-        "url": undefined,
-      }
-    }
-  />
-</Alert>
-`;
-
-exports[`renders correctly: on background task page for branch 1`] = `
-<Alert
-  display="banner"
-  variant="error"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.failed_branch_X.admin.help"
-    id="component_navigation.status.failed_branch_X.admin.help"
-    values={
-      Object {
-        "branch": "my/branch",
-        "stacktrace": "background_tasks.show_stacktrace",
-        "type": "background_task.type.REPORT",
-        "url": undefined,
-      }
-    }
-  />
-</Alert>
-`;
-
-exports[`renders correctly: pending 1`] = `
-<Alert
-  display="banner"
-  variant="info"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.pending_X"
-    id="component_navigation.status.pending_X"
-    values={
-      Object {
-        "branch": undefined,
-        "stacktrace": undefined,
-        "type": "background_task.type.REPORT",
-        "url": undefined,
-      }
-    }
-  />
-</Alert>
-`;
-
-exports[`renders correctly: pending for admins 1`] = `
-<Alert
-  display="banner"
-  variant="info"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.pending_X.admin.link"
-    id="component_navigation.status.pending_X.admin.link"
-    values={
-      Object {
-        "branch": undefined,
-        "stacktrace": undefined,
-        "type": "background_task.type.REPORT",
-        "url": <Link
-          onlyActiveOnIndex={false}
-          style={Object {}}
-          to={
-            Object {
-              "pathname": "/project/background_tasks",
-              "query": Object {
-                "id": "my-project",
-                "status": "__ALL__",
-              },
-            }
-          }
-        >
-          background_tasks.page
-        </Link>,
-      }
-    }
-  />
-</Alert>
-`;
-
-exports[`renders correctly: pull request 1`] = `
-<Alert
-  display="banner"
-  variant="error"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.failed_branch_X.admin.link"
-    id="component_navigation.status.failed_branch_X.admin.link"
-    values={
-      Object {
-        "branch": "650 - feature/my_pr",
-        "stacktrace": undefined,
-        "type": "background_task.type.REPORT",
-        "url": <Link
-          onlyActiveOnIndex={false}
-          style={Object {}}
-          to={
-            Object {
-              "pathname": "/project/background_tasks",
-              "query": Object {
-                "id": "my-project",
-                "status": undefined,
-              },
-            }
-          }
-        >
-          background_tasks.page
-        </Link>,
-      }
-    }
-  />
-</Alert>
-`;
-
-exports[`renders correctly: pull request for admins 1`] = `
-<Alert
-  display="banner"
-  variant="error"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.failed_branch_X.admin.link"
-    id="component_navigation.status.failed_branch_X.admin.link"
-    values={
-      Object {
-        "branch": "650 - feature/my_pr",
-        "stacktrace": undefined,
-        "type": "background_task.type.REPORT",
-        "url": <Link
-          onlyActiveOnIndex={false}
-          style={Object {}}
-          to={
-            Object {
-              "pathname": "/project/background_tasks",
-              "query": Object {
-                "id": "my-project",
-                "status": undefined,
-              },
-            }
-          }
-        >
-          background_tasks.page
-        </Link>,
-      }
-    }
-  />
-</Alert>
-`;
index 52f8c5a608b3618bbed195fec99fb0af81629db2..c9c6710aa715837aa842017b91e8b2e70c8d558c 100644 (file)
@@ -2742,12 +2742,16 @@ component_navigation.status.failed_branch.admin.help==The last analysis on this
 component_navigation.status.failed_branch_X.admin.help=The last {type} on this project ({branch}) failed. You can find more details below by clicking on the cog menu, and then "{stacktrace}".
 component_navigation.status.pending=There is a pending background task.
 component_navigation.status.pending_X=There is a pending {type}.
-component_navigation.status.pending.admin=There is a pending background task. More details available on the {url} page.
-component_navigation.status.pending_X.admin=There is a pending {type}. More details available on the {url} page.
+component_navigation.status.pending.admin.link=There is a pending background task. More details available on the {url} page.
+component_navigation.status.pending_X.admin.link=There is a pending {type}. More details available on the {url} page.
+component_navigation.status.pending.admin.help=There is a pending background task.
+component_navigation.status.pending_X.admin.help=There is a pending {type}.
 component_navigation.status.in_progress=A background task is in progress.
 component_navigation.status.in_progress_X=The {type} is in progress.
-component_navigation.status.in_progress.admin=A background task is in progress. More details available on the {url} page.
-component_navigation.status.in_progress_X.admin=The {type} is in progress. More details available on the {url} page.
+component_navigation.status.in_progress.admin.link=A background task is in progress. More details available on the {url} page.
+component_navigation.status.in_progress_X.admin.link=The {type} is in progress. More details available on the {url} page.
+component_navigation.status.in_progress.admin.help=A background task is in progress.
+component_navigation.status.in_progress_X.admin.help=The {type} is in progress.
 component_navigation.status.last_blocked_due_to_bad_license_X=Last analysis blocked due to an invalid license, which has since been corrected. Please reanalyze this {0}.
 
 component_navigation.last_analysis_had_warnings=Last analysis had {warnings}