From e65f6b0c099ccf130c2c3793534b9171ff4e78fe Mon Sep 17 00:00:00 2001 From: titix Date: Tue, 3 Sep 2024 17:40:41 -0300 Subject: [PATCH] test: chain page testing --- cypress/e2e/navigation.cy.ts | 14 ++++------ src/pages/[chain]/index.tsx | 51 ++++++++++++------------------------ 2 files changed, 22 insertions(+), 43 deletions(-) diff --git a/cypress/e2e/navigation.cy.ts b/cypress/e2e/navigation.cy.ts index bfc6954..72fe681 100644 --- a/cypress/e2e/navigation.cy.ts +++ b/cypress/e2e/navigation.cy.ts @@ -24,13 +24,11 @@ describe('Navigation tests', () => { cy.getByTestId('chain-row').should('be.visible').click(); cy.url().should('include', '/324'); - // Wait for the mock data to be loaded - // cy.wait('@getChainData'); - // cy.getByTestId('chain-id').should('be.visible').and('contain', '324'); + cy.getByTestId('chain-id').should('be.visible').and('contain', '324'); - // cy.getByTestId('home-breadcrumb').click(); - // cy.url().should('eq', 'http://localhost:5173/'); - // cy.getByTestId('search-bar').find('input').should('have.value', ''); + cy.getByTestId('home-breadcrumb').click(); + cy.url().should('eq', 'http://localhost:5173/'); + cy.getByTestId('search-bar').find('input').should('have.value', ''); }); it('should navigate to tokens page, on all tokens button click', () => { @@ -46,8 +44,6 @@ describe('Navigation tests', () => { cy.getByTestId('chain-row').first().click(); cy.url().should('include', '/324'); - // Wait for the mock data to be loaded - // cy.wait('@getChainData'); - // cy.getByTestId('chain-id').should('be.visible').and('contain', '324'); + cy.getByTestId('chain-id').should('be.visible').and('contain', '324'); }); }); diff --git a/src/pages/[chain]/index.tsx b/src/pages/[chain]/index.tsx index a8a1d4f..b46c96f 100644 --- a/src/pages/[chain]/index.tsx +++ b/src/pages/[chain]/index.tsx @@ -1,7 +1,6 @@ import { useEffect } from 'react'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { GetStaticProps, GetStaticPaths, GetStaticPropsContext, InferGetStaticPropsType } from 'next'; -import { useTranslation } from 'next-i18next'; import { EcosystemChainData } from '~/types'; import { CustomHead } from '~/components'; @@ -13,23 +12,18 @@ import { getConfig } from '~/config'; const { DEFAULT_LANG, SUPPORTED_LANGUAGES } = getConfig(); interface ChainProps { - chain: EcosystemChainData | null; + chain: EcosystemChainData; } const Chain = ({ chain }: InferGetStaticPropsType) => { const { setSelectedChainId, refetchChainData } = useData(); - const { t } = useTranslation(); useEffect(() => { - if (chain?.chainId) { + if (chain.chainId) { setSelectedChainId(chain.chainId); } }, [chain?.chainId, setSelectedChainId, refetchChainData]); - if (!chain) { - return
{t('ERROR.errorFetchingData')}
; - } - return ( <> @@ -39,38 +33,27 @@ const Chain = ({ chain }: InferGetStaticPropsType) => { }; export const getStaticPaths: GetStaticPaths = async () => { - let paths = []; - - try { - const ecosystemData = await fetchEcosystemData(); - const chains = ecosystemData.zkChains; - - paths = SUPPORTED_LANGUAGES.flatMap((locale) => - chains.map((chain: EcosystemChainData) => ({ - params: { chain: chain.chainId.toString() }, - locale, - })), - ); - } catch (error) { - console.error('Failed to fetch ecosystem data:', error); - } + const ecosystemData = await fetchEcosystemData(); + const chains = ecosystemData.zkChains; + + const paths = SUPPORTED_LANGUAGES.flatMap((locale) => + chains.map((chain: EcosystemChainData) => ({ + params: { chain: chain.chainId.toString() }, + locale, + })), + ); return { paths, fallback: true }; }; export const getStaticProps: GetStaticProps = async ({ params, locale }: GetStaticPropsContext) => { - const chain: EcosystemChainData | null = null; + const ecosystemData = await fetchEcosystemData(); + const chains = ecosystemData.zkChains; + const chainId = params?.chain; + const chain = chains.find((chain: EcosystemChainData) => chain.chainId === chainId); - try { - const ecosystemData = await fetchEcosystemData(); - const chains = ecosystemData.zkChains; - const chainId = params?.chain; - const chain = chains.find((chain: EcosystemChainData) => chain.chainId === chainId); - if (!chain) { - return { notFound: true }; - } - } catch (error) { - console.error('Failed to fetch ecosystem data:', error); + if (!chain) { + return { notFound: true }; } const i18Config = await serverSideTranslations(locale || DEFAULT_LANG, ['common'], null, SUPPORTED_LANGUAGES);