/** * Copyright (c) Paymium. * * This source code is licensed under the MIT license found in the * LICENSE file in the root of this projects source tree. */ import { render, screen } from '@crossed/test'; import '@testing-library/jest-dom'; import { Text } from '../../../typography'; import { Divider } from '../../../layout'; import { Card, CardTitle, CardDescription, CardGroup, CardExtra, } from '../index'; expect(Card).toBeDefined(); expect(CardTitle).toBeDefined(); expect(CardDescription).toBeDefined(); expect(CardGroup).toBeDefined(); expect(CardExtra).toBeDefined(); describe('Card Group', () => { test('if child not valid it is not rendered', () => { render( Toto {42} ); expect(screen.getByText('Toto')).toBeInTheDocument(); expect(screen.queryByText('42')).not.toBeInTheDocument(); }); test('Throw error with direct child different from Card or Divider', () => { const renderWithInvalidChild = () => render( Toto ); expect(renderWithInvalidChild).toThrow( 'Direct children of CardGroup should be Divider or Card' ); }); test('Divider is rendered ', () => { render( ); expect(screen.getByTestId('divider')).toBeTruthy(); }); test("With only one Child CardGroup doesn't change style of child", () => { render( Toto ); const element = screen.getByTestId('firstCardChild'); expect(element).not.toHaveClass( 'border-top-left-radius-[0px] border-bottom-left-radius-[0px] border-top-right-radius-[0px] border-bottom-right-radius-[0px]' ); }); describe('With 2 Card Children', () => { const customRender = () => { render( Toto Toti ); }; test('border bottom and border radius bottom of first child are modified', () => { customRender(); const firstCardChild = screen.getByTestId('firstCardChild'); expect(firstCardChild).not.toHaveClass( 'border-top-left-radius-[0px] border-top-right-radius-[0px]' ); expect(firstCardChild).toHaveClass( 'border-bottom-left-radius-[0px] border-bottom-right-radius-[0px] border-bottom-width-[0px]' ); }); test('border top and border radius top of last child are modified', () => { customRender(); const lastCardChild = screen.getByTestId('lastCardChild'); expect(lastCardChild).toHaveClass( 'border-top-left-radius-[0px] border-top-right-radius-[0px] border-top-width-[0px]' ); expect(lastCardChild).not.toHaveClass( 'border-bottom-left-radius-[0px] border-bottom-right-radius-[0px]' ); }); }); describe('With 3 Card Children', () => { const customRender = () => { render( Toto Titi Toti ); }; test('border bottom and border radius bottom of first child are modified', () => { customRender(); const firstCardChild = screen.getByTestId('firstCardChild'); expect(firstCardChild).not.toHaveClass( 'border-top-left-radius-[0px] border-top-right-radius-[0px]' ); expect(firstCardChild).toHaveClass( 'border-bottom-left-radius-[0px] border-bottom-right-radius-[0px] border-bottom-width-[0px]' ); }); test('border top and bottom and border radius top and bottom of middle child are modified', () => { customRender(); const middleCardChild = screen.getByTestId('middleCardChild'); expect(middleCardChild).toHaveClass( 'border-radius-[0px] border-bottom-width-[0px] border-top-width-[0px]' ); }); test('border top and border radius top of last child are modified', () => { customRender(); const lastCardChild = screen.getByTestId('lastCardChild'); expect(lastCardChild).toHaveClass( 'border-top-left-radius-[0px] border-top-right-radius-[0px] border-top-width-[0px]' ); expect(lastCardChild).not.toHaveClass( 'border-bottom-left-radius-[0px] border-bottom-right-radius-[0px]' ); }); }); }); describe('Card', () => { test('if pressable, link style is applied', () => { render( Toto ); expect(screen.getByTestId('card')).toHaveClass( 'active:background-color-[var(--components--card-active-background)]' ); }); });