Skip to content
This repository has been archived by the owner on Mar 23, 2022. It is now read-only.

Commit

Permalink
ADD - Analysis entry render test
Browse files Browse the repository at this point in the history
Signed-off-by: RaenonX <[email protected]>
  • Loading branch information
RaenonX committed May 27, 2021
1 parent 22a5592 commit 7a5f8ec
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 3 deletions.
144 changes: 144 additions & 0 deletions src/components/elements/posts/analysis/lookup/out/entry.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import React from 'react';

import {screen} from '@testing-library/react';

import {renderReact} from '../../../../../../../test/render/main';
import {AnalysisLookupEntry, SupportedLanguages, UnitType} from '../../../../../../api-def/api';
import {UnitInfoData} from '../../../../../../api-def/resources';
import {PostPath} from '../../../../../../const/path/definitions';
import {translation as translationEN} from '../../../../../../i18n/translations/en/translation';
import {makePostPath} from '../../../../../../utils/path/make';
import {AnalysisEntry} from './entry';

describe('Analysis lookup entry', () => {
const name = {
[SupportedLanguages.CHT]: 'name CHT',
[SupportedLanguages.EN]: 'Gala Leonidas',
[SupportedLanguages.JP]: 'name JP',
};

const unitInfo: UnitInfoData = {
type: UnitType.CHARACTER,
name,
id: 10950101,
rarity: 5,
element: 2,
iconName: 'icon',
cvEn: name,
cvJp: name,
releaseEpoch: 900000,
};
const analysisMeta: AnalysisLookupEntry = {
type: UnitType.CHARACTER,
lang: SupportedLanguages.CHT,
unitId: 10950101,
viewCount: 777,
modifiedEpoch: 9000000,
publishedEpoch: 8000000,
};

it('renders analysis with correct info and link to click', async () => {
renderReact(() => (
<AnalysisEntry
unitInfo={unitInfo}
analysisMeta={analysisMeta}
isFetchingMeta={false}
simplified={false}
/>
));

expect(screen.getByAltText('Gala Leonidas')).toBeInTheDocument();
const unitName = screen.getByText('Gala Leonidas');
expect(unitName).not.toHaveClass('text-danger');
expect(unitName).not.toHaveClass('text-muted');
expect(unitName)
.toHaveAttribute(
'href',
makePostPath(PostPath.ANALYSIS, {lang: SupportedLanguages.EN, pid: 10950101}),
);
expect(screen.queryByText(/777/)).toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.published}`))).toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.lastModified}`))).toBeInTheDocument();
expect(screen.queryByText(translationEN.message.info.fetching)).not.toBeInTheDocument();
expect(screen.queryByText(translationEN.posts.analysis.error.unavailable)).not.toBeInTheDocument();
});

it('shows that the analysis meta is fetching', async () => {
renderReact(() => (
<AnalysisEntry
unitInfo={unitInfo}
isFetchingMeta
simplified={false}
/>
));

expect(screen.getByAltText('Gala Leonidas')).toBeInTheDocument();
const unitName = screen.getByText('Gala Leonidas');
expect(unitName).toHaveClass('text-muted');
expect(screen.queryByText(/777/)).not.toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.published}`))).not.toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.lastModified}`))).not.toBeInTheDocument();
expect(screen.queryByText(translationEN.message.info.fetching)).toBeInTheDocument();
expect(screen.queryByText(translationEN.posts.analysis.error.unavailable)).not.toBeInTheDocument();
});

it('shows unavailable as expected', async () => {
renderReact(() => (
<AnalysisEntry
unitInfo={unitInfo}
isFetchingMeta={false}
simplified={false}
/>
));

expect(screen.getByAltText('Gala Leonidas')).toBeInTheDocument();
const unitName = screen.getByText('Gala Leonidas');
expect(unitName).toHaveClass('text-muted');
expect(screen.queryByText(/777/)).not.toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.published}`))).not.toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.lastModified}`))).not.toBeInTheDocument();
expect(screen.queryByText(translationEN.message.info.fetching)).not.toBeInTheDocument();
const unavailable = screen.getByText(translationEN.posts.analysis.error.unavailable);
expect(unavailable).toHaveClass('text-danger');
});

it('shows available but simplified entry', async () => {
renderReact(() => (
<AnalysisEntry
unitInfo={unitInfo}
analysisMeta={analysisMeta}
isFetchingMeta={false}
simplified
/>
));

expect(screen.getByAltText('Gala Leonidas')).toBeInTheDocument();
const unitName = screen.getByText('Gala Leonidas');
expect(unitName).not.toHaveClass('text-muted');
expect(screen.queryByText(/777/)).not.toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.published}`))).not.toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.lastModified}`))).toBeInTheDocument();
expect(screen.queryByText(translationEN.message.info.fetching)).not.toBeInTheDocument();
expect(screen.queryByText(translationEN.posts.analysis.error.unavailable)).not.toBeInTheDocument();
});

it('shows unavailable even if simplified', async () => {
renderReact(() => (
<AnalysisEntry
unitInfo={unitInfo}
isFetchingMeta={false}
simplified
/>
));

expect(screen.getByAltText('Gala Leonidas')).toBeInTheDocument();
const unitName = screen.getByText('Gala Leonidas');
expect(unitName).toHaveClass('text-muted');
expect(screen.queryByText(/777/)).not.toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.published}`))).not.toBeInTheDocument();
expect(screen.queryByText(new RegExp(`${translationEN.posts.info.lastModified}`))).not.toBeInTheDocument();
expect(screen.queryByText(translationEN.message.info.fetching)).not.toBeInTheDocument();
const unavailable = screen.getByText(translationEN.posts.analysis.error.unavailable);
expect(unavailable).toHaveClass('text-danger');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type AnalysisEntryCommonProps = {
unitInfo: UnitInfoData,
}

type AnalysisEntryProps = AnalysisEntryCommonProps & AnalysisEntryAvailableProps & {
type AnalysisEntryProps = AnalysisEntryCommonProps & Omit<AnalysisEntryAvailableProps, 'analysisMeta'> & {
analysisMeta?: AnalysisLookupEntry,
isFetchingMeta: boolean,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type AnalysisEntryAvailableProps = AnalysisEntryCommonProps & {
export const AnalysisEntryAvailable = ({
unitInfo,
analysisMeta,
simplified = true,
simplified = false,
}: AnalysisEntryAvailableProps) => {
const {t, lang} = useI18n();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const AnalysisEntryUnavailable = ({unitInfo, isFetchingMeta}: AnalysisEnt
<>
<Row noGutters className="pt-1" style={{height: '2.5rem'}}>
<Col className="mr-2">
<h6 className="text-muted">{unitInfo.name[lang]}</h6>
<span className="h6 text-muted">{unitInfo.name[lang]}</span>
</Col>
</Row>
<Row noGutters className="align-items-center" style={{height: '1.5rem'}}>
Expand Down

0 comments on commit 7a5f8ec

Please sign in to comment.