Skip to content

Commit

Permalink
update solution and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nkdengineer committed Mar 22, 2024
1 parent 8bd0254 commit 84db2f3
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ function getContinuousReportActionChain(sortedReportActions: ReportAction[], id?
if (id) {
index = sortedReportActions.findIndex((obj) => obj.reportActionID === id);
} else {
index = sortedReportActions.findIndex((obj) => obj.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || obj.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED);
index = sortedReportActions.findIndex((obj) => obj.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
}

if (index === -1) {
return [];
return id ? [] : sortedReportActions;
}

let startIndex = index;
Expand Down
122 changes: 117 additions & 5 deletions tests/unit/ReportActionsUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1784,22 +1784,134 @@ describe('ReportActionsUtils', () => {
expect(result).toStrictEqual(expectedResult.reverse());
});

it('give an empty input ID and the report actions only contain created action with pending action is add it will return the created report action', () => {
it('give an empty input ID and the report actions only contain the actions with pending action is add it will return all actions', () => {
const input: ReportAction[] = [
// Given these sortedReportActions
{
reportActionID: '1',
previousReportActionID: undefined,
created: '2022-11-13 22:27:01.825',
actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
originalMessage: {
html: 'Hello world',
whisperedTo: [],
},
message: [
{
html: 'Hello world',
type: 'Action type',
text: 'Action text',
},
],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
{
reportActionID: '2',
previousReportActionID: '1',
created: '2022-11-13 22:27:01.825',
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
originalMessage: {
html: 'Hello world',
whisperedTo: [],
},
message: [
{
style: 'normal',
text: 'created this report',
type: 'text',
html: 'Hello world',
type: 'Action type',
text: 'Action text',
},
],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
{
reportActionID: '3',
previousReportActionID: '2',
created: '2022-11-13 22:27:01.825',
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
originalMessage: {
html: 'Hello world',
whisperedTo: [],
},
message: [
{
html: 'Hello world',
type: 'Action type',
text: 'Action text',
},
],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
{
reportActionID: '4',
previousReportActionID: '3',
created: '2022-11-13 22:27:01.825',
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
originalMessage: {
html: 'Hello world',
whisperedTo: [],
},
message: [
{
html: 'Hello world',
type: 'Action type',
text: 'Action text',
},
],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
{
reportActionID: '5',
previousReportActionID: '4',
created: '2022-11-13 22:27:01.825',
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
originalMessage: {
html: 'Hello world',
whisperedTo: [],
},
message: [
{
html: 'Hello world',
type: 'Action type',
text: 'Action text',
},
],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
{
reportActionID: '6',
previousReportActionID: '5',
created: '2022-11-13 22:27:01.825',
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
originalMessage: {
html: 'Hello world',
whisperedTo: [],
},
message: [
{
html: 'Hello world',
type: 'Action type',
text: 'Action text',
},
],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
{
reportActionID: '7',
previousReportActionID: '6',
created: '2022-11-13 22:27:01.825',
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
originalMessage: {
html: 'Hello world',
whisperedTo: [],
},
message: [
{
html: 'Hello world',
type: 'Action type',
text: 'Action text',
},
],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
];

Expand Down

0 comments on commit 84db2f3

Please sign in to comment.