Skip to content

Commit afc0d7b

Browse files
committed
add unit tests for getTagList and getTagListByOrderWeight
1 parent 0e378f9 commit afc0d7b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/unit/PolicyUtilsTest.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
getPolicyNameByID,
99
getRateDisplayValue,
1010
getSubmitToAccountID,
11+
getTagList,
12+
getTagListByOrderWeight,
1113
getUnitRateValue,
1214
isUserInvitedToWorkspace,
1315
shouldShowPolicy,
@@ -172,6 +174,20 @@ const rules = {
172174
},
173175
],
174176
};
177+
const policyTags = {
178+
TagListTest0: {
179+
name: 'TagListTest0',
180+
orderWeight: 0,
181+
required: false,
182+
tags: {},
183+
},
184+
TagListTest2: {
185+
name: 'TagListTest2',
186+
orderWeight: 2,
187+
required: false,
188+
tags: {},
189+
},
190+
};
175191

176192
describe('PolicyUtils', () => {
177193
describe('getActivePolicies', () => {
@@ -818,4 +834,24 @@ describe('PolicyUtils', () => {
818834
expect(result).toBeTruthy();
819835
});
820836
});
837+
describe('getTagList', () => {
838+
it.each([
839+
['when index is 0', 0, policyTags.TagListTest0.name],
840+
['when index is 1', 1, policyTags.TagListTest2.name],
841+
['when index is out of range', 2, ''],
842+
])('%s', (_description, index, expected) => {
843+
const tagList = getTagList(policyTags, index);
844+
expect(tagList.name).toEqual(expected);
845+
});
846+
});
847+
describe('getTagListByOrderWeight', () => {
848+
it.each([
849+
['when orderWeight is 0', 0, policyTags.TagListTest0.name],
850+
['when orderWeight is 2', 2, policyTags.TagListTest2.name],
851+
['when orderWeight is out of range', 1, ''],
852+
])('%s', (_description, index, expected) => {
853+
const tagList = getTagListByOrderWeight(policyTags, index);
854+
expect(tagList.name).toEqual(expected);
855+
});
856+
});
821857
});

0 commit comments

Comments
 (0)