Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

375-refactor: Subtitle component refactor #401

Merged
merged 33 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a02c4de
refactor: subtitle component
seygorin Jul 10, 2024
9673dc1
fix: delete extra size at subtitle component
seygorin Jul 11, 2024
75279cf
refactor: test for subtitle component and change prop to children in …
seygorin Jul 11, 2024
a297a85
fix: update extected heading conut in for study-with-us section
seygorin Jul 11, 2024
76f7dc1
fix: delete src/shared/__tests__/visualTesting/report/index.html
seygorin Jul 11, 2024
7dd2600
fix: delete src/shared/__tests__/visualTesting/results/.last-run.json
seygorin Jul 11, 2024
ec16d59
fix: add black color to main-section
seygorin Jul 12, 2024
f2b3313
refactor: add subttitles to hero / communtication and trainer-card ui…
seygorin Jul 15, 2024
36a01f4
feat: added additional styles for title and subtitle
seygorin Jul 21, 2024
05d0910
refactor: replaced all duplicate styles (margin) with one from the co…
seygorin Jul 21, 2024
9c586ed
fix: edited test for speakers componets
seygorin Jul 21, 2024
658c589
fix: remove redundant render call
seygorin Jul 22, 2024
fb557a3
fix: change expected items in testes for speaker \ course components
seygorin Jul 22, 2024
fb179cf
fix: resolve merge conflicts
seygorin Jul 22, 2024
e0ac8c1
fix: reformat SCSS and fix color type issues
seygorin Jul 23, 2024
562fed2
docs: playWright test updated for the mac users according to main branch
seygorin Jul 23, 2024
3648c52
fix: make the hero components more generic
seygorin Jul 23, 2024
628d8f5
fix: remove redundant styles in trainers comp
seygorin Jul 23, 2024
fff3924
fix: 375 - resolve merge conflicts and remove extra code in widget-title
seygorin Aug 23, 2024
f9c616f
feat: 375 - added data-testid and rewrite tests
seygorin Aug 23, 2024
ca5c092
feat: 375 - updated playWright tests
seygorin Aug 24, 2024
58262dc
fix: 375 - resolved merge conflicts
seygorin Sep 6, 2024
784c9b9
refactor: 375 - changed margin to padding
seygorin Sep 6, 2024
a759632
feat: 375 - added tests cases
seygorin Sep 6, 2024
9b75b71
fix: 375 - removed redundant styles in widget-title
seygorin Sep 6, 2024
2c7e7fc
fix: 375 - merged with main
seygorin Sep 12, 2024
defad00
refactor: 375 - added extra fontSizes for component and upded tests
seygorin Sep 12, 2024
e2471d4
fix: 375 - merged with main
seygorin Sep 12, 2024
e5a0bcf
fix: 375 - prettier problems
seygorin Sep 12, 2024
ff10470
fix: 375 - orde of properties in a component
seygorin Sep 12, 2024
ab009dc
fix: 375 - changed fontSize names to kebab-case
seygorin Sep 12, 2024
0d111da
fix: 375 - merged with main
seygorin Sep 12, 2024
b115403
fix: 375 - deleted visualTesting folder
seygorin Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions dev-data/training-program.data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const contentMap: ContentMap = {
Be well-prepared to pass the "AWS Certified Developer - Associate" certification
and confidently apply your skills in real-world projects by the end of the course.
</Paragraph>,
<Subtitle key="aws cloud dev 03" text="Course highlights:" />,
<Subtitle key="aws cloud dev 03">
Course highlights:
</Subtitle>,
Comment on lines +55 to +57
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

<List
key="aws cloud dev 04"
data={[
Expand Down Expand Up @@ -197,7 +199,9 @@ export const contentMap: ContentMap = {
<Paragraph key="js / front-end pre-school ru 01">
<span>Π’Π²Π΅Π΄Π΅Π½ΠΈΠ΅ Π² RS School:</span>
<List
data={['Знакомство со школой, профСссиСй JS/Front-end Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠ° ΠΈ систСмой контроля вСрсий Git.']}
data={[
'Знакомство со школой, профСссиСй JS/Front-end Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠ° ΠΈ систСмой контроля вСрсий Git.',
]}
marked={false}
/>
</Paragraph>,
Expand Down Expand Up @@ -230,7 +234,10 @@ export const contentMap: ContentMap = {
</Paragraph>,
<Paragraph key="js / front-end pre-school ru 05">
<span>Π˜Ρ‚ΠΎΠ³ΠΎΠ²Π°Ρ аттСстация:</span>
<List data={['ΠšΡ€ΠΎΡΡ-Ρ‡Π΅ΠΊ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ΠΎΠ², тСсты ΠΈ Ρ€Π΅Π²ΡŒΡŽ ΠΊΠΎΠ΄Π°. Π’Ρ‹Π΄Π°Ρ‡Π° сСртификата.']} marked={false} />
<List
data={['ΠšΡ€ΠΎΡΡ-Ρ‡Π΅ΠΊ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ΠΎΠ², тСсты ΠΈ Ρ€Π΅Π²ΡŒΡŽ ΠΊΠΎΠ΄Π°. Π’Ρ‹Π΄Π°Ρ‡Π° сСртификата.']}
marked={false}
/>
</Paragraph>,
],
image: jsImg,
Expand All @@ -254,10 +261,10 @@ export const contentMap: ContentMap = {
'Understanding of the REST',
]}
/>,
<Subtitle
key="react 03"
text="Attention! Mentors on this course will be first assigned to the graduates of the RS School Stage #2."
/>,
<Subtitle key="react 03">
Attention! Mentors on this course will be first assigned to the graduates of the RS School
Stage #2.
</Subtitle>,
],
image: reactEnImg,
},
Expand Down Expand Up @@ -289,13 +296,12 @@ export const contentMap: ContentMap = {
title: 'Details',
content: [
<Paragraph key="aws devops 01">
If you are looking for an entry point to kickstart your IT career as a DevOps engineer,
then this AWS course challenge is what you need.
If you are looking for an entry point to kickstart your IT career as a DevOps engineer, then
this AWS course challenge is what you need.
</Paragraph>,
<Subtitle
key="aws devops 02"
text="Showcase your level of expertise and join this expert-led program to:"
/>,
<Subtitle key="aws devops 02">
Showcase your level of expertise and join this expert-led program to:
</Subtitle>,
<List
key="aws devops 03"
data={[
Expand All @@ -308,10 +314,9 @@ export const contentMap: ContentMap = {
'Become a DevOps engineer who is ready to face engineering challenges',
]}
/>,
<Subtitle
key="aws devops 04"
text="What do we offer?"
/>,
<Subtitle key="aws devops 04">
What do we offer?
</Subtitle>,
Comment on lines +317 to +319
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

<List
key="aws devops 05"
data={[
Expand Down
62 changes: 62 additions & 0 deletions src/shared/ui/subtitle/subtitle.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.subtitle {
ansivgit marked this conversation as resolved.
Show resolved Hide resolved
margin: 0;
natanchik marked this conversation as resolved.
Show resolved Hide resolved
font-weight: $font-weight-medium;

&.extra-small-font-size {
font-size: 20px;
line-height: 28px;

@include media-tablet {
font-size: 18px;
line-height: 24px;
}
}

&.small-font-size {
font-size: 24px;
line-height: 32px;

@include media-tablet {
font-size: 20px;
line-height: 28px;
}
}

&.medium-font-size {
font-size: 28px;
line-height: 36px;

@include media-tablet {
font-size: 24px;
line-height: 32px;
}
}

&.large-font-size {
font-size: 32px;
line-height: 40px;

@include media-tablet {
font-size: 28px;
line-height: 36px;
}
}

&.extra-large-font-size {
font-size: 36px;
line-height: 44px;

@include media-tablet {
font-size: 32px;
line-height: 36px;
}
}
seygorin marked this conversation as resolved.
Show resolved Hide resolved

&.gray-600 {
color: $color-gray-600;
}

&.black {
color: $color-black;
}
}
KristiBo marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 0 additions & 18 deletions src/shared/ui/subtitle/subtitle.scss

This file was deleted.

81 changes: 74 additions & 7 deletions src/shared/ui/subtitle/subtitle.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,86 @@
import { render, screen } from '@testing-library/react';
import { cleanup, render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Subtitle } from './subtitle';
import { Subtitle, cx } from './subtitle';

describe('Subtitle component', () => {
it('renders without crashing', () => {
render(<Subtitle text="Test Subtitle" />);
const subtitle = screen.getByText('Test Subtitle');
render(<Subtitle>Test Subtitle</Subtitle>);
const subtitle = screen.getByTestId('subtitle');

expect(subtitle).toBeInTheDocument();
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(subtitle).toBeInTheDocument();
expect(subtitle).toBeVisible();


it('displays correct text', () => {
render(<Subtitle text="Another Test Subtitle" />);
const text = screen.getByText('Another Test Subtitle');
const testText = 'Another Test Subtitle';

SpaNb4 marked this conversation as resolved.
Show resolved Hide resolved
expect(text).toBeInTheDocument();
render(<Subtitle>{testText}</Subtitle>);
const subtitle = screen.getByTestId('subtitle');

expect(subtitle).toHaveTextContent(testText);
});

it('applies medium font size class by default', () => {
render(<Subtitle>Default Font Size</Subtitle>);
const subtitle = screen.getByTestId('subtitle');

expect(subtitle).toHaveClass(cx('medium-font-size'));
});

it('applies correct font size classes when specified', () => {
const sizes = ['extra-small', 'small', 'medium', 'large', 'extra-large'] as const;

sizes.forEach((size) => {
const { getByTestId } = render(
<Subtitle fontSize={size}>
{size}
Font Size
</Subtitle>,
);
const subtitle = getByTestId('subtitle');

expect(subtitle).toHaveClass(cx(`${size}-font-size`));
cleanup();
});
});

it('applies gray color class by default', () => {
render(<Subtitle>Default Color</Subtitle>);
const subtitle = screen.getByTestId('subtitle');

expect(subtitle).toHaveClass(cx('gray-600'));
});

it('applies black color class when specified', () => {
render(<Subtitle color="black">Black Color</Subtitle>);
const subtitle = screen.getByTestId('subtitle');

expect(subtitle).toHaveClass(cx('black'));
});

it('applies custom className when provided', () => {
render(<Subtitle className="custom-class">Custom Class</Subtitle>);
const subtitle = screen.getByTestId('subtitle');

expect(subtitle).toHaveClass('custom-class');
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(subtitle).toHaveClass('custom-class');
expect(subtitle).toHaveClass('custom-class', cx('gray-600'), cx('medium-font-size'));


it('applies multiple variant classes correctly', () => {
render(
<Subtitle fontSize="large" color="black" className="custom-class">
Multiple Variants
</Subtitle>,
);
const subtitle = screen.getByTestId('subtitle');

expect(subtitle).toHaveClass(cx('large-font-size'));
expect(subtitle).toHaveClass(cx('black'));
expect(subtitle).toHaveClass('custom-class');
});

it('renders as h3 element', () => {
render(<Subtitle>H3 Element</Subtitle>);
const subtitle = screen.getByTestId('subtitle');

expect(subtitle.tagName).toBe('H3');
});
});
51 changes: 43 additions & 8 deletions src/shared/ui/subtitle/subtitle.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
import './subtitle.scss';
import { HTMLAttributes } from 'react';
import { type VariantProps, cva } from 'class-variance-authority';
import classNames from 'classnames/bind';

interface SubtitleProps {
text: string;
type?: string;
}
import styles from './subtitle.module.scss';

export const Subtitle = ({ text, type = '' }: SubtitleProps) => (
<div className={`subtitle ${type}`}>{text}</div>
);
type SubtitleProps = Pick<HTMLAttributes<HTMLHeadingElement>, 'className' | 'children'> &
VariantProps<typeof subtitleVariants>;

ansivgit marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +7 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen the the same problem in our codebase before, but are we sure to use type SubtitleProps, which includes type of variable subtitleVariants, before definition of this variable?

export const cx = classNames.bind(styles);

const subtitleVariants = cva(cx('subtitle'), {
variants: {
fontSize: {
'extra-small': cx('extra-small-font-size'),
small: cx('small-font-size'),
medium: cx('medium-font-size'),
large: cx('large-font-size'),
'extra-large': cx('extra-large-font-size'),
},
color: {
gray: cx('gray-600'),
black: cx('black'),
},
},
defaultVariants: {
fontSize: 'medium',
color: 'gray',
},
});

export const Subtitle = ({ children, fontSize, color, className }: SubtitleProps) => {
return (
<h3
className={subtitleVariants({
fontSize,
color,
className,
})}
data-testid="subtitle"
>
{children}
</h3>
);
};
4 changes: 0 additions & 4 deletions src/widgets/certification/ui/certification.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

font-size: 20px;

.subtitle {
font-size: 28px;
}

@include media-tablet-large {
flex-direction: column;
gap: 40px;
Expand Down
4 changes: 0 additions & 4 deletions src/widgets/communication/ui/communication.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
padding-top: 5px;
}

.subtitle {
font-size: 28px;
}

.disclogo-wrapper {
flex-shrink: 0;
align-self: center;
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/communication/ui/communication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const Communication = ({ courseName, lang = 'en' }: RequiredProps) => {
<DiscordLogo />
</figure>
<div>
<Subtitle text={localizedContent[lang].subTitle} />
<Subtitle>{localizedContent[lang].subTitle}</Subtitle>
seygorin marked this conversation as resolved.
Show resolved Hide resolved
<Paragraph className="communication-paragraph">
{localizedContent[lang].firstParagraphFirstHalf}{' '}
<LinkCustom href={DISCORD_LINKS[courseName]} icon={<TextLinkIcon />} target="_blank">
Expand Down
4 changes: 0 additions & 4 deletions src/widgets/community/ui/community.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
width: 640px;
text-align: left;

& .subtitle {
margin-top: 8px;
}

& .social-media-container {
display: flex;
flex-flow: row wrap;
Expand Down
6 changes: 5 additions & 1 deletion src/widgets/course-main/course-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export const CourseMain = ({ courseName, lang = 'en', type }: CourseMainProps) =
<div className={styles.info}>
<SectionLabel>{status}</SectionLabel>
<WidgetTitle>{`${altTitle || title} Course`}</WidgetTitle>
{type && <Subtitle text={type} type="course-main" />}
{type && (
<Subtitle fontSize="small" color="black">
{type}
</Subtitle>
)}
<DateLang startDate={date} language={language} mode={mode} withMargin />
<LinkCustom href={enroll} icon={<ArrowIcon />} variant="secondary" target="_blank">
{localizedContent[lang].linkLabel}
Expand Down
Loading
Loading