-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
35da3c0
commit 2470605
Showing
5 changed files
with
138 additions
and
12 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...ents/src/components/UserGuide/components/UserGuideBubbleStep/UserGuideBubbleStep.spec.tsx
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,45 @@ | ||
import { render, userEvent, vi } from 'test-utils'; | ||
|
||
import { IUserGuideBubbleStepProps } from './types'; | ||
import { UserGuideBubbleStep } from './UserGuideBubbleStep'; | ||
|
||
const DEFAULT_PROPS: IUserGuideBubbleStepProps = { | ||
headerMessage: 'Header', | ||
message: 'Text', | ||
cta: <button>Primary</button>, | ||
disableTypingAnimations: true, | ||
}; | ||
|
||
const renderComponent = (props: IUserGuideBubbleStepProps) => | ||
render(<UserGuideBubbleStep {...props} />); | ||
|
||
describe('<UserGuideBubbleStep> component', () => { | ||
it('should render all default elements', () => { | ||
const { getByText, getByRole } = renderComponent(DEFAULT_PROPS); | ||
|
||
expect(getByText('Header')).toBeInTheDocument(); | ||
expect(getByText('Text')).toBeInTheDocument(); | ||
expect(getByRole('button', { name: 'Primary' })).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render icon if provided', () => { | ||
const { getByTestId } = renderComponent({ | ||
...DEFAULT_PROPS, | ||
headerIcon: <div data-testid="icon" />, | ||
}); | ||
|
||
expect(getByTestId('icon')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call handleAnimationComplete when all bubbles are visible', () => { | ||
const handleAnimationComplete = vi.fn(); | ||
const { getByRole } = renderComponent({ | ||
...DEFAULT_PROPS, | ||
handleAnimationComplete, | ||
}); | ||
|
||
userEvent.click(getByRole('button', { name: 'Primary' })); | ||
|
||
expect(handleAnimationComplete).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
77 changes: 77 additions & 0 deletions
77
...react-components/src/components/UserGuide/components/UserGuideStep/UserGuideStep.spec.tsx
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,77 @@ | ||
import { render, userEvent, vi } from 'test-utils'; | ||
|
||
import { IUserGuideStepProps } from './types'; | ||
import { UserGuideStep } from './UserGuideStep'; | ||
|
||
const DEFAULT_PROPS: IUserGuideStepProps = { | ||
header: 'Header', | ||
text: 'Text', | ||
currentStep: 1, | ||
stepMax: 2, | ||
handleClickPrimary: vi.fn(), | ||
}; | ||
|
||
const renderComponent = (props: IUserGuideStepProps) => | ||
render(<UserGuideStep {...props} />); | ||
|
||
describe('<UserGuideStep> component', () => { | ||
it('should render all default elements', () => { | ||
const { getByText, getByRole } = renderComponent(DEFAULT_PROPS); | ||
|
||
expect(getByText('Header')).toBeInTheDocument(); | ||
expect(getByText('Text')).toBeInTheDocument(); | ||
expect(getByText('Step 1 of 2')).toBeInTheDocument(); | ||
expect(getByRole('button', { name: 'Next' })).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render image if provided', () => { | ||
const { getByAltText } = renderComponent({ | ||
...DEFAULT_PROPS, | ||
image: { src: 'image.jpg', alt: 'Image' }, | ||
}); | ||
|
||
expect(getByAltText('Image')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render video if provided and no image', () => { | ||
const { getByTestId } = renderComponent({ | ||
...DEFAULT_PROPS, | ||
video: { src: 'video.mp4' }, | ||
}); | ||
|
||
expect(getByTestId('user-guide-step-video')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call handleClickPrimary when primary button is clicked', () => { | ||
const handleClickPrimary = vi.fn(); | ||
const { getByRole } = renderComponent({ | ||
...DEFAULT_PROPS, | ||
handleClickPrimary, | ||
}); | ||
|
||
userEvent.click(getByRole('button', { name: 'Next' })); | ||
|
||
expect(handleClickPrimary).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call handleCloseAction when skip button is clicked', () => { | ||
const handleCloseAction = vi.fn(); | ||
const { getByRole } = renderComponent({ | ||
...DEFAULT_PROPS, | ||
handleCloseAction, | ||
}); | ||
|
||
userEvent.click(getByRole('button', { name: 'Skip all' })); | ||
|
||
expect(handleCloseAction).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should change primary button content when currentStep is equal to stepMax', () => { | ||
const { getByRole } = renderComponent({ | ||
...DEFAULT_PROPS, | ||
currentStep: 2, | ||
}); | ||
|
||
expect(getByRole('button', { name: 'Finish' })).toBeInTheDocument(); | ||
}); | ||
}); |
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