Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import stripFollowupListFromHtml from './ReportActionFollowupUtils/stripFollowup
import {getOriginalMessage, getReportActionHtml, getReportActionMessage, getReportActionText, getTextFromHtml} from './ReportActionMessageUtils';
import {isActionOfType, isDynamicExternalWorkflowApproveFailedAction, isModifiedExpenseAction, isMoneyRequestAction} from './ReportActionTypeGuards';
import StringUtils from './StringUtils';
import {getAutoReportingOffsetDisplayName, parseAutoReportingOffset} from './SubmissionScheduleUtils';
import {getWorkArrangementLabel} from './WorkArrangementUtils';
import {getUnitTranslationKey, getWorkspaceAddressStreetLines} from './WorkspaceDisplayUtils';
import {getReportFieldTypeTranslationKey} from './WorkspaceReportFieldUtils';
Expand Down Expand Up @@ -4464,18 +4465,8 @@ function getWorkspaceUpdateFieldMessage(translate: LocalizedTranslate, action: R
(typeof oldValue === 'string' || typeof oldValue === 'number') &&
(typeof newValue === 'string' || typeof newValue === 'number')
) {
const getAutoReportingOffsetToDisplay = (autoReportingOffset: string | number) => {
if (autoReportingOffset === CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_DAY_OF_MONTH) {
return translate('workflowsPage.frequencies.lastDayOfMonth');
}
if (autoReportingOffset === CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_BUSINESS_DAY_OF_MONTH) {
return translate('workflowsPage.frequencies.lastBusinessDayOfMonth');
}
if (typeof autoReportingOffset === 'number') {
return toLocaleOrdinal(IntlStore.getCurrentLocale(), autoReportingOffset);
}
return '';
};
const getAutoReportingOffsetToDisplay = (autoReportingOffset: string | number) =>
getAutoReportingOffsetDisplayName(parseAutoReportingOffset(autoReportingOffset), translate, (day) => toLocaleOrdinal(IntlStore.getCurrentLocale(), day));
return translate('workspaceActions.updateMonthlyOffset', getAutoReportingOffsetToDisplay(oldValue), getAutoReportingOffsetToDisplay(newValue));
}
if (updatedField && updatedField === CONST.POLICY.COLLECTION_KEYS.TIME_ZONE && (typeof oldValue === 'string' || typeof oldValue === 'undefined') && typeof newValue === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/SubmissionScheduleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {AutoReportingOffset} from '@src/types/onyx/Policy';
import type {OnyxEntry} from 'react-native-onyx';
import type {TupleToUnion, ValueOf} from 'type-fest';

import {getCorrectedAutoReportingFrequency} from './PolicyUtils';
import {getCorrectedAutoReportingFrequency} from './PolicyUtils/workflows';

type AutoReportingFrequency = ValueOf<typeof CONST.POLICY.AUTO_REPORTING_FREQUENCIES>;

Expand Down
79 changes: 79 additions & 0 deletions tests/unit/ReportActionsUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5241,6 +5241,85 @@ describe('ReportActionsUtils', () => {
});

describe('getWorkspaceUpdateFieldMessage', () => {
describe.each([
[1, '1st'],
[2, '2nd'],
[3, '3rd'],
[21, '21st'],
['1', '1st'],
['15', '15th'],
[CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_DAY_OF_MONTH, 'Last day of the month'],
[CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_BUSINESS_DAY_OF_MONTH, 'Last business day of the month'],
[CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_MONDAY_OF_MONTH, 'Last Monday'],
[CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_TUESDAY_OF_MONTH, 'Last Tuesday'],
[CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_WEDNESDAY_OF_MONTH, 'Last Wednesday'],
[CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_THURSDAY_OF_MONTH, 'Last Thursday'],
[CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_FRIDAY_OF_MONTH, 'Last Friday'],
[CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_SATURDAY_OF_MONTH, 'Last Saturday'],
[CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_SUNDAY_OF_MONTH, 'Last Sunday'],
])('monthly offset %s', (offset, displayName) => {
it('should display the new date instead of the server message', () => {
// Given a valid monthly date change whose server text must not replace the localized message
const action = {
actionName: CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_FIELD,
reportActionID: '1',
created: '',
message: [{type: 'COMMENT', text: 'server message'}],
originalMessage: {
updatedField: CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_OFFSET,
oldValue: 1,
newValue: offset,
},
} as ReportAction;

// When building the admin log message
const result = getWorkspaceUpdateFieldMessage(translateLocal, action);

// Then both dates remain visible, including named weekday offsets
expect(result).toBe(`updated the monthly report submission date to "${displayName}" (previously "1st")`);
});

it('should display the previous date rather than treating it as unset', () => {
// Given a change away from a saved monthly offset
const action = {
actionName: CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_FIELD,
reportActionID: '1',
created: '',
originalMessage: {
updatedField: CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_OFFSET,
oldValue: offset,
newValue: 1,
},
} as ReportAction;

// When building the admin log message
const result = getWorkspaceUpdateFieldMessage(translateLocal, action);

// Then a named previous date keeps the updated wording and is not lost
expect(result).toBe(`updated the monthly report submission date to "1st" (previously "${displayName}")`);
});
});

it('should use set wording when the previous monthly offset is empty', () => {
// Given a workspace without a previous monthly date
const action = {
actionName: CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_FIELD,
reportActionID: '1',
created: '',
originalMessage: {
updatedField: CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_OFFSET,
oldValue: '',
newValue: CONST.POLICY.AUTO_REPORTING_OFFSET.LAST_FRIDAY_OF_MONTH,
},
} as ReportAction;

// When building the admin log message
const result = getWorkspaceUpdateFieldMessage(translateLocal, action);

// Then the new date is translated without inventing a previous date
expect(result).toBe('set the monthly report submission date to "Last Friday"');
});

it('should return the App message when the workspace timezone changes', () => {
// Given a timezone update whose server text would otherwise be shown as is
const action = {
Expand Down
Loading