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

535-refactor: Widget School Courses #572

Merged
merged 33 commits into from
Oct 10, 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
6f68471
refactor: 546 - rename CourseCard to course-item
Quiddlee Sep 27, 2024
539f3e0
refactor: 546 - extract course-item styles to separate file
Quiddlee Sep 27, 2024
a3c1481
feat: 546 - add course-item unit tests
Quiddlee Sep 27, 2024
672eff5
refactor: 546 - move course-item to entity course
Quiddlee Sep 27, 2024
f78ccc5
refactor: 546 - remove course-item styles from courses scss
Quiddlee Sep 27, 2024
1ee229c
fix: 546 - courses imports
Quiddlee Sep 27, 2024
2e2b6de
refactor: 546 - rename courses to courses-school
Quiddlee Sep 27, 2024
872ac23
refactor: 546 - rename courses scss to courses-school scss
Quiddlee Sep 27, 2024
6d367e2
refactor: 546 - move tabletScreenBreakPoint to constants.ts
Quiddlee Sep 27, 2024
905878d
refactor: 546 - replace RsBanner with Image component
Quiddlee Sep 27, 2024
50eb819
refactor: 546 - rename MAX_COURSE_COUNT to camelCase
Quiddlee Sep 27, 2024
dcd2de5
refactor: 546 - move courses-school test to ui folder
Quiddlee Sep 27, 2024
249f5fa
refactor: 546 - move all the width and height to constants
Quiddlee Sep 27, 2024
430c8b5
refactor: 546 - remove all it.skip
Quiddlee Sep 27, 2024
247abf4
refactor: 546 - get rid of divs
Quiddlee Sep 27, 2024
c229b9b
refactor: 546 - move course item type to entity types
Quiddlee Sep 27, 2024
7d6670c
refactor: 546 - remove course icon alt attribute
Quiddlee Sep 27, 2024
3e2d492
refactor: 546 - add better class name
Quiddlee Sep 27, 2024
2a9d275
fix: 546 - remove blank line
Quiddlee Sep 27, 2024
710faa9
refactor: 546 - replace date with time tag
Quiddlee Sep 27, 2024
3966ecb
refactor: 546 - remove unnecessary test
Quiddlee Sep 27, 2024
3d0f336
refactor: 546 - change course entity re-exports
Quiddlee Sep 27, 2024
4847b52
fix: 546 - course school import
Quiddlee Sep 27, 2024
0642967
fix: 546 - correct test cases
Quiddlee Sep 27, 2024
d9bcd44
refactor: 546 - change course language tag
Quiddlee Sep 27, 2024
1dc96e9
refactor: 546 - remove unnecessary type casting
Quiddlee Sep 30, 2024
dc28c0d
feat: 546 - add test cases to cover different screen sizes
Quiddlee Sep 30, 2024
cda22b2
refactor: 546 - rename component to upcoming courses
Quiddlee Sep 30, 2024
66654cc
refactor: 546 - rename maxCourseCount to maxUpcomingCoursesQuantity
Quiddlee Oct 1, 2024
213e45e
refactor: 546 - merge some test cases
Quiddlee Oct 1, 2024
b8e8052
refactor: 546 - remove unnecessary file extension
Quiddlee Oct 1, 2024
02ddde6
refactor: 546 - remove unnecessary file extension
Quiddlee Oct 1, 2024
0fc8232
refactor: 546 - remove title's top margin
Quiddlee Oct 1, 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
3 changes: 2 additions & 1 deletion src/entities/course/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type { Course, CourseStatus } from './types';
export type { Course, CourseItemData, CourseStatus } from './types';
export { CourseCard } from './ui/course-card/course-card';
export { CourseItem } from './ui/course-item/course-item';
5 changes: 5 additions & 0 deletions src/entities/course/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ export type Course = {
};

export type CourseStatus = 'planned' | 'available' | 'upcoming';

export type CourseItemData = Pick<Course, 'title' | 'language' | 'startDate' | 'detailsUrl'> & {
buttonText: string;
iconSrc: string;
};
1 change: 1 addition & 0 deletions src/entities/course/ui/course-card/course-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const CourseCard = ({
href={detailsUrl}
variant="rounded"
aria-label="View course details"
data-testid="course-link"
>
View details
</LinkCustom>
Expand Down
44 changes: 44 additions & 0 deletions src/entities/course/ui/course-item/course-item.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.course-item {
@extend %transition-all;

display: flex;
align-items: center;
justify-content: space-between;
width: 100%;

.icon-container {
display: flex;
align-items: center;
justify-content: center;
padding: 16px;

.course-icon {
width: 48px;
height: 36px;
object-fit: contain;
}
}

.course-info {
width: 100%;

.date {
margin-top: 8px;
margin-bottom: 0;

font-size: 14px;
line-height: 20px;
color: $color-gray-600;
}
}

.details-link {
margin: 16px;
}

@include media-hover {
&:hover {
box-shadow: 0 4px 16px 0 rgb(0 0 0 / 12%);
}
}
}
41 changes: 41 additions & 0 deletions src/entities/course/ui/course-item/course-item.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { screen } from '@testing-library/react';
import dayjs from 'dayjs';
import { CourseItem, CourseItemData } from '@/entities/course';
import { renderWithRouter } from '@/shared/__tests__/utils';

const mockedProps: CourseItemData = {
title: 'Introduction to React',
language: ['en'],
startDate: '2024-05-01',
detailsUrl: '/courses/react-intro',
buttonText: 'View Details',
iconSrc: '/images/react-icon.png',
};

const expectedDate = dayjs(mockedProps.startDate).toISOString();

describe('CourseItem Component', () => {
beforeEach(() => {
renderWithRouter(<CourseItem {...mockedProps} />);
});

it('renders the component data as expected', () => {
const titleElement = screen.getByText(mockedProps.title);
const languageInitial = mockedProps.language[0].toUpperCase();
const dateElement = screen.getByTestId('course-language');
const courseDate = screen.getByTestId('course-date');

expect(titleElement).toBeInTheDocument();
expect(dateElement).toBeInTheDocument();
expect(dateElement).toHaveTextContent(`β€’ ${languageInitial}`);
expect(courseDate).toHaveAttribute('datetime', expectedDate);
});

it('renders the LinkCustom component with correct href and text', () => {
const link = screen.getByTestId('course-link');

expect(link).toBeInTheDocument();
expect(link).toHaveAttribute('href', mockedProps.detailsUrl);
expect(link).toHaveTextContent(mockedProps.buttonText);
});
});
55 changes: 55 additions & 0 deletions src/entities/course/ui/course-item/course-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import classNames from 'classnames/bind';
import dayjs from 'dayjs';
import { CourseItemData } from '@/entities/course';
import { Image } from '@/shared/ui/image';
import { LinkCustom } from '@/shared/ui/link-custom';
import { Subtitle } from '@/shared/ui/subtitle';

import styles from './course-item.module.scss';

const cx = classNames.bind(styles);

export const CourseItem = ({
title,
language,
startDate,
detailsUrl,
buttonText,
iconSrc,
}: CourseItemData) => {
const dateTime = dayjs(startDate).toISOString();

return (
<section className={cx('course-item')}>
<figure className={cx('icon-container')}>
<Image
className={cx('course-icon')}
src={iconSrc}
alt=""
aria-hidden="true"
data-testid="course-image"
/>
</figure>
<article className={cx('course-info')}>
<Subtitle color="black" fontSize="extra-small">
{title}
</Subtitle>
<p className={cx('date')}>
<time dateTime={dateTime} data-testid="course-date">
{startDate}
</time>
<span data-testid="course-language">{` β€’ ${language[0].toUpperCase()}`}</span>
</p>
</article>
<LinkCustom
className={cx('details-link')}
href={detailsUrl}
variant="rounded"
aria-label="More details"
data-testid="course-link"
>
{buttonText}
</LinkCustom>
</section>
);
};
4 changes: 2 additions & 2 deletions src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { useTitle } from '@/shared/hooks/use-title';
import { AboutSchool } from '@/widgets/about-school';
import { Alumni } from '@/widgets/alumni';
import { Breadcrumbs } from '@/widgets/breadcrumbs';
import { Courses } from '@/widgets/courses-school';
import { HeroPage } from '@/widgets/hero-page';
import { Mentoring } from '@/widgets/mentoring';
import { Mentors } from '@/widgets/mentors';
import { Principles } from '@/widgets/principles';
import { Requirements } from '@/widgets/requirements';
import { StudyWithUs } from '@/widgets/study-with-us';
import { UpcomingCourses } from '@/widgets/upcoming-courses';

export const Home: FC = () => {
useTitle('Home Β· The Rolling Scopes School');
Expand All @@ -22,7 +22,7 @@ export const Home: FC = () => {
<AboutSchool />
<Principles />
<StudyWithUs />
<Courses />
<UpcomingCourses />
<Alumni />
<Mentors />
<Mentoring />
Expand Down
1 change: 0 additions & 1 deletion src/shared/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export { NodeJsIcon } from './nodejs-icon';
export { OpenSourcePhilosophyIcon } from './open-source-philosophy-icon';
export { OpenToEveryoneIcon } from './open-to-everyone-icon';
export { ReactIcon } from './react-icon';
export { RsBanner } from './rs-banner';
export { TeachItForwardIcon } from './teach-It-forward-icon';
export { TelegramIcon } from './telegram';
export { TextLinkIcon } from './text-link-icon';
Expand Down
6 changes: 0 additions & 6 deletions src/shared/icons/rs-banner.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/widgets/courses-school/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/widgets/courses-school/model/constants.ts

This file was deleted.

43 changes: 0 additions & 43 deletions src/widgets/courses-school/ui/CourseCard.tsx

This file was deleted.

84 changes: 0 additions & 84 deletions src/widgets/courses-school/ui/courses.module.scss

This file was deleted.

2 changes: 2 additions & 0 deletions src/widgets/upcoming-courses/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const tabletScreenBreakPoint = 810;
export const maxUpcomingCoursesQuantity = 5;
1 change: 1 addition & 0 deletions src/widgets/upcoming-courses/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { UpcomingCourses } from './ui/upcoming-courses';
22 changes: 22 additions & 0 deletions src/widgets/upcoming-courses/ui/upcoming-courses.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.rs-banner {
width: 300px;
height: 200px;

@include media-laptop {
margin-top: 24px;
}
}

.course-list {
display: flex;
flex-direction: column;
gap: 24px;
align-items: flex-start;
justify-content: space-between;

width: 800px;

@include media-laptop {
width: 100%;
}
}
Loading
Loading