-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
193 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { render } from '@testing-library/react' | ||
import React from 'react' | ||
import { Card } from './Card' | ||
|
||
describe('Card', () => { | ||
test('renders the card correctly', () => { | ||
const { getByTestId } = render( | ||
<Card title="Title" subtitle="Subtitle"> | ||
<div data-testid="children">Content</div> | ||
</Card>, | ||
) | ||
|
||
expect(getByTestId('title')).toBeInTheDocument() | ||
expect(getByTestId('title').textContent).toBe('Title') | ||
|
||
expect(getByTestId('subtitle')).toBeInTheDocument() | ||
expect(getByTestId('subtitle').textContent).toBe('Subtitle') | ||
|
||
expect(getByTestId('children')).toBeInTheDocument() | ||
expect(getByTestId('children').textContent).toBe('Content') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { render } from '@testing-library/react' | ||
import React from 'react' | ||
import { Logo } from './Logo' | ||
import { config } from '@/config' | ||
|
||
describe('Logo', () => { | ||
test('renders the logo correctly', () => { | ||
const { getByText } = render(<Logo />) | ||
const title = config.app.metadata.title.default | ||
|
||
expect(getByText(title)).toBeInTheDocument() | ||
expect(getByText(title).textContent).toBe(title) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { afterEach, describe, expect, test, vi } from 'vitest' | ||
import { cleanup, fireEvent, render, screen } from '@testing-library/react' | ||
import Modal from './Modal' | ||
import React from 'react' | ||
|
||
describe('Modal', () => { | ||
describe('modal is open', () => { | ||
const closeModalMock = vi.fn() | ||
|
||
vi.mock('@/hooks/useModal', () => ({ | ||
useModal: () => ({ | ||
title: 'Title', | ||
content: 'content...', | ||
showModal: true, | ||
closeBtnTitle: 'close', | ||
closeModal: closeModalMock, | ||
}), | ||
})) | ||
|
||
test('renders the modal correctly', () => { | ||
render(<Modal />) | ||
|
||
const buttom = screen.getByRole('button', { name: 'close' }) | ||
expect(buttom).toBeInTheDocument() | ||
|
||
const title = screen.getByTestId('title') | ||
expect(title).toBeInTheDocument() | ||
expect(title.textContent).toBe('Title') | ||
|
||
const content = screen.getByTestId('content') | ||
expect(content).toBeInTheDocument() | ||
expect(content.textContent).toBe('content...') | ||
}) | ||
|
||
test('calls closeModal when the close button is clicked', () => { | ||
render(<Modal />) | ||
|
||
fireEvent.click(screen.getByRole('button')) | ||
|
||
expect(closeModalMock).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
describe('modal is close', () => { | ||
vi.mock('@/hooks/useModal', () => ({ | ||
useModal: () => ({ | ||
title: 'Title', | ||
showModal: false, | ||
closeBtnTitle: 'close', | ||
closeModal: vi.fn(), | ||
}), | ||
})) | ||
|
||
test('does not render the modal when showModal is false', () => { | ||
const { container } = render(<Modal />) | ||
expect(container.innerText).toBeUndefined() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expect, test, vi } from 'vitest' | ||
import { render } from '@testing-library/react' | ||
import { Term } from './Term' | ||
import React from 'react' | ||
|
||
const openModalMock = vi.fn() | ||
|
||
vi.mock('@/hooks/useModal', () => ({ | ||
useModal: () => ({ | ||
openModal: openModalMock, | ||
}), | ||
})) | ||
|
||
describe('Term', () => { | ||
test('calls openModal when the term is rendered', () => { | ||
render(<Term />) | ||
expect(openModalMock).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { afterEach, describe, expect, test } from 'vitest' | ||
import { cleanup, render } from '@testing-library/react' | ||
import { Title } from './Title' | ||
import React from 'react' | ||
|
||
describe('Title', () => { | ||
afterEach(cleanup) | ||
|
||
test('renders the title correctly', () => { | ||
const { getByTestId } = render( | ||
<Title> | ||
<div data-testid="children">Title Text</div> | ||
</Title>, | ||
) | ||
expect(getByTestId('children')).toBeInTheDocument() | ||
expect(getByTestId('children').textContent).toBe('Title Text') | ||
}) | ||
|
||
test('applies additional class names correctly', () => { | ||
const { getByText } = render( | ||
<Title className="custom-class">Title Text</Title>, | ||
) | ||
expect(getByText('Title Text')).toHaveClass('custom-class') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { afterEach, describe, expect, test, vi } from 'vitest' | ||
import { cleanup, fireEvent, render } from '@testing-library/react' | ||
import { TooltipHelper } from './TooltipHelper' | ||
import React from 'react' | ||
|
||
const openModalMock = vi.fn() | ||
vi.mock('@/hooks/useModal', () => ({ | ||
useModal: () => ({ | ||
openModal: openModalMock, | ||
}), | ||
})) | ||
|
||
describe('TooltipHelper', () => { | ||
afterEach(cleanup) | ||
|
||
test('renders the tooltip correctly', () => { | ||
const { getByRole } = render( | ||
<TooltipHelper title="Title" content="content..." />, | ||
) | ||
|
||
const buttom = getByRole('button') | ||
expect(buttom).toBeInTheDocument() | ||
}) | ||
|
||
test('opens the modal when the button is clicked', () => { | ||
const { getByRole } = render( | ||
<TooltipHelper title="Title" content="content..." />, | ||
) | ||
|
||
fireEvent.click(getByRole('button')) | ||
expect(openModalMock).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters