Skip to content

Commit

Permalink
Merge pull request #47687 from daledah/fix/47301
Browse files Browse the repository at this point in the history
fix: unexpected behavior of tag selection
  • Loading branch information
grgia authored Aug 22, 2024
2 parents 4ad8900 + 5f7cb17 commit 19ca2bb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ function insertTagIntoTransactionTagsString(transactionTags: string, tag: string
const tagArray = TransactionUtils.getTagArrayFromName(transactionTags);
tagArray[tagIndex] = tag;

return tagArray
.map((tagItem) => tagItem.trim())
.filter((tagItem) => !!tagItem)
.join(CONST.COLON);
while (tagArray.length > 0 && !tagArray[tagArray.length - 1]) {
tagArray.pop();
}

return tagArray.map((tagItem) => tagItem.trim()).join(CONST.COLON);
}

function isMovingTransactionFromTrackExpense(action?: IOUAction) {
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/IOUUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ describe('IOUUtils', () => {
expect(IOUUtils.calculateAmount(participantsAccountIDs.length, 100, 'BHD')).toBe(33);
});
});

describe('insertTagIntoTransactionTagsString', () => {
test('Inserting a tag into tag string should update the tag', () => {
expect(IOUUtils.insertTagIntoTransactionTagsString(':NY:Texas', 'California', 2)).toBe(':NY:California');
});

test('Inserting a tag into an index with no tags should update the tag', () => {
expect(IOUUtils.insertTagIntoTransactionTagsString('::California', 'NY', 1)).toBe(':NY:California');
});

test('Inserting a tag with colon in name into tag string should keep the colon in tag', () => {
expect(IOUUtils.insertTagIntoTransactionTagsString('East:NY:California', 'City \\: \\:', 1)).toBe('East:City \\: \\::California');
});

test('Remove a tag from tagString', () => {
expect(IOUUtils.insertTagIntoTransactionTagsString('East:City \\: \\::California', '', 1)).toBe('East::California');
});
});
});

describe('isValidMoneyRequestType', () => {
Expand Down

0 comments on commit 19ca2bb

Please sign in to comment.