Skip to content

Commit

Permalink
moved extra functions to helpers instead and added test coverage (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevkevinpal authored Dec 22, 2023
1 parent 834cee0 commit c38eee1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
14 changes: 13 additions & 1 deletion frontend/app/src/helpers/__test__/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
spliceOutPubkey,
userHasManageBountyRoles,
RolesCategory,
handleDisplayRole
handleDisplayRole,
formatSat,
filterCount
} from '../helpers-extended';

beforeAll(() => {
Expand Down Expand Up @@ -260,5 +262,15 @@ describe('testing helpers', () => {
role5: true
});
});

test('formatSat', () => {
expect(formatSat(10000)).toBe('10 000');
expect(formatSat(0)).toBe('0');
});
test('filterCount', () => {
expect(filterCount({ thing1: 0, thing2: 1 })).toBe(1);
expect(filterCount({ thing1: 1, thing2: 1 })).toBe(2);
expect(filterCount({})).toBe(0);
});
});
});
19 changes: 19 additions & 0 deletions frontend/app/src/helpers/helpers-extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
import LighningDecoder from 'light-bolt11-decoder';
import { getHost } from '../config/host';

export const filterCount = (filterValues: any) => {
let count = 0;
for (const [, value] of Object.entries(filterValues)) {
if (value) {
count += 1;
}
}
return count;
};

export const formatSat = (sat: number) => {
if (sat === 0 || !sat) {
return '0';
}
const satsWithComma = sat.toLocaleString();
const splittedSat = satsWithComma.split(',');
return splittedSat.join(' ');
};

export const formatPrice = (amount = 0) => amount;

export const formatSatPrice = (amount = 0) => {
Expand Down
18 changes: 0 additions & 18 deletions frontend/app/src/people/utils/ExtraFunctions.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/app/src/people/widgetViews/BountyHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { colors } from '../../config/colors';
import { useIsMobile } from '../../hooks';
import { SearchBar } from '../../components/common/index';
import { useStores } from '../../store';
import { filterCount } from '../utils/ExtraFunctions';
import { filterCount } from '../../helpers';
import { GetValue, coding_languages, status } from '../utils/languageLabelStyle';
import { PostBounty } from './postBounty';

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/people/widgetViews/PeopleHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { useState, useEffect } from 'react';
import { EuiCheckboxGroup, EuiPopover, EuiText } from '@elastic/eui';
import MaterialIcon from '@material/react-material-icon';
import { colors } from 'config';
import { filterCount } from 'people/utils/ExtraFunctions';
import { filterCount } from '../../helpers';
import { GetValue, coding_languages } from '../utils/languageLabelStyle';

interface styledProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import moment from 'moment';
import styled from 'styled-components';
import { PaymentHistory, OrgTransactionType } from 'store/main';
import { useStores } from 'store';
import { formatSat } from 'people/utils/ExtraFunctions';
import { formatSat } from '../../../helpers';
import { Modal } from '../../../components/common';
import { colors } from '../../../config/colors';
import ArrowRight from '../../../public/static/arrow-right.svg';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import styled from 'styled-components';
import { formatSat } from 'people/utils/ExtraFunctions';
import { formatSat } from '../../../helpers';

const Wrapper = styled.div`
display: flex;
Expand Down

0 comments on commit c38eee1

Please sign in to comment.