Skip to content

Commit d0c7f5e

Browse files
committed
Added tests for constructNewContents module
1 parent 85dadbe commit d0c7f5e

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/utils/constructNewContents.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ export const constructNewContents = (
2424

2525
for (const [category, category_info] of categories_map) {
2626
const content = [
27-
`<h3><img height="20px" src="https://img.shields.io/badge/${category}-${
28-
ColorMap[category_info.color]
29-
}"/></h3>`
27+
`<h3><img height="20px" src="https://img.shields.io/badge/${qs.escape(
28+
category
29+
)}-${ColorMap[category_info.color]}"/></h3>`
3030
];
3131
category_info.items.forEach((item) =>
3232
content.push(
3333
`<span><img src="https://img.shields.io/badge/-${qs.escape(
3434
item.title[0][0]
3535
)}-${
36-
item[color_schema_unit_key][0][0]
36+
item[color_schema_unit_key]?.[0][0] ?? 'black'
3737
}?style=flat-square&amp;logo=${qs.escape(item.title[0][0])}" alt="${
3838
item.title[0][0]
3939
}"/></span>`
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { constructNewContents } from '../../src/utils/constructNewContents';
2+
3+
it('Should Work', () => {
4+
const categories_map = new Map([
5+
[
6+
'Tech Tools',
7+
{
8+
items: [
9+
{
10+
title: [['React']],
11+
color: [['blue']]
12+
},
13+
{
14+
title: [['Apollo Graphql']]
15+
}
16+
],
17+
color: 'teal'
18+
}
19+
]
20+
]) as any;
21+
22+
const new_contents = constructNewContents(categories_map, 'color');
23+
expect(new_contents).toStrictEqual([
24+
'<h3><img height="20px" src="https://img.shields.io/badge/Tech%20Tools-467870"/></h3>',
25+
'<span><img src="https://img.shields.io/badge/-React-blue?style=flat-square&amp;logo=React" alt="React"/></span>',
26+
'<span><img src="https://img.shields.io/badge/-Apollo%20Graphql-black?style=flat-square&amp;logo=Apollo%20Graphql" alt="Apollo Graphql"/></span>',
27+
'<hr>'
28+
]);
29+
});

0 commit comments

Comments
 (0)