Skip to content

Commit

Permalink
feat: add tests for humanize (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Mar 17, 2023
1 parent ad8ba73 commit cda9426
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CurrencyDollarIcon } from '@heroicons/react/outline';
import humanize from '@lib/humanize';
import { Trans } from '@lingui/macro';
import type { NewCollectNotification } from 'lens';
import type { FC } from 'react';
import getTokenImage from 'utils/getTokenImage';
import humanize from 'utils/humanize';

interface CollectedAmountProps {
notification: NewCollectNotification;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Profile/Followerings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Modal } from '@components/UI/Modal';
import { UsersIcon } from '@heroicons/react/outline';
import humanize from '@lib/humanize';
import { t, Trans } from '@lingui/macro';
import type { Profile } from 'lens';
import type { FC } from 'react';
import { useState } from 'react';
import humanize from 'utils/humanize';

import Followers from './Followers';
import Following from './Following';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Loader from '@components/Shared/Loader';
import { ErrorMessage } from '@components/UI/ErrorMessage';
import HelpTooltip from '@components/UI/HelpTooltip';
import humanize from '@lib/humanize';
import { t } from '@lingui/macro';
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { ERROR_MESSAGE, SIMPLEANALYTICS_API } from 'data/constants';
import type { Publication } from 'lens';
import type { FC } from 'react';
import humanize from 'utils/humanize';

const Stat: FC<{ title: string; helper: string; stat: number }> = ({ title, helper, stat }) => (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import { CheckCircleIcon } from '@heroicons/react/solid';
import { formatTime } from '@lib/formatTime';
import getCoingeckoPrice from '@lib/getCoingeckoPrice';
import humanize from '@lib/humanize';
import { Mixpanel } from '@lib/mixpanel';
import onError from '@lib/onError';
import splitSignature from '@lib/splitSignature';
Expand Down Expand Up @@ -53,6 +52,7 @@ import formatHandle from 'utils/formatHandle';
import getAssetAddress from 'utils/getAssetAddress';
import getSignature from 'utils/getSignature';
import getTokenImage from 'utils/getTokenImage';
import humanize from 'utils/humanize';
import { useAccount, useBalance, useContractRead, useContractWrite, useSignTypedData } from 'wagmi';

import Splits from './Splits';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import GetModuleIcon from '@components/utils/GetModuleIcon';
import { CollectionIcon } from '@heroicons/react/outline';
import { CollectionIcon as CollectionIconSolid } from '@heroicons/react/solid';
import { getModule } from '@lib/getModule';
import humanize from '@lib/humanize';
import { Mixpanel } from '@lib/mixpanel';
import nFormatter from '@lib/nFormatter';
import { t } from '@lingui/macro';
Expand All @@ -16,6 +15,7 @@ import dynamic from 'next/dynamic';
import type { FC } from 'react';
import { useEffect, useState } from 'react';
import { PUBLICATION } from 'src/tracking';
import humanize from 'utils/humanize';

const CollectModule = dynamic(() => import('./CollectModule'), {
loading: () => <Loader message={t`Loading collect`} />
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Publication/Actions/Comment.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Tooltip } from '@components/UI/Tooltip';
import { ChatAlt2Icon } from '@heroicons/react/outline';
import humanize from '@lib/humanize';
import nFormatter from '@lib/nFormatter';
import { t } from '@lingui/macro';
import { motion } from 'framer-motion';
import type { Publication } from 'lens';
import Link from 'next/link';
import type { FC } from 'react';
import humanize from 'utils/humanize';

interface CommentProps {
publication: Publication;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Publication/Actions/Mirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ApolloCache } from '@apollo/client';
import { Spinner } from '@components/UI/Spinner';
import { Tooltip } from '@components/UI/Tooltip';
import { SwitchHorizontalIcon } from '@heroicons/react/outline';
import humanize from '@lib/humanize';
import { publicationKeyFields } from '@lib/keyFields';
import { Mixpanel } from '@lib/mixpanel';
import nFormatter from '@lib/nFormatter';
Expand All @@ -25,6 +24,7 @@ import toast from 'react-hot-toast';
import { useAppStore } from 'src/store/app';
import { PUBLICATION } from 'src/tracking';
import getSignature from 'utils/getSignature';
import humanize from 'utils/humanize';
import { useContractWrite, useSignTypedData } from 'wagmi';

interface MirrorProps {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/StaffTools/Stats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from '@heroicons/react/outline';
import { PencilAltIcon } from '@heroicons/react/solid';
import { getTimeAddedNDayUnix, getTimeMinusNDayUnix } from '@lib/formatTime';
import humanize from '@lib/humanize';
import { Mixpanel } from '@lib/mixpanel';
import { t } from '@lingui/macro';
import clsx from 'clsx';
Expand All @@ -25,6 +24,7 @@ import type { FC, ReactNode } from 'react';
import { useEffect } from 'react';
import Custom404 from 'src/pages/404';
import { PAGEVIEW } from 'src/tracking';
import humanize from 'utils/humanize';

import StaffToolsSidebar from '../Sidebar';

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/nFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import humanize from './humanize';
import humanize from 'utils/humanize';

/**
*
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions tests/scripts/packages/utils/humanize.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from '@playwright/test';
import humanize from 'utils/humanize';

test.describe('humanize', () => {
test('should return comma-separated thousands', () => {
expect(humanize(0)).toEqual('0');
expect(humanize(10)).toEqual('10');
expect(humanize(100)).toEqual('100');
expect(humanize(1000)).toEqual('1,000');
expect(humanize(10000)).toEqual('10,000');
expect(humanize(100000)).toEqual('100,000');
expect(humanize(1000000)).toEqual('1,000,000');
expect(humanize(123456789)).toEqual('123,456,789');
});
});

3 comments on commit cda9426

@vercel
Copy link

@vercel vercel bot commented on cda9426 Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

prerender – ./apps/prerender

prerender-lenster.vercel.app
prerender.lenster.xyz
prerender-git-main-lenster.vercel.app

@vercel
Copy link

@vercel vercel bot commented on cda9426 Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./apps/web

web-lenster.vercel.app
web-git-main-lenster.vercel.app
lenster.vercel.app
lenster.xyz

@hop-deploy
Copy link

@hop-deploy hop-deploy bot commented on cda9426 Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment Status Build Logs Updated At
lenster ✅ Deployed View Logs 2023-03-17T13:54:23.041Z

Please sign in to comment.