Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #375 from deriv-com/Jia/features-block-new-variants
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-deriv authored Feb 20, 2024
2 parents 412273d + cc409ec commit 9305f57
Show file tree
Hide file tree
Showing 18 changed files with 508 additions and 80 deletions.
6 changes: 3 additions & 3 deletions libs/blocks/src/lib/block-wrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
} from '@deriv/quill-design';
import { ReactNode } from 'react';

type BgVariant = 'light' | 'gray';
export type BgVariant = 'light' | 'gray';

const bgColorVariantClass: { [key in BgVariant]: string } = {
export const bgColorVariantClass: { [key in BgVariant]: string } = {
light: 'bg-background-primary-container',
gray: 'bg-background-primary-base',
};
Expand All @@ -18,7 +18,7 @@ export interface BlockWrapperProps {
description?: ReactNode;
className?: string;
children: ReactNode;
background: BgVariant;
background?: BgVariant;
}

export const BlockWrapper = ({
Expand Down
50 changes: 32 additions & 18 deletions libs/blocks/src/lib/features/content-left/content-left.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';

import ContentLeft from '.';
import { Button, Heading } from '@deriv/quill-design';

const ContentLeftContent = () => (
<Heading.H2>This is a heading content</Heading.H2>
);
const className = 'text-heading-h2';
const title = 'This is the title';
const description = 'Description here';
const content = 'This is a heading content';
const child = 'This is a button';

describe('ContentLeft', () => {
it('renders with correct class names and content', () => {
const className = 'text-heading-h2';
const title = 'This is the title';
const description = 'Description here';
const ContentLeftContent = () => <Heading.H3>{content}</Heading.H3>;

const { getByText } = render(
describe('ContentLeft', () => {
beforeEach(() => {
render(
<ContentLeft
className={className}
title={title}
description={description}
content={ContentLeftContent}
>
<Button>This is a button</Button>
<Button>{child}</Button>
</ContentLeft>,
);
const titleElement = getByText(title);
});

//renders with correct classname
expect(titleElement).toHaveClass(className);
it('renders with correct class names passing in', () => {
expect(document.querySelector(`.${className}`)).toBeInTheDocument();
});

//renders with the correct title
expect(getByText(title)).toBeInTheDocument();
it(`renders with correct title '${title}'`, () => {
expect(
screen.getByRole('heading', { name: title, level: 2 }),
).toBeInTheDocument();
});

it(`renders with correct description '${description}'`, () => {
expect(screen.getByText(description)).toBeInTheDocument();
});

it(`renders with correct content`, () => {
expect(
screen.getByRole('heading', { name: content, level: 3 }),
).toBeInTheDocument();
});

//renders with the correct description
expect(getByText(description)).toBeInTheDocument();
it(`renders with correct children`, () => {
expect(screen.getByRole('button', { name: child })).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
className:
'my-1000 bg-background-primary-container max-sm:px-800 max-lg:px-1200',
className: 'bg-background-primary-container',
title: 'Title here',
description:
'Description goes here description goes here description goes here description goes here',
Expand All @@ -23,6 +22,8 @@ export const Default: Story = {
<Text>Any Content here</Text>
</div>
),
contentTop: false,
contentPadding: true,
content: () => (
<img
className="flex w-full flex-1"
Expand Down
22 changes: 18 additions & 4 deletions libs/blocks/src/lib/features/content-left/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { FluidContainer, Heading, Section, Text } from '@deriv/quill-design';
import {
FluidContainer,
Heading,
Section,
Text,
qtJoin,
} from '@deriv/quill-design';
import clsx from 'clsx';
import { ContentLeftProps } from '../types';

Expand All @@ -10,6 +16,8 @@ const ContentLeft = ({
children,
content: Content,
variant = 'content-left',
contentTop = false,
contentPadding = true,
}: ContentLeftProps) => {
return (
<Section
Expand All @@ -22,12 +30,13 @@ const ContentLeft = ({
<FluidContainer
className={clsx(
variant === 'content-left' ? 'lg:flex-row-reverse' : 'lg:flex-row',
'flex flex-col gap-gap-xl lg:gap-gap-lg',
'flex flex-col gap-gap-3xl px-general-none lg:gap-gap-lg',
contentTop ? 'flex-col-reverse' : 'flex-col',
)}
>
<div
className={clsx(
'flex flex-1 basis-1/2 flex-col gap-general-2xl lg:justify-center lg:gap-gap-3xl',
'flex flex-1 basis-1/2 flex-col gap-general-2xl px-general-md lg:justify-center lg:gap-gap-3xl lg:px-general-none',
variant === 'content-left'
? 'lg:pl-general-xl'
: 'lg:pr-general-2xl',
Expand All @@ -40,7 +49,12 @@ const ContentLeft = ({
{children && children}
</div>
{Content && (
<div className="flex flex-1 basis-1/2 justify-center">
<div
className={qtJoin(
'flex flex-1 basis-1/2 justify-center',
contentPadding && 'px-general-md lg:px-general-none',
)}
>
<Content />
</div>
)}
Expand Down
52 changes: 33 additions & 19 deletions libs/blocks/src/lib/features/content-right/content-right.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';

import ContentRight from '.';
import { Button, Heading } from '@deriv/quill-design';

const ContentRightContent = () => (
<Heading.H2>This is a heading content</Heading.H2>
);
const className = 'text-heading-h2';
const title = 'This is the title';
const description = 'Description here';
const content = 'This is a heading content';
const child = 'This is a button';

describe('ContentLeft', () => {
it('renders with correct class names and content', () => {
const className = 'text-heading-h2';
const title = 'This is the title';
const description = 'Description here';
const ContentRightContent = () => <Heading.H3>{content}</Heading.H3>;

const { getByText } = render(
describe('ContentRight', () => {
beforeEach(() => {
render(
<ContentRight
className={className}
title={title}
content={ContentRightContent}
description={description}
content={ContentRightContent}
>
<Button>This is a button</Button>
<Button>{child}</Button>
</ContentRight>,
);
const titleElement = getByText(title);
});

//renders with correct classname
expect(titleElement).toHaveClass(className);
it('renders with correct class names passing in', () => {
expect(document.querySelector(`.${className}`)).toBeInTheDocument();
});

//renders with the correct title
expect(getByText(title)).toBeInTheDocument();
it(`renders with correct title '${title}'`, () => {
expect(
screen.getByRole('heading', { name: title, level: 2 }),
).toBeInTheDocument();
});

it(`renders with correct description '${description}'`, () => {
expect(screen.getByText(description)).toBeInTheDocument();
});

it(`renders with correct content`, () => {
expect(
screen.getByRole('heading', { name: content, level: 3 }),
).toBeInTheDocument();
});

//renders with the correct description
expect(getByText(description)).toBeInTheDocument();
it(`renders with correct children`, () => {
expect(screen.getByRole('button', { name: child })).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
className:
'my-1000 bg-background-primary-container max-sm:px-800 max-lg:px-1200',
className: 'bg-background-primary-container',
title: 'Title here',
description:
'Description goes here description goes here description goes here description goes here',
Expand All @@ -23,6 +22,8 @@ export const Default: Story = {
<Text>Any Content here</Text>
</div>
),
contentPadding: true,
contentTop: false,
content: () => (
<img
className="flex w-full flex-1"
Expand Down
20 changes: 2 additions & 18 deletions libs/blocks/src/lib/features/content-right/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import ContentLeft from '../content-left';
import { ContentLeftProps } from '../types';

const ContentRight = ({
title,
className,
description,
children,
content,
}: Omit<ContentLeftProps, 'variant'>) => {
return (
<ContentLeft
title={title}
variant="content-right"
description={description}
content={content}
className={className}
>
{children}
</ContentLeft>
);
const ContentRight = ({ ...rest }: Omit<ContentLeftProps, 'variant'>) => {
return <ContentLeft variant="content-right" {...rest} />;
};

export default ContentRight;
57 changes: 43 additions & 14 deletions libs/blocks/src/lib/features/content-slider/content-slider.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';

import ContentSlider from '.';
import { Button } from '@deriv/quill-design';
import { cards } from './mock-data';

describe('CardSlider', () => {
it('renders with correct class names and content', () => {
const className = 'text-heading-h2';
const title = 'This is the title';
const description = 'Description here';
const className = 'text-heading-h2';
const title = 'This is the title';
const description = 'Description here';
const cta = 'CTA';

const { getByText } = render(
describe('CardSlider', () => {
beforeEach(() => {
render(
<ContentSlider
className={className}
title={title}
description={description}
cardSliderProps={{
slideClasses: 'max-w-xs',
variant: 'ContentBottom',
cards: cards,
}}
cta={() => <Button>{cta}</Button>}
/>,
);
const titleElement = getByText(title);
});

it(`should render the correct class name '${className}' passing in`, () => {
expect(document.querySelector(`.${className}`)).toBeInTheDocument();
});

//renders with correct classname
expect(titleElement).toHaveClass(className);
it(`should render the correct title '${title}'`, () => {
expect(
screen.getByRole('heading', { name: title, level: 2 }),
).toBeInTheDocument();
});

it(`should render the correct description '${description}'`, () => {
expect(screen.getByText(description)).toBeInTheDocument();
});

it('should render the correct cta', () => {
expect(screen.getByRole('button', { name: cta })).toBeInTheDocument();
});

//renders with the correct title
expect(getByText(title)).toBeInTheDocument();
cards.forEach((_, i) => {
it(`should render the correct title '${title}'`, () => {
expect(
screen.getByRole('heading', { name: `Card ${i + 1}`, level: 4 }),
).toBeInTheDocument();
});

//renders with the correct description
expect(getByText(description)).toBeInTheDocument();
it(`should render the correct description '${description}'`, () => {
expect(screen.getByText(`Description here ${i + 1}`)).toBeInTheDocument();
});
});
});
14 changes: 14 additions & 0 deletions libs/blocks/src/lib/features/content-slider/mock-data.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CardVariantProps } from '@deriv-com/components';
import { IllustrativeProtectedAndSecureIcon } from '@deriv/quill-icons';

export const cards: CardVariantProps<'ContentBottom'>[] = Array.from({
length: 6,
}).map((_, i) => ({
id: i,
header: `Card ${i + 1}`,
description: `Description here ${i + 1}`,
icon: <IllustrativeProtectedAndSecureIcon />,
color: 'gray',
align: 'start',
size: 'sm',
}));
Loading

0 comments on commit 9305f57

Please sign in to comment.