All files / src/components/Home Categories.tsx

100% Statements 8/8
50% Branches 1/2
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33            4x   4x 3x   3x                       4x 1x   1x     3x      
import React, { FC } from 'react';
import { GatsbyImage, getImage } from 'gatsby-plugin-image';
import { KsCard } from 'ag-ems-ui-library';
import { LocalizedLink as Link } from 'gatsby-theme-i18n';
import { useTranslation } from 'react-i18next';
 
const styles = require('./Home.module.css');
 
const Category: FC<{ category: any }> = ({ category }) => {
  const image = getImage(category.images[0].localFile);
 
  return <KsCard
    classes={styles.Category}
    desktopView={false}
    image={image
      ? <GatsbyImage image={image} alt={category.name} />
      : null}
    title={category.name}
    link={`/${category.slug}`}
    linkComponent={Link}
  />;
};
 
export const Categories: FC<{ categories: any[] }> = ({ categories }) => {
  const { t } = useTranslation();
 
  return <div className={styles.Categories}>
    <h2>{t('offers')}</h2>
    <div className={styles.CategoriesList}>
      {categories.map(category => <Category key={category.strapiId} category={category} />)}
    </div>
  </div>;
};