Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format numerical stats with commas #2405

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions src/components/Stats/__tests__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ const mockedUseDataStore = useDataStore as jest.MockedFunction<typeof useDataSto
const mockedUseUserStore = useUserStore as jest.MockedFunction<typeof useUserStore>

const mockStats = {
audio_count: '1,000',
contributors_count: '500',
daily_count: '200',
episodes_count: '2,000',
node_sount: '5,000',
twitter_spaceCount: '300',
video_count: '800',
documents_count: '1,483',
audio_count: 1000,
contributors_count: 500,
daily_count: 200,
episodes_count: 2000,
node_sount: 5000,
twitter_spaceCount: 300,
video_count: 800,
documents_count: 1483,
}

const mockBudget = 20000
Expand Down Expand Up @@ -78,12 +78,9 @@ describe('Component Test Stats', () => {

const { getByText } = render(<Stats />)

expect(getByText(mockStats.audio_count)).toBeInTheDocument()
expect(getByText(mockStats.contributors_count)).toBeInTheDocument()
expect(getByText(mockStats.daily_count)).toBeInTheDocument()
expect(getByText(mockStats.documents_count)).toBeInTheDocument()
expect(getByText(mockStats.episodes_count)).toBeInTheDocument()
expect(getByText(mockStats.video_count)).toBeInTheDocument()
Object.values(mockStats).forEach((value) => {
expect(getByText(formatStats.formatNumberWithCommas(value))).toBeInTheDocument()
})
})

it('test formatting of numbers', () => {
Expand Down Expand Up @@ -121,11 +118,9 @@ describe('Component Test Stats', () => {

const { getByText, getByTestId } = render(<Stats />)

expect(getByText(mockStats.node_sount)).toBeInTheDocument()
expect(getByText(mockStats.audio_count)).toBeInTheDocument()
expect(getByText(mockStats.episodes_count)).toBeInTheDocument()
expect(getByText(mockStats.video_count)).toBeInTheDocument()
expect(getByText(mockStats.twitter_spaceCount)).toBeInTheDocument()
Object.values(mockStats).forEach((value) => {
expect(getByText(formatStats.formatNumberWithCommas(value))).toBeInTheDocument()
})

expect(getByTestId('Audio')).toBeInTheDocument()
expect(getByTestId('Episodes')).toBeInTheDocument()
Expand Down
8 changes: 4 additions & 4 deletions src/components/Stats/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { noop } from 'lodash'
import { useEffect, useState } from 'react'
import styled from 'styled-components'
import { Icons } from '~/components/Icons'
import BudgetIcon from '~/components/Icons/BudgetIcon'
import NodesIcon from '~/components/Icons/NodesIcon'
import { Tooltip } from '~/components/common/ToolTip'
import { getStats, getTotalProcessing } from '~/network/fetchSourcesData'
import { useDataStore } from '~/stores/useDataStore'
import { useUpdateSelectedNode } from '~/stores/useGraphStore'
import { useModal } from '~/stores/useModalStore'
import { useSchemaStore } from '~/stores/useSchemaStore'
import { useUserStore } from '~/stores/useUserStore'
import { TStats } from '~/types'
import { formatBudget, formatStatsResponse } from '~/utils'
import { formatBudget, formatNumberWithCommas, formatStatsResponse } from '~/utils'
import { colors } from '~/utils/colors'
import { Flex } from '../common/Flex'
import { Animation } from './Animation'
import { Icons } from '~/components/Icons'
import { useSchemaStore } from '~/stores/useSchemaStore'

export const Stats = () => {
const [isTotalProcessing, setIsTotalProcessing] = useState(false)
Expand Down Expand Up @@ -119,7 +119,7 @@ export const Stats = () => {
<div className="icon">
<Icon />
</div>
<div className="text">{stats[key as keyof TStats]}</div>
<div className="text">{formatNumberWithCommas(stats[key as keyof TStats] ?? 0)}</div>
</Tooltip>
</Stat>
) : (
Expand Down
Loading