test: check block height in mocked e2e tests

This commit is contained in:
Matthew Russell
2023-02-25 11:14:12 -08:00
parent b9d0ce6485
commit 0fd6ff6eec
4 changed files with 32 additions and 7 deletions
@@ -304,4 +304,11 @@ describe('home', { tags: '@regression' }, () => {
});
});
});
describe('footer', () => {
it('shows current block height', () => {
cy.visit('/');
cy.getByTestId('app-footer').contains('Operational').contains('100');
});
});
});
+4 -1
View File
@@ -13,7 +13,10 @@ export const Footer = () => {
const { blockDiff, datanodeBlockHeight } = useNodeHealth();
return (
<footer className="px-4 py-1 text-xs border-t border-default text-vega-light-300 dark:text-vega-dark-300">
<footer
data-testid="app-footer"
className="px-4 py-1 text-xs border-t border-default text-vega-light-300 dark:text-vega-dark-300"
>
{/* Pull left to align with top nav, due to button padding */}
<div className="-ml-2">
{VEGA_URL && (
+9 -1
View File
@@ -32,7 +32,8 @@ export const aliasGQLQuery = (
operationName: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: any,
errors?: Partial<GraphQLError>[]
errors?: Partial<GraphQLError>[],
headers?: Record<string, string>
) => {
if (hasOperationName(req, operationName)) {
req.alias = operationName;
@@ -40,6 +41,13 @@ export const aliasGQLQuery = (
req.reply({
statusCode: 200,
body: { ...(data && { data }), ...(errors && { errors }) },
headers: {
...req.headers,
// basic default block height header response
'x-block-height': '100',
'x-block-timestamp': Date.now().toString() + '0'.repeat(6),
...headers,
},
});
}
}
+12 -5
View File
@@ -4,14 +4,16 @@ import { useHeaderStore } from '@vegaprotocol/apollo-client';
import { useEnvironment } from './use-environment';
import { fromNanoSeconds } from '@vegaprotocol/react-helpers';
const POLL_INTERVAL = 1000;
export const useNodeHealth = () => {
const url = useEnvironment((store) => store.VEGA_URL);
const headerStore = useHeaderStore();
const headers = url ? headerStore[url] : undefined;
const { data, error, loading, stopPolling } = useStatisticsQuery({
pollInterval: 1000,
fetchPolicy: 'no-cache',
});
const { data, error, loading, startPolling, stopPolling } =
useStatisticsQuery({
fetchPolicy: 'no-cache',
});
const blockDiff = useMemo(() => {
if (!data?.statistics.blockHeight) {
@@ -28,8 +30,13 @@ export const useNodeHealth = () => {
useEffect(() => {
if (error) {
stopPolling();
return;
}
}, [error, stopPolling]);
if (!('Cypress' in window)) {
startPolling(POLL_INTERVAL);
}
}, [error, startPolling, stopPolling]);
return {
error,