Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 24 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/features/about/activity/CardItem.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { render, screen } from '@testing-library/react';

import { ActivityType, type Activity } from './models';
import { CardItem } from './CardItem';

const activity: Activity = {
name: 'FEConf',
type: ActivityType.conference,
startDate: 2024,
url: 'https://feconf.kr',
};

describe('CardItem', () => {
it('should render activity type and external link', () => {
render(
<ul>
<CardItem activity={activity} />
</ul>,
);

expect(screen.getByText(ActivityType.conference)).toBeVisible();
const link = screen.getByRole('link', { name: 'FEConf' });
expect(link).toHaveAttribute('href', 'https://feconf.kr');
expect(link).toHaveAttribute('target', '_blank');
});
});
34 changes: 34 additions & 0 deletions src/features/about/shared/Label.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { Label } from './Label';

describe('Label', () => {
it('should render static heading when onClick is omitted', () => {
render(<Label label="WORK EXPERIENCE" />);

expect(screen.getByText('WORK EXPERIENCE')).toBeVisible();
expect(screen.queryByRole('button')).not.toBeInTheDocument();
});

it('should render interactive button and handle click/keyboard', async () => {
const onClick = jest.fn();
render(<Label label="WORK EXPERIENCE" onClick={onClick} ariaExpanded />);

const button = screen.getByRole('button', { name: 'WORK EXPERIENCE' });
expect(button).toHaveAttribute('aria-expanded', 'true');

await userEvent.click(button);
expect(onClick).toHaveBeenCalledTimes(1);

button.focus();
await userEvent.keyboard('{Enter}');
expect(onClick).toHaveBeenCalledTimes(2);

await userEvent.keyboard(' ');
expect(onClick).toHaveBeenCalledTimes(3);

await userEvent.keyboard('a');
expect(onClick).toHaveBeenCalledTimes(3);
});
});
29 changes: 29 additions & 0 deletions src/features/about/work/card/content/ProjectDate.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { render, screen } from '@testing-library/react';

import { ProjectDate } from './ProjectDate';

describe('ProjectDate', () => {
it('should render start and end dates', () => {
render(
<ProjectDate
startDate={Date.UTC(2020, 0, 1)}
endDate={Date.UTC(2022, 0, 1)}
format="yyyy"
className="extra"
/>,
);

expect(screen.getByText('2020')).toBeVisible();
expect(screen.getByText('2022')).toBeVisible();
expect(screen.getByText(/-/)).toBeVisible();
});

it('should render Present when endDate is missing', () => {
const { container } = render(
<ProjectDate startDate={Date.UTC(2023, 0, 1)} format="yyyy" />,
);

expect(screen.getByText('2023')).toBeVisible();
expect(container).toHaveTextContent('Present');
});
});
18 changes: 18 additions & 0 deletions src/features/about/work/card/content/Tags.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { render, screen } from '@testing-library/react';

import { Tags } from './Tags';

describe('Tags', () => {
it('should render each tag', () => {
render(<Tags tags={['React18', 'AWS']} />);

expect(screen.getByText('React18')).toBeVisible();
expect(screen.getByText('AWS')).toBeVisible();
});

it('should render empty container when tags are empty', () => {
const { container } = render(<Tags tags={[]} />);

expect(container.firstChild).toBeEmptyDOMElement();
});
});
37 changes: 37 additions & 0 deletions src/features/about/work/shared/Body.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { render, screen } from '@testing-library/react';

import { Paragraph, Section, Sentence } from './Body';

describe('Body', () => {
it('should render Section with top margin class when top is false', () => {
const { container } = render(
<ul>
<Section>내용</Section>
</ul>,
);

expect(container.querySelector('li')).toHaveClass('mt-8');
expect(screen.getByText('내용')).toBeVisible();
});

it('should omit extra top margin when top is true', () => {
const { container } = render(
<ul>
<Section top>상단</Section>
</ul>,
);

expect(container.querySelector('li')).not.toHaveClass('mt-8');
});

it('should render Paragraph and Sentence', () => {
render(
<Paragraph>
<Sentence value="첫 문장">추가</Sentence>
</Paragraph>,
);

expect(screen.getByRole('list')).toBeVisible();
expect(screen.getByRole('listitem')).toHaveTextContent('첫 문장추가');
});
});
8 changes: 5 additions & 3 deletions src/features/home/Container.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ describe('HomeContainer', () => {
it('should fire analytics on click', async () => {
render(<HomeContainer />);

await userEvent.click(
screen.getByRole('link', { name: '포스트 목록으로 이동' }),
);
const link = screen.getByRole('link', { name: '포스트 목록으로 이동' });
link.addEventListener('click', (event) => {
event.preventDefault();
});
await userEvent.click(link);

expect(ga).toHaveBeenCalledWith('homeClick', {
type: 'router-push',
Expand Down
20 changes: 14 additions & 6 deletions src/features/post/PostNavigationContainer/PrevNext.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ describe('PrevNext', () => {
/>,
);

await userEvent.click(
screen.getByRole('link', { name: '이전 글: prev-post title' }),
);
const link = screen.getByRole('link', {
name: '이전 글: prev-post title',
});
link.addEventListener('click', (event) => {
event.preventDefault();
});
await userEvent.click(link);

expect(mockSendGAEvent).toHaveBeenCalledWith('event', 'postNavigation', {
type: 'prev',
Expand All @@ -119,9 +123,13 @@ describe('PrevNext', () => {
/>,
);

await userEvent.click(
screen.getByRole('link', { name: '다음 글: next-post title' }),
);
const link = screen.getByRole('link', {
name: '다음 글: next-post title',
});
link.addEventListener('click', (event) => {
event.preventDefault();
});
await userEvent.click(link);

expect(mockSendGAEvent).toHaveBeenCalledWith('event', 'postNavigation', {
type: 'next',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ describe('RelatedPostItem', () => {
/>,
);

await userEvent.click(
screen.getByRole('link', { name: /Sample Post Title/i }),
);
const link = screen.getByRole('link', { name: /Sample Post Title/i });
link.addEventListener('click', (event) => {
event.preventDefault();
});
await userEvent.click(link);

expect(mockSendGAEvent).toHaveBeenCalledWith('event', 'postNavigation', {
type: 'similar',
Expand All @@ -99,9 +101,11 @@ describe('RelatedPostItem', () => {
/>,
);

await userEvent.click(
screen.getByRole('link', { name: /Sample Post Title/i }),
);
const link = screen.getByRole('link', { name: /Sample Post Title/i });
link.addEventListener('click', (event) => {
event.preventDefault();
});
await userEvent.click(link);

expect(mockSendGAEvent).toHaveBeenCalledWith('event', 'postNavigation', {
type: 'discovery',
Expand Down
Loading
Loading