|
| 1 | +import React from 'react'; |
| 2 | +import { act, fireEvent, render, screen } from '@testing-library/react'; |
| 3 | +import { TutorialOverlay } from '../src/components/tutorial-overlay'; |
| 4 | +import { tutorial } from '../src/core/tutorial'; |
| 5 | + |
| 6 | +function renderOverlay() { |
| 7 | + render( |
| 8 | + <div> |
| 9 | + <div id="first-target">First target</div> |
| 10 | + <div id="second-target">Second target</div> |
| 11 | + <TutorialOverlay /> |
| 12 | + </div> |
| 13 | + ); |
| 14 | +} |
| 15 | + |
| 16 | +describe('Content', () => { |
| 17 | + test('button navigation invokes each step callback once', () => { |
| 18 | + const onNextStep = jest.fn(); |
| 19 | + const onPrevStep = jest.fn(); |
| 20 | + |
| 21 | + renderOverlay(); |
| 22 | + |
| 23 | + act(() => { |
| 24 | + tutorial.open({ |
| 25 | + steps: [ |
| 26 | + { title: 'Step 1', content: 'Step 1 content', targetIds: ['first-target'], onNextStep }, |
| 27 | + { title: 'Step 2', content: 'Step 2 content', targetIds: ['second-target'], onPrevStep }, |
| 28 | + ], |
| 29 | + options: {}, |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + fireEvent.click(screen.getByRole('button', { name: '다음' })); |
| 34 | + |
| 35 | + expect(onNextStep).toHaveBeenCalledTimes(1); |
| 36 | + expect(screen.getByText('Step 2 content')).toBeInTheDocument(); |
| 37 | + |
| 38 | + fireEvent.click(screen.getByRole('button', { name: '이전' })); |
| 39 | + |
| 40 | + expect(onPrevStep).toHaveBeenCalledTimes(1); |
| 41 | + expect(screen.getByText('Step 1 content')).toBeInTheDocument(); |
| 42 | + }); |
| 43 | + |
| 44 | + test('renders content strings as text instead of interpreting html', () => { |
| 45 | + renderOverlay(); |
| 46 | + |
| 47 | + act(() => { |
| 48 | + tutorial.open({ |
| 49 | + steps: [ |
| 50 | + { |
| 51 | + title: 'HTML content', |
| 52 | + content: '<strong>Literal HTML</strong>', |
| 53 | + targetIds: ['first-target'], |
| 54 | + }, |
| 55 | + ], |
| 56 | + options: {}, |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + expect(screen.getByText('<strong>Literal HTML</strong>')).toBeInTheDocument(); |
| 61 | + expect(document.querySelector('strong')).toBeNull(); |
| 62 | + }); |
| 63 | +}); |
0 commit comments