Skip to content

Commit 1f772c0

Browse files
committed
card-component 테스트코드 수정
1 parent a473594 commit 1f772c0

1 file changed

Lines changed: 27 additions & 26 deletions

File tree

tests/markdown.test.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ beforeAll(() => {
1717
(global as any).customElements = dom.window.customElements;
1818
/* eslint-enable @typescript-eslint/no-explicit-any */
1919

20-
class BoxComponent extends dom.window.HTMLElement {
20+
class CardComponent extends dom.window.HTMLElement {
2121
connectedCallback() {
22-
const title = this.getAttribute('title') || 'Box Title';
23-
const description = this.getAttribute('description') || 'Box content';
22+
const title = this.getAttribute('title') || 'Card Title';
23+
const description = this.getAttribute('description') || 'Card content';
2424
const imgsrc = this.getAttribute('imgsrc') || '';
2525
const href = this.getAttribute('href') || '/';
2626

2727
this.innerHTML = `
28-
<div class="overflow-x-hidden shadow rounded bg-white mb-4 transition-all duration-200 hover:shadow hover:ring hover:ring-gray-200">
28+
<div class="card">
2929
<a href="${href}" class="no-underline decoration-none" style="text-decoration: none;">
3030
<div class="flex flex-col gap-2 p-4">
3131
<div class="flex gap-4 items-center">
@@ -55,7 +55,7 @@ beforeAll(() => {
5555
}
5656
}
5757

58-
dom.window.customElements.define('box-component', BoxComponent);
58+
dom.window.customElements.define('card-component', CardComponent);
5959
dom.window.customElements.define('button-component', ButtonComponent);
6060
});
6161

@@ -68,19 +68,19 @@ beforeEach(() => {
6868

6969
describe('renderMarkdownWithComponents', () => {
7070
describe('웹 컴포넌트 존재 확인', () => {
71-
it('단일 box-component가 DOM에 존재하는지 확인', async () => {
71+
it('단일 card-component가 DOM에 존재하는지 확인', async () => {
7272
// Arrange
7373
const mdText =
74-
'<box-component title="Docker 개요" description="Docker의 기본 개념" imgsrc="/imgs/docker.svg" href="/overview"></box-component>';
74+
'<card-component title="Docker 개요" description="Docker의 기본 개념" imgsrc="/imgs/docker.svg" href="/overview"></card-component>';
7575

7676
// Act
7777
await renderMarkdownWithComponents(mdText, contentElement);
7878
await new Promise((resolve) => setTimeout(resolve, 10));
7979

8080
// Assert
81-
const boxComponent = contentElement.querySelector('box-component');
82-
expect(boxComponent).toBeTruthy();
83-
expect(boxComponent?.tagName.toLowerCase()).toBe('box-component');
81+
const cardComponent = contentElement.querySelector('card-component');
82+
expect(cardComponent).toBeTruthy();
83+
expect(cardComponent?.tagName.toLowerCase()).toBe('card-component');
8484
});
8585

8686
it('단일 button-component가 DOM에 존재하는지 확인', async () => {
@@ -98,10 +98,10 @@ describe('renderMarkdownWithComponents', () => {
9898
expect(buttonComponent?.tagName.toLowerCase()).toBe('button-component');
9999
});
100100

101-
it('box-component와 button-component가 모두 DOM에 존재하는지 확인', async () => {
101+
it('card-component와 button-component가 모두 DOM에 존재하는지 확인', async () => {
102102
// Arrange
103103
const mdText = `
104-
<box-component title="Docker 개요" description="Docker의 기본 개념" imgsrc="/imgs/docker.svg" href="/overview"></box-component>
104+
<card-component title="Docker 개요" description="Docker의 기본 개념" imgsrc="/imgs/docker.svg" href="/overview"></card-component>
105105
<button-component title="시작하기" href="/get-started"></button-component>
106106
`;
107107

@@ -110,37 +110,38 @@ describe('renderMarkdownWithComponents', () => {
110110
await new Promise((resolve) => setTimeout(resolve, 10));
111111

112112
// Assert
113-
const boxComponent = contentElement.querySelector('box-component');
113+
const cardComponent = contentElement.querySelector('card-component');
114114
const buttonComponent = contentElement.querySelector('button-component');
115115

116-
expect(boxComponent).toBeTruthy();
116+
expect(cardComponent).toBeTruthy();
117117
expect(buttonComponent).toBeTruthy();
118118
expect(
119-
contentElement.querySelectorAll('box-component, button-component')
119+
contentElement.querySelectorAll('card-component, button-component')
120120
.length
121121
).toBe(2);
122122
});
123123
});
124124

125125
describe('HTML 내용 검증', () => {
126-
it('box-component의 HTML 내용이 올바르게 렌더링되는지 확인', async () => {
126+
it('card-component의 HTML 내용이 올바르게 렌더링되는지 확인', async () => {
127127
// Arrange
128128
const title = 'Docker 개요';
129129
const description = 'Docker의 기본 개념';
130-
const mdText = `<box-component title="${title}" description="${description}" imgsrc="/imgs/docker.svg" href="/overview"></box-component>`;
130+
const imgsrc = '/imgs/docker.svg';
131+
const href = '/overview';
132+
const mdText = `<card-component title="${title}" description="${description}" imgsrc="${imgsrc}" href="${href}"></card-component>`;
131133

132134
// Act
133135
await renderMarkdownWithComponents(mdText, contentElement);
134136
await new Promise((resolve) => setTimeout(resolve, 10));
135137

136138
// Assert
137-
const boxComponent = contentElement.querySelector('box-component');
138-
const innerHTML = boxComponent?.innerHTML || '';
139-
139+
const cardComponent = contentElement.querySelector('card-component');
140+
const innerHTML = cardComponent?.innerHTML || '';
140141
expect(innerHTML).toContain(title);
141142
expect(innerHTML).toContain(description);
142-
expect(innerHTML).toContain('shadow rounded bg-white');
143-
expect(innerHTML).toContain('href="/overview"');
143+
expect(innerHTML).toContain('card');
144+
expect(innerHTML).toContain(`href="${href}"`);
144145
});
145146

146147
it('button-component의 HTML 내용이 올바르게 렌더링되는지 확인', async () => {
@@ -169,7 +170,7 @@ describe('renderMarkdownWithComponents', () => {
169170
const boxDescription = 'Docker의 기본 개념';
170171
const buttonTitle = '시작하기';
171172
const mdText = `
172-
<box-component title="${boxTitle}" description="${boxDescription}" imgsrc="/imgs/docker.svg" href="/overview"></box-component>
173+
<card-component title="${boxTitle}" description="${boxDescription}" imgsrc="/imgs/docker.svg" href="/overview"></card-component>
173174
<button-component title="${buttonTitle}" href="/get-started"></button-component>
174175
`;
175176

@@ -178,11 +179,11 @@ describe('renderMarkdownWithComponents', () => {
178179
await new Promise((resolve) => setTimeout(resolve, 10));
179180

180181
// Assert
181-
const boxComponent = contentElement.querySelector('box-component');
182+
const cardComponent = contentElement.querySelector('card-component');
182183
const buttonComponent = contentElement.querySelector('button-component');
183184

184-
expect(boxComponent?.innerHTML).toContain(boxTitle);
185-
expect(boxComponent?.innerHTML).toContain(boxDescription);
185+
expect(cardComponent?.innerHTML).toContain(boxTitle);
186+
expect(cardComponent?.innerHTML).toContain(boxDescription);
186187
expect(buttonComponent?.innerHTML).toContain(buttonTitle);
187188

188189
const allContent = contentElement.innerHTML;

0 commit comments

Comments
 (0)