Commit b970f662 authored by tom's avatar tom

fix issue with zero values in gas tracker

parent 5ddd4557
import { test, expect } from '@playwright/experimental-ct-react';
import React from 'react'; import React from 'react';
import * as statsMock from 'mocks/stats/index'; import * as statsMock from 'mocks/stats/index';
import contextWithEnvs from 'playwright/fixtures/contextWithEnvs'; import { test, expect } from 'playwright/lib';
import TestApp from 'playwright/TestApp';
import * as configs from 'playwright/utils/configs'; import * as configs from 'playwright/utils/configs';
import GasTrackerPriceSnippet from './GasTrackerPriceSnippet'; import GasTrackerPriceSnippet from './GasTrackerPriceSnippet';
...@@ -13,48 +11,57 @@ test.use({ viewport: configs.viewport.md }); ...@@ -13,48 +11,57 @@ test.use({ viewport: configs.viewport.md });
const data = statsMock.base.gas_prices.fast; const data = statsMock.base.gas_prices.fast;
const clip = { x: 0, y: 0, width: 334, height: 204 }; const clip = { x: 0, y: 0, width: 334, height: 204 };
test('with usd as primary unit +@dark-mode', async({ mount, page }) => { test('with usd as primary unit +@dark-mode', async({ render, page }) => {
await mount( await render(
<TestApp>
<GasTrackerPriceSnippet <GasTrackerPriceSnippet
data={ data } data={ data }
type="fast" type="fast"
isLoading={ false } isLoading={ false }
/> />,
</TestApp>,
); );
await expect(page).toHaveScreenshot({ clip }); await expect(page).toHaveScreenshot({ clip });
}); });
test('loading state', async({ mount, page }) => { test('loading state', async({ render, page }) => {
await mount( await render(
<TestApp>
<GasTrackerPriceSnippet <GasTrackerPriceSnippet
data={ data } data={ data }
type="fast" type="fast"
isLoading={ true } isLoading={ true }
/> />,
</TestApp>,
); );
await expect(page).toHaveScreenshot({ clip }); await expect(page).toHaveScreenshot({ clip });
}); });
const gweiUnitsTest = test.extend({ test('with gwei as primary unit +@dark-mode', async({ render, page, mockEnvs }) => {
context: contextWithEnvs([ await mockEnvs([
{ name: 'NEXT_PUBLIC_GAS_TRACKER_UNITS', value: '["gwei","usd"]' }, [ 'NEXT_PUBLIC_GAS_TRACKER_UNITS', '["gwei","usd"]' ],
// eslint-disable-next-line @typescript-eslint/no-explicit-any ]);
]) as any, await render(
<GasTrackerPriceSnippet
data={ data }
type="slow"
isLoading={ false }
/>,
);
await expect(page).toHaveScreenshot({ clip });
}); });
gweiUnitsTest('with gwei as primary unit +@dark-mode', async({ mount, page }) => { test('with zero values', async({ render, page }) => {
await mount( const data = {
<TestApp> fiat_price: '1.74',
price: 0.0,
time: 0,
base_fee: 0,
priority_fee: 0,
};
await render(
<GasTrackerPriceSnippet <GasTrackerPriceSnippet
data={ data } data={ data }
type="slow" type="slow"
isLoading={ false } isLoading={ false }
/> />,
</TestApp>,
); );
await expect(page).toHaveScreenshot({ clip }); await expect(page).toHaveScreenshot({ clip });
}); });
...@@ -50,14 +50,14 @@ const GasTrackerPriceSnippet = ({ data, type, isLoading }: Props) => { ...@@ -50,14 +50,14 @@ const GasTrackerPriceSnippet = ({ data, type, isLoading }: Props) => {
</Skeleton> </Skeleton>
</Flex> </Flex>
<Skeleton isLoaded={ !isLoading } fontSize="sm" color="text_secondary" mt={ 3 } w="fit-content"> <Skeleton isLoaded={ !isLoading } fontSize="sm" color="text_secondary" mt={ 3 } w="fit-content">
{ data.price && data.fiat_price && <GasPrice data={ data } prefix={ `${ asymp } ` } unitMode="secondary"/> } { data.price !== null && data.fiat_price !== null && <GasPrice data={ data } prefix={ `${ asymp } ` } unitMode="secondary"/> }
<span> per transaction</span> <span> per transaction</span>
{ typeof data.time === 'number' && data.time > 0 && <span> / { (data.time / SECOND).toLocaleString(undefined, { maximumFractionDigits: 1 }) }s</span> } { typeof data.time === 'number' && data.time > 0 && <span> / { (data.time / SECOND).toLocaleString(undefined, { maximumFractionDigits: 1 }) }s</span> }
</Skeleton> </Skeleton>
<Skeleton isLoaded={ !isLoading } fontSize="sm" color="text_secondary" mt={ 2 } w="fit-content" whiteSpace="pre"> <Skeleton isLoaded={ !isLoading } fontSize="sm" color="text_secondary" mt={ 2 } w="fit-content" whiteSpace="pre">
{ data.base_fee && <span>Base { data.base_fee.toLocaleString(undefined, { maximumFractionDigits: 0 }) }</span> } { typeof data.base_fee === 'number' && <span>Base { data.base_fee.toLocaleString(undefined, { maximumFractionDigits: 0 }) }</span> }
{ data.base_fee && data.priority_fee && <span> / </span> } { typeof data.base_fee === 'number' && typeof data.priority_fee === 'number' && <span> / </span> }
{ data.priority_fee && <span>Priority { data.priority_fee.toLocaleString(undefined, { maximumFractionDigits: 0 }) }</span> } { typeof data.priority_fee === 'number' && <span>Priority { data.priority_fee.toLocaleString(undefined, { maximumFractionDigits: 0 }) }</span> }
</Skeleton> </Skeleton>
</Box> </Box>
); );
......
...@@ -36,7 +36,8 @@ const GasTracker = () => { ...@@ -36,7 +36,8 @@ const GasTracker = () => {
rowGap={ 1 } rowGap={ 1 }
flexDir={{ base: 'column', lg: 'row' }} flexDir={{ base: 'column', lg: 'row' }}
> >
{ data?.network_utilization_percentage && <GasTrackerNetworkUtilization percentage={ data.network_utilization_percentage } isLoading={ isLoading }/> } { typeof data?.network_utilization_percentage === 'number' &&
<GasTrackerNetworkUtilization percentage={ data.network_utilization_percentage } isLoading={ isLoading }/> }
{ data?.gas_price_updated_at && ( { data?.gas_price_updated_at && (
<Skeleton isLoaded={ !isLoading } whiteSpace="pre" display="flex" alignItems="center"> <Skeleton isLoaded={ !isLoading } whiteSpace="pre" display="flex" alignItems="center">
<span>Last updated </span> <span>Last updated </span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment