From 6d48c2810f088ee18b33300f77d981a0165f831b Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 9 Feb 2021 11:17:42 +0100 Subject: [PATCH] SONAR-14430 Missing translation keys for background tasks --- .../ComponentNavBgTaskNotif-test.tsx | 331 +++++++++++++++--- .../ComponentNavBgTaskNotif-test.tsx.snap | 224 ------------ .../resources/org/sonar/l10n/core.properties | 12 +- 3 files changed, 281 insertions(+), 286 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx index 1f28a742198..0cb0ebd7579 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx @@ -19,9 +19,12 @@ */ 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 = {}) { return shallow( - - -`; - -exports[`renders correctly: branch for admins 1`] = ` - - - -`; - exports[`renders correctly: default 1`] = ` `; -exports[`renders correctly: in progress 1`] = ` - - - -`; - exports[`renders correctly: license issue 1`] = ` `; - -exports[`renders correctly: no current task 1`] = `""`; - -exports[`renders correctly: on background task page 1`] = ` - - - -`; - -exports[`renders correctly: on background task page for branch 1`] = ` - - - -`; - -exports[`renders correctly: pending 1`] = ` - - - -`; - -exports[`renders correctly: pending for admins 1`] = ` - - - background_tasks.page - , - } - } - /> - -`; - -exports[`renders correctly: pull request 1`] = ` - - - background_tasks.page - , - } - } - /> - -`; - -exports[`renders correctly: pull request for admins 1`] = ` - - - background_tasks.page - , - } - } - /> - -`; diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 52f8c5a608b..c9c6710aa71 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -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} -- 2.39.5