Skip to content

Commit ee341f0

Browse files
test: add jest tests for prepare cluster links funcs
1 parent 3123f4f commit ee341f0

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {prepareClusterCoresLink, prepareClusterLoggingLinks} from '../useClusterLinks';
2+
3+
describe('prepareClusterCoresLink', () => {
4+
it('It should parse stringified json with cores url', () => {
5+
expect(
6+
prepareClusterCoresLink('{"url":"https://coredumps.com?cluster=my_cluster"}'),
7+
).toEqual('https://coredumps.com?cluster=my_cluster');
8+
});
9+
10+
it('It should return undefined if input is undefined', () => {
11+
expect(prepareClusterCoresLink(undefined)).toEqual(undefined);
12+
});
13+
it('It should return undefined if input is incorrect', () => {
14+
expect(prepareClusterCoresLink('hello')).toEqual(undefined);
15+
});
16+
});
17+
18+
describe('prepareClusterLoggingLinks', () => {
19+
it('It should parse stringified json with logging and slo logs urls', () => {
20+
expect(
21+
prepareClusterLoggingLinks(
22+
'{"url":"https://logging.com/logs?cluster=my_cluster","slo_logs_url":"https://logging.com/slo-logs?cluster=my_cluster"}',
23+
),
24+
).toEqual({
25+
logsUrl: 'https://logging.com/logs?cluster=my_cluster',
26+
sloLogsUrl: 'https://logging.com/slo-logs?cluster=my_cluster',
27+
});
28+
});
29+
it('It should parse stringified json with only logging url', () => {
30+
expect(
31+
prepareClusterLoggingLinks('{"url":"https://logging.com/logs?cluster=my_cluster"}'),
32+
).toEqual({
33+
logsUrl: 'https://logging.com/logs?cluster=my_cluster',
34+
});
35+
});
36+
it('It should parse stringified json with only slo logs url', () => {
37+
expect(
38+
prepareClusterLoggingLinks(
39+
'{"slo_logs_url":"https://logging.com/slo-logs?cluster=my_cluster"}',
40+
),
41+
).toEqual({
42+
sloLogsUrl: 'https://logging.com/slo-logs?cluster=my_cluster',
43+
});
44+
});
45+
it('It should return empty object if input is undefined', () => {
46+
expect(prepareClusterLoggingLinks(undefined)).toEqual({});
47+
});
48+
it('It should return empty object if input is incorrect', () => {
49+
expect(prepareClusterLoggingLinks('hello')).toEqual({});
50+
});
51+
});

src/containers/Cluster/ClusterInfo/utils/useClusterLinks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import i18n from '../../i18n';
88
/**
99
* parses stringified json in format {url: "href"}
1010
*/
11-
function prepareClusterCoresLink(rawCoresString?: string) {
11+
export function prepareClusterCoresLink(rawCoresString?: string) {
1212
try {
1313
const linkObject = parseJson(rawCoresString) as unknown;
1414

@@ -28,7 +28,7 @@ function prepareClusterCoresLink(rawCoresString?: string) {
2828
/**
2929
* parses stringified json in format {url: "href", slo_logs_url: "href"}
3030
*/
31-
function prepareClusterLoggingLinks(rawLoggingString?: string) {
31+
export function prepareClusterLoggingLinks(rawLoggingString?: string) {
3232
try {
3333
const linkObject = parseJson(rawLoggingString) as unknown;
3434

0 commit comments

Comments
 (0)